From 241d109db6f9c6667df8881c13f8d08d06bfbd73 Mon Sep 17 00:00:00 2001 From: KitsuneAlex Date: Tue, 14 May 2024 23:48:12 +0200 Subject: [PATCH] Add msdf_shape_one_shot_distance function --- core/msdfgen-c.cpp | 11 +++++++++++ msdfgen-c.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/core/msdfgen-c.cpp b/core/msdfgen-c.cpp index 7715e7b..ba103c1 100644 --- a/core/msdfgen-c.cpp +++ b/core/msdfgen-c.cpp @@ -13,7 +13,9 @@ */ #include "../msdfgen-c.h" + #include "../msdfgen.h" +#include "ShapeDistanceFinder.h" #include @@ -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(shape), + *reinterpret_cast(origin)); + return MSDF_SUCCESS; +} + MSDF_API void msdf_shape_free(msdf_shape_handle shape) { delete reinterpret_cast(shape); } diff --git a/msdfgen-c.h b/msdfgen-c.h index fa575d9..e7ae838 100644 --- a/msdfgen-c.h +++ b/msdfgen-c.h @@ -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.