@@ -177,7 +177,9 @@ namespace tmd
177177 *
178178 * @return Result containing distance, nearest point on the mesh, nearest entity and the nearest triangle index.
179179 */
180- Result unsigned_distance (const Vec3d &point) const ;
180+ template <typename IndexableVector3double>
181+ Result unsigned_distance (const IndexableVector3double& point) const ;
182+ Result unsigned_distance (const std::array<double , 3 >& point) const ;
181183
182184 /* *
183185 * @brief Computes the unsigned distance from a point to the triangle mesh. Thread safe.
@@ -186,7 +188,9 @@ namespace tmd
186188 *
187189 * @return Result containing distance, nearest point on the mesh, nearest entity and the nearest triangle index.
188190 */
189- Result signed_distance (const Vec3d& point) const ;
191+ template <typename IndexableVector3double>
192+ Result signed_distance (const IndexableVector3double& point) const ;
193+ Result signed_distance (const std::array<double , 3 >& point) const ;
190194 };
191195}
192196
@@ -243,9 +247,10 @@ inline void tmd::TriangleMeshDistance::construct(const std::vector<IndexableVect
243247 this ->_construct ();
244248}
245249
246- inline tmd::Result tmd::TriangleMeshDistance::signed_distance (const Vec3d & point) const
250+ inline tmd::Result tmd::TriangleMeshDistance::signed_distance (const std::array< double , 3 > & point) const
247251{
248- Result result = this ->unsigned_distance (point);
252+ const Vec3d p (point[0 ], point[1 ], point[2 ]);
253+ Result result = this ->unsigned_distance (p);
249254
250255 const std::array<int , 3 >& triangle = this ->triangles [result.triangle_id ];
251256 Vec3d pseudonormal;
@@ -277,25 +282,38 @@ inline tmd::Result tmd::TriangleMeshDistance::signed_distance(const Vec3d& point
277282 break ;
278283 }
279284
280- const Vec3d u = point - result.nearest_point ;
285+ const Vec3d u = p - result.nearest_point ;
281286 result.distance *= (u.dot (pseudonormal) >= 0.0 ) ? 1.0 : -1.0 ;
282287
283288 return result;
284289}
285290
286- inline tmd::Result tmd::TriangleMeshDistance::unsigned_distance (const Vec3d& point) const
291+ template <typename IndexableVector3double>
292+ inline tmd::Result tmd::TriangleMeshDistance::signed_distance (const IndexableVector3double& point) const
293+ {
294+ return this ->signed_distance ({ static_cast <double >(point[0 ]), static_cast <double >(point[1 ]), static_cast <double >(point[2 ]) });
295+ }
296+
297+ inline tmd::Result tmd::TriangleMeshDistance::unsigned_distance (const std::array<double , 3 >& point) const
287298{
288299 if (!this ->is_constructed ) {
289300 std::cout << " DistanceTriangleMesh error: not constructed." << std::endl;
290301 exit (-1 );
291302 }
292303
304+ const Vec3d p (point[0 ], point[1 ], point[2 ]);
293305 Result result;
294306 result.distance = std::numeric_limits<double >::max ();
295- this ->_query (result, this ->nodes [0 ], point );
307+ this ->_query (result, this ->nodes [0 ], p );
296308 return result;
297309}
298310
311+ template <typename IndexableVector3double>
312+ inline tmd::Result tmd::TriangleMeshDistance::unsigned_distance (const IndexableVector3double& point) const
313+ {
314+ return this ->unsigned_distance ({static_cast <double >(point[0 ]), static_cast <double >(point[1 ]), static_cast <double >(point[2 ])});
315+ }
316+
299317inline void tmd::TriangleMeshDistance::_construct ()
300318{
301319 if (this ->triangles .size () == 0 ) {
0 commit comments