mirror of https://github.com/Chlumsky/msdfgen.git
Add msdf_shape_remove_contour and msdf_contour_remove_edge functions
This commit is contained in:
parent
4974fb7203
commit
68dc012b32
|
|
@ -176,6 +176,28 @@ MSDF_API int msdf_shape_add_contour(msdf_shape_handle shape, msdf_contour_const_
|
||||||
return MSDF_SUCCESS;
|
return MSDF_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MSDF_API int msdf_shape_remove_contour(msdf_shape_handle shape, msdf_contour_const_handle contour) {
|
||||||
|
if(shape == nullptr || contour == nullptr) {
|
||||||
|
return MSDF_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
auto& contours = reinterpret_cast<msdfgen::Shape*>(shape)->contours;//NOLINT
|
||||||
|
ptrdiff_t index = 0;
|
||||||
|
bool found = false;
|
||||||
|
for(const auto& contour_ref : contours) {
|
||||||
|
if(&contour_ref != reinterpret_cast<const msdfgen::Contour*>(contour)) {
|
||||||
|
++index;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!found) {
|
||||||
|
return MSDF_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
contours.erase(contours.cbegin() + index);
|
||||||
|
return MSDF_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
MSDF_API int msdf_shape_get_contour_count(msdf_shape_const_handle shape, size_t* contour_count) {
|
MSDF_API int msdf_shape_get_contour_count(msdf_shape_const_handle shape, size_t* contour_count) {
|
||||||
if(shape == nullptr || contour_count == nullptr) {
|
if(shape == nullptr || contour_count == nullptr) {
|
||||||
return MSDF_ERR_INVALID_ARG;
|
return MSDF_ERR_INVALID_ARG;
|
||||||
|
|
@ -298,6 +320,28 @@ MSDF_API int msdf_contour_add_edge(msdf_contour_handle contour, msdf_segment_han
|
||||||
return MSDF_SUCCESS;
|
return MSDF_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MSDF_API int msdf_contour_remove_edge(msdf_contour_handle contour, msdf_segment_handle segment) {
|
||||||
|
if(contour == nullptr || segment == nullptr) {
|
||||||
|
return MSDF_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
auto& edges = reinterpret_cast<msdfgen::Contour*>(contour)->edges;
|
||||||
|
ptrdiff_t index = 0;
|
||||||
|
bool found = false;
|
||||||
|
for(const msdfgen::EdgeSegment* edge : edges) {
|
||||||
|
if(edge != reinterpret_cast<const msdfgen::EdgeSegment*>(segment)) {
|
||||||
|
++index;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(!found) {
|
||||||
|
return MSDF_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
edges.erase(edges.cbegin() + index);
|
||||||
|
return MSDF_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
MSDF_API int msdf_contour_get_edge_count(msdf_contour_const_handle contour, size_t* edge_count) {
|
MSDF_API int msdf_contour_get_edge_count(msdf_contour_const_handle contour, size_t* edge_count) {
|
||||||
if(contour == nullptr || edge_count == nullptr) {
|
if(contour == nullptr || edge_count == nullptr) {
|
||||||
return MSDF_ERR_INVALID_ARG;
|
return MSDF_ERR_INVALID_ARG;
|
||||||
|
|
|
||||||
16
msdfgen-c.h
16
msdfgen-c.h
|
|
@ -197,6 +197,14 @@ MSDF_API int msdf_shape_get_bounds(msdf_shape_const_handle shape, msdf_bounds_t*
|
||||||
*/
|
*/
|
||||||
MSDF_API int msdf_shape_add_contour(msdf_shape_handle shape, msdf_contour_const_handle contour);
|
MSDF_API int msdf_shape_add_contour(msdf_shape_handle shape, msdf_contour_const_handle contour);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the given contour from the given shape if present.
|
||||||
|
* @param shape A pointer to a shape object to remove the given contour from.
|
||||||
|
* @param contour A pointer to the contour to remove from the shape.
|
||||||
|
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
|
||||||
|
*/
|
||||||
|
MSDF_API int msdf_shape_remove_contour(msdf_shape_handle shape, msdf_contour_const_handle contour);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the number of contours allocated within the given shape object.
|
* Retrieves the number of contours allocated within the given shape object.
|
||||||
* @param shape A pointer to a shape object from which to retrieve the contour count.
|
* @param shape A pointer to a shape object from which to retrieve the contour count.
|
||||||
|
|
@ -325,6 +333,14 @@ MSDF_API int msdf_contour_alloc(msdf_contour_handle* contour);
|
||||||
*/
|
*/
|
||||||
MSDF_API int msdf_contour_add_edge(msdf_contour_handle contour, msdf_segment_handle segment);
|
MSDF_API int msdf_contour_add_edge(msdf_contour_handle contour, msdf_segment_handle segment);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the given edge from the given contour if present.
|
||||||
|
* @param contour A pointer to the contour to remove the given edge (segment) from.
|
||||||
|
* @param segment A pointer to the segment to remove from the given contour.
|
||||||
|
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
|
||||||
|
*/
|
||||||
|
MSDF_API int msdf_contour_remove_edge(msdf_contour_handle contour, msdf_segment_handle segment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the edge count of the given contour.
|
* Retrieves the edge count of the given contour.
|
||||||
* @param contour A pointer to the contour to retrieve the edge count from.
|
* @param contour A pointer to the contour to retrieve the edge count from.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue