Add msdf_shape_one_shot_distance function

This commit is contained in:
KitsuneAlex 2024-05-14 23:48:12 +02:00
parent 79c242ae0b
commit 241d109db6
No known key found for this signature in database
GPG Key ID: 6B0CE864BB69B7D0
2 changed files with 21 additions and 0 deletions

View File

@ -13,7 +13,9 @@
*/
#include "../msdfgen-c.h"
#include "../msdfgen.h"
#include "ShapeDistanceFinder.h"
#include <utility>
@ -298,6 +300,15 @@ MSDF_API int msdf_shape_edge_colors_by_distance(msdf_shape_handle shape, const d
return MSDF_SUCCESS;
}
MSDF_API int msdf_shape_one_shot_distance(msdf_shape_const_handle shape, const msdf_vector2_t* origin, double* distance) {
if(shape == nullptr || origin == nullptr) {
return MSDF_ERR_INVALID_ARG;
}
*distance = msdfgen::SimpleTrueShapeDistanceFinder::oneShotDistance(*reinterpret_cast<const msdfgen::Shape*>(shape),
*reinterpret_cast<const msdfgen::Point2*>(origin));
return MSDF_SUCCESS;
}
MSDF_API void msdf_shape_free(msdf_shape_handle shape) {
delete reinterpret_cast<msdfgen::Shape*>(shape);
}

View File

@ -319,6 +319,16 @@ MSDF_API int msdf_shape_edge_colors_ink_trap(msdf_shape_handle shape, double ang
*/
MSDF_API int msdf_shape_edge_colors_by_distance(msdf_shape_handle shape, double angle_threshold);
/**
* Finds the distance between shape and origin.
* Does not allocate result cache used to optimize performance of multiple queries.
* @param shape A pointer to the shape to find the distance to.
* @param origin The point to find the distance relative to the given shape to.
* @param distance A pointer to a variable to be populated with the calculated distance to the given shape.
* @returns @code MSDF_SUCCESS@endcode on success, otherwise one of the constants prefixed with @code MSDF_ERR_@endcode.
*/
MSDF_API int msdf_shape_one_shot_distance(msdf_shape_const_handle shape, const msdf_vector2_t* origin, double* distance);
/**
* Calls the destructor of the given bitmap and frees its memory using the
* internal allocator.