Added Edge#euclidian_distance

This commit is contained in:
Matthias Koefferlein 2023-12-07 23:09:04 +01:00
parent 787114fee2
commit b6d3f8be93
2 changed files with 29 additions and 5 deletions

View File

@ -555,7 +555,7 @@ struct edge_defs
"This method has been introduced in version 0.26.2.\n"
) +
method ("distance", &C::distance, gsi::arg ("p"),
"@brief Distance between the edge and a point.\n"
"@brief Gets the distance of the point from the line through the edge.\n"
"\n"
"Returns the distance between the edge and the point. The \n"
"distance is signed which is negative if the point is to the\n"
@ -564,6 +564,11 @@ struct edge_defs
"line through the edge. If the edge is degenerated, the distance\n"
"is not defined.\n"
"\n"
"This method considers the edge to define an infinite line running through it.\n"
"the distance is the minimum distance of the point to any of the points on this\n"
"infinite line. A similar method is \\euclidian_distance, but the latter regards\n"
"the edge as a finite set of points between the endpoints.\n"
"\n"
"@param p The point to test.\n"
"\n"
"@return The distance\n"
@ -578,6 +583,19 @@ struct edge_defs
"\n"
"@return The side value\n"
) +
method ("euclidian_distance", &C::euclidian_distance, gsi::arg ("p"),
"@brief Gets the distance of the point from the the edge.\n"
"\n"
"Returns the minimum distance of the point to any point on the edge.\n"
"Unlike \\distance, the edge is considered a finite set of points between\n"
"the endpoints. The result is also not signed like it is the case for \\distance.\n"
"\n"
"This method has been introduced in version 0.28.14.\n"
"\n"
"@param p The point to test.\n"
"\n"
"@return The distance\n"
) +
method ("distance_abs", &C::distance_abs, gsi::arg ("p"),
"@brief Absolute distance between the edge and a point.\n"
"\n"

View File

@ -111,6 +111,9 @@ class DBEdge_TestClass < TestBase
assert_equal( a.intersect?( RBA::DEdge::new( -1, 11, 1, 15 ) ), false )
assert_equal( a.distance( RBA::DPoint::new( 3, 3 ) ), 1.0 )
assert_equal( a.distance( RBA::DPoint::new( 3, 1 ) ), -1.0 )
assert_equal( a.euclidian_distance( RBA::DPoint::new( 3, 3 ) ), 1.0 )
assert_equal( a.euclidian_distance( RBA::DPoint::new( 3, 1 ) ), 1.0 )
assert_equal( a.euclidian_distance( RBA::DPoint::new( -3, 2 ) ), 1.0 )
assert_equal( a.distance_abs( RBA::DPoint::new( 3, 3 ) ), 1.0 )
assert_equal( a.distance_abs( RBA::DPoint::new( 3, 1 ) ), 1.0 )
assert_equal( a.side_of( RBA::DPoint::new( 3, 3 ) ), 1 )
@ -224,10 +227,13 @@ class DBEdge_TestClass < TestBase
assert_equal( a.intersection_point( RBA::Edge::new( RBA::Point::new( -1, -1 ), RBA::Point::new( 1, 5 ) ) ).to_s, "0,2" )
assert_equal( a.intersection_point( RBA::Edge::new( RBA::Point::new( -1, 3 ), RBA::Point::new( 1, 5 ) ) ) == nil, true )
assert_equal( a.intersect?( RBA::Edge::new( RBA::Point::new( -1, 11 ), RBA::Point::new( 1, 15 ) ) ), false )
assert_equal( a.distance( RBA::Point::new( 3, 3 ) ), 1.0 )
assert_equal( a.distance( RBA::Point::new( 3, 1 ) ), -1.0 )
assert_equal( a.distance_abs( RBA::Point::new( 3, 3 ) ), 1.0 )
assert_equal( a.distance_abs( RBA::Point::new( 3, 1 ) ), 1.0 )
assert_equal( a.distance( RBA::Point::new( 3, 3 ) ), 1 )
assert_equal( a.distance( RBA::Point::new( 3, 1 ) ), -1 )
assert_equal( a.euclidian_distance( RBA::Point::new( 3, 4 ) ), 2 )
assert_equal( a.euclidian_distance( RBA::Point::new( 3, 0 ) ), 2 )
assert_equal( a.euclidian_distance( RBA::Point::new( -4, 2 ) ), 2 )
assert_equal( a.distance_abs( RBA::Point::new( 3, 3 ) ), 1 )
assert_equal( a.distance_abs( RBA::Point::new( 3, 1 ) ), 1 )
assert_equal( a.side_of( RBA::Point::new( 3, 3 ) ), 1 )
assert_equal( a.side_of( RBA::Point::new( 3, 1 ) ), -1 )