Skip to content
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

fix(Geometry): better management of parallel case tests in intersection #999

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile bindings/python/requirements.in
# pip-compile --pre bindings/python/requirements.in
#
15 changes: 9 additions & 6 deletions src/geode/geometry/intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,14 @@ namespace geode
const auto segment_normalized_direction =
segment.normalized_direction();
auto d_dot_n = segment_normalized_direction.dot( normal );
auto d_dot_n_normalized =
segment_normalized_direction.dot( normal.normalize() );
signed_index_t sign;
if( d_dot_n > 0. )
if( d_dot_n_normalized > GLOBAL_EPSILON )
{
sign = 1;
}
else if( d_dot_n < -0. )
else if( d_dot_n_normalized < -GLOBAL_EPSILON )
{
sign = -1;
d_dot_n = -d_dot_n;
Expand Down Expand Up @@ -355,12 +357,13 @@ namespace geode
// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
auto d_dot_n = line.direction().dot( normal );
auto d_dot_n_normalized = line.direction().dot( normal.normalize() );
signed_index_t sign;
if( d_dot_n > 0. )
if( d_dot_n_normalized > GLOBAL_EPSILON )
{
sign = 1;
}
else if( d_dot_n < -0. )
else if( d_dot_n_normalized < -GLOBAL_EPSILON )
{
sign = -1;
d_dot_n = -d_dot_n;
Expand Down Expand Up @@ -427,7 +430,7 @@ namespace geode
const Vector2D diff{ line0.origin(), line1.origin() };
const auto D0DotPerpD1 =
dot_perpendicular( line0.direction(), line1.direction() );
if( std::fabs( D0DotPerpD1 ) < 0. )
if( std::fabs( D0DotPerpD1 ) < GLOBAL_EPSILON )
{
// The lines are parallel.
return { INTERSECTION_TYPE::parallel };
Expand Down Expand Up @@ -985,7 +988,7 @@ namespace geode
// The planes are parallel. Check if they are coplanar.
const auto constant_diff =
dot >= 0. ? constant0 - constant1 : constant0 + constant1;
if( std::fabs( constant_diff ) == 0. )
if( std::fabs( constant_diff ) < GLOBAL_EPSILON )
{
// The planes are coplanar.
return { INTERSECTION_TYPE::parallel };
Expand Down
Loading