Repository navigation
fix(Geometry): tier 2 robustness fixes for degenerate inputs #1350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9226618
f0170a3
0cb2680
7520d0f
9954a5a
277d418
11e0f3f
0b5c331
31d436f
eb10fd2
e583f38
bb4e8c4
dd78ca3
60154c7
e56031e
dfbb566
c49c47f
7693197
feb1afc
a47191e
e2f5223
f164ce5
5fff17c
956ec85
c96cb56
f87d684
157faa9
dcad44c
221eac0
5fa318e
eaeaaed
667f3ed
6bc6f70
f79047f
f3667b0
9e4d1ad
085e6a2
fd73a33
8eb88c4
047c437
6586706
712b5a9
fe632c8
9720b70
feb062d
4210ba5
d361d07
b23aac1
7ba2fbc
082b75e
2c94610
3782a94
f54694f
bbf3d60
4427dd8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,8 @@ | |
| #include <geode/geometry/basic_objects/segment.hpp> | ||
| #include <geode/geometry/bounding_box.hpp> | ||
| #include <geode/geometry/distance.hpp> | ||
| #include <geode/geometry/perpendicular.hpp> | ||
| #include <geode/geometry/vector.hpp> | ||
|
|
||
| namespace | ||
| { | ||
|
|
@@ -73,6 +75,19 @@ namespace | |
| } | ||
| return result; | ||
| } | ||
|
|
||
| double squared_double_area( | ||
| const geode::Vector2D& edge0, const geode::Vector2D& edge1 ) | ||
| { | ||
| const auto double_area = geode::dot_perpendicular( edge0, edge1 ); | ||
| return double_area * double_area; | ||
| } | ||
|
|
||
| double squared_double_area( | ||
| const geode::Vector3D& edge0, const geode::Vector3D& edge1 ) | ||
| { | ||
| return edge0.cross( edge1 ).length2(); | ||
| } | ||
| } // namespace | ||
|
|
||
| namespace geode | ||
|
|
@@ -295,16 +310,18 @@ namespace geode | |
| template < typename PointType, index_t dimension > | ||
| bool GenericTriangle< PointType, dimension >::is_degenerated() const | ||
| { | ||
| const Point< dimension >& point0 = vertices_.at( 0 ); | ||
| const Point< dimension >& point1 = vertices_.at( 1 ); | ||
| const Segment< dimension > edge{ point0, point1 }; | ||
| if( edge.is_degenerated() ) | ||
| { | ||
| return true; | ||
| } | ||
| const Point< dimension >& point2 = vertices_.at( 2 ); | ||
| return point_line_distance( point2, InfiniteLine< dimension >{ edge } ) | ||
| <= GLOBAL_EPSILON; | ||
| // The triangle is degenerated if its minimum height, i.e. twice its | ||
| // area divided by its longest edge length, is below GLOBAL_EPSILON. | ||
| const Point< dimension >& point0 = vertices_[0]; | ||
| const Point< dimension >& point1 = vertices_[1]; | ||
| const Point< dimension >& point2 = vertices_[2]; | ||
| const Vector< dimension > edge01{ point0, point1 }; | ||
| const Vector< dimension > edge02{ point0, point2 }; | ||
| const Vector< dimension > edge12{ point1, point2 }; | ||
| const auto max_length2 = std::max( | ||
| { edge01.length2(), edge02.length2(), edge12.length2() } ); | ||
| return squared_double_area( edge01, edge02 ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same question than for tetrahedron. is it possible to have different response depending on which edges is given to squared_double_area. You need to check limit cases.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same answer as for the tetrahedron. |cross(e01, e02)| is the same for any pair of edges in exact arithmetic, and max_length2 is taken over all three edges. Rounding contributes about u·L² against a threshold of GLOBAL_EPSILON·L, so the result is the same whichever edges are used unless L ≳ 1e10.
|
||
| <= GLOBAL_EPSILON * GLOBAL_EPSILON * max_length2; | ||
| } | ||
|
|
||
| template < typename PointType, index_t dimension > | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.