Skip to content

Commit

Permalink
Added Edge#euclidian_distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Dec 7, 2023
1 parent 787114f commit b6d3f8b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
20 changes: 19 additions & 1 deletion src/db/db/gsiDeclDbEdge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
14 changes: 10 additions & 4 deletions testdata/ruby/dbEdgeTest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def test_1_DEdge
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 )
Expand Down Expand Up @@ -224,10 +227,13 @@ def test_1_Edge
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 )

Expand Down

0 comments on commit b6d3f8b

Please sign in to comment.