fix(Distace): use dichotomic method to compute segment segment distan…#1244
fix(Distace): use dichotomic method to compute segment segment distan…#1244
Conversation
…ce in case first method can't be precise enough
src/geode/geometry/distance.cpp
Outdated
| const geode::Segment< dimension >& segment0, | ||
| const geode::Segment< dimension >& segment1 ) | ||
| { | ||
| auto current_point = segment0.barycenter(); |
There was a problem hiding this comment.
Why segment0? Should we choose the longest segment?
| std::optional< std::tuple< double, | ||
| geode::Point< dimension >, | ||
| geode::Point< dimension > > > | ||
| approximate_segment_segment_distance( |
There was a problem hiding this comment.
warning: function 'approximate_segment_segment_distance' has cognitive complexity of 98 (threshold 10) [readability-function-cognitive-complexity]
approximate_segment_segment_distance(
^Additional context
src/geode/geometry/distance.cpp:501: +1, including nesting penalty of 0, nesting level increased to 1
if( std::log2( std::abs( ac ) / std::abs( ac - bb ) ) > 20 )
^src/geode/geometry/distance.cpp:507: +1, including nesting penalty of 0, nesting level increased to 1
if( det > 0 )
^src/geode/geometry/distance.cpp:511: +2, including nesting penalty of 1, nesting level increased to 2
if( bte <= ctd ) // s <= 0
^src/geode/geometry/distance.cpp:514: +3, including nesting penalty of 2, nesting level increased to 3
if( e <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:519: +4, including nesting penalty of 3, nesting level increased to 4
if( nd >= a )
^src/geode/geometry/distance.cpp:523: +1, nesting level increased to 4
else if( nd > 0 )
^src/geode/geometry/distance.cpp:529: +1, nesting level increased to 3
else if( e < c ) // 0 < t < 1
^src/geode/geometry/distance.cpp:534: +1, nesting level increased to 3
else // t >= 1
^src/geode/geometry/distance.cpp:539: +4, including nesting penalty of 3, nesting level increased to 4
if( bmd >= a )
^src/geode/geometry/distance.cpp:543: +1, nesting level increased to 4
else if( bmd > 0 )
^src/geode/geometry/distance.cpp:550: +1, nesting level increased to 2
else // s > 0
^src/geode/geometry/distance.cpp:552: +3, including nesting penalty of 2, nesting level increased to 3
if( std::log2( std::abs( bte ) / std::abs( bte - ctd ) ) > 20 )
^src/geode/geometry/distance.cpp:557: +3, including nesting penalty of 2, nesting level increased to 3
if( s >= det ) // s >= 1
^src/geode/geometry/distance.cpp:562: +4, including nesting penalty of 3, nesting level increased to 4
if( bpe <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:567: +5, including nesting penalty of 4, nesting level increased to 5
if( nd <= 0 )
^src/geode/geometry/distance.cpp:571: +1, nesting level increased to 5
else if( nd < a )
^src/geode/geometry/distance.cpp:577: +1, nesting level increased to 4
else if( bpe < c ) // 0 < t < 1
^src/geode/geometry/distance.cpp:582: +1, nesting level increased to 4
else // t >= 1
^src/geode/geometry/distance.cpp:587: +5, including nesting penalty of 4, nesting level increased to 5
if( bmd <= 0 )
^src/geode/geometry/distance.cpp:591: +1, nesting level increased to 5
else if( bmd < a )
^src/geode/geometry/distance.cpp:598: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:602: +4, including nesting penalty of 3, nesting level increased to 4
if( ate <= btd ) // t <= 0
^src/geode/geometry/distance.cpp:607: +5, including nesting penalty of 4, nesting level increased to 5
if( nd <= 0 )
^src/geode/geometry/distance.cpp:611: +1, nesting level increased to 5
else if( nd >= a )
^src/geode/geometry/distance.cpp:615: +1, nesting level increased to 5
else
^src/geode/geometry/distance.cpp:620: +1, nesting level increased to 4
else // t > 0
^src/geode/geometry/distance.cpp:622: +5, including nesting penalty of 4, nesting level increased to 5
if( std::log2( std::abs( ate ) / std::abs( ate - btd ) )
^src/geode/geometry/distance.cpp:628: +5, including nesting penalty of 4, nesting level increased to 5
if( t >= det ) // t >= 1
^src/geode/geometry/distance.cpp:633: +6, including nesting penalty of 5, nesting level increased to 6
if( bmd <= 0 )
^src/geode/geometry/distance.cpp:637: +1, nesting level increased to 6
else if( bmd >= a )
^src/geode/geometry/distance.cpp:641: +1, nesting level increased to 6
else
^src/geode/geometry/distance.cpp:646: +1, nesting level increased to 5
else // 0 < t < 1
^src/geode/geometry/distance.cpp:656: +1, nesting level increased to 1
else
^src/geode/geometry/distance.cpp:676: +2, including nesting penalty of 1, nesting level increased to 2
if( e <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:681: +3, including nesting penalty of 2, nesting level increased to 3
if( nd <= 0 ) // s <= 0
^src/geode/geometry/distance.cpp:686: +1, nesting level increased to 3
else if( nd >= a ) // s >= 1
^src/geode/geometry/distance.cpp:691: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:697: +1, nesting level increased to 2
else if( e >= c ) // t >= 1
^src/geode/geometry/distance.cpp:702: +3, including nesting penalty of 2, nesting level increased to 3
if( bmd <= 0 ) // s <= 0
^src/geode/geometry/distance.cpp:707: +1, nesting level increased to 3
else if( bmd >= a ) // s >= 1
^src/geode/geometry/distance.cpp:712: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:718: +1, nesting level increased to 2
else // 0 < t < 1
^src/geode/geometry/distance.cpp:733: +1, including nesting penalty of 0, nesting level increased to 1
if( distance < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:740: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest0 < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:747: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest1 < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:753: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest0 < distance )
^src/geode/geometry/distance.cpp:755: +2, including nesting penalty of 1, nesting level increased to 2
if( distance_to_closest1 < distance_to_closest0 )
^src/geode/geometry/distance.cpp:764: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest1 < distance )
^| std::optional< std::tuple< double, | ||
| geode::Point< dimension >, | ||
| geode::Point< dimension > > > | ||
| approximate_segment_segment_distance( |
There was a problem hiding this comment.
warning: function 'approximate_segment_segment_distance' is declared in an anonymous namespace; prefer using 'static' for restricting visibility [llvm-prefer-static-over-anonymous-namespace]
approximate_segment_segment_distance(
^| const auto P1mP0 = segment0.direction(); | ||
| const auto Q1mQ0 = segment1.direction(); | ||
| const Vector< dimension > P0mQ0{ segment1.vertices()[0], | ||
| const geode::Vector< dimension > P0mQ0{ segment1.vertices()[0], |
There was a problem hiding this comment.
warning: invalid case style for variable 'P0mQ0' [readability-identifier-naming]
| const geode::Vector< dimension > P0mQ0{ segment1.vertices()[0], | |
| const geode::Vector< dimension > p0m_q0{ segment1.vertices()[0], |
src/geode/geometry/distance.cpp:497:
- const auto d = P1mP0.dot( P0mQ0 );
- const auto e = Q1mQ0.dot( P0mQ0 );
+ const auto d = P1mP0.dot( p0m_q0 );
+ const auto e = Q1mQ0.dot( p0m_q0 );| const auto d = P1mP0.dot( P0mQ0 ); | ||
| const auto e = Q1mQ0.dot( P0mQ0 ); | ||
| const auto det = a * c - b * b; | ||
| const auto ac = a * c; |
There was a problem hiding this comment.
warning: variable name 'ac' is too short, expected at least 3 characters [readability-identifier-length]
const auto ac = a * c;
^| const auto e = Q1mQ0.dot( P0mQ0 ); | ||
| const auto det = a * c - b * b; | ||
| const auto ac = a * c; | ||
| const auto bb = b * b; |
There was a problem hiding this comment.
warning: variable name 'bb' is too short, expected at least 3 characters [readability-identifier-length]
const auto bb = b * b;
^| } | ||
| else // s > 0 | ||
| { | ||
| if( std::log2( std::abs( bte ) / std::abs( bte - ctd ) ) > 20 ) |
There was a problem hiding this comment.
warning: 20 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]
if( std::log2( std::abs( bte ) / std::abs( bte - ctd ) ) > 20 )
^| else // t > 0 | ||
| { | ||
| if( std::log2( std::abs( ate ) / std::abs( ate - btd ) ) | ||
| > 20 ) |
There was a problem hiding this comment.
warning: 20 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]
> 20 )
^|
|
||
| template < geode::index_t dimension > | ||
| std::tuple< double, geode::Point< dimension >, geode::Point< dimension > > | ||
| dichotomic_segment_segment_distance( |
There was a problem hiding this comment.
warning: function 'dichotomic_segment_segment_distance' is declared in an anonymous namespace; prefer using 'static' for restricting visibility [llvm-prefer-static-over-anonymous-namespace]
dichotomic_segment_segment_distance(
^| while( step > geode::GLOBAL_EPSILON ) | ||
| { | ||
| const auto point_at_step_plus = | ||
| current_point + segment_direction * step; |
There was a problem hiding this comment.
warning: '*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
| current_point + segment_direction * step; | |
| current_point + (segment_direction * step); |
| const auto point_at_step_plus = | ||
| current_point + segment_direction * step; | ||
| const auto point_at_step_minus = | ||
| current_point - segment_direction * step; |
There was a problem hiding this comment.
warning: '*' has higher precedence than '-'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]
| current_point - segment_direction * step; | |
| current_point - (segment_direction * step); |
| std::optional< std::tuple< double, | ||
| geode::Point< dimension >, | ||
| geode::Point< dimension > > > | ||
| approximate_segment_segment_distance( |
There was a problem hiding this comment.
warning: function 'approximate_segment_segment_distance' has cognitive complexity of 99 (threshold 10) [readability-function-cognitive-complexity]
approximate_segment_segment_distance(
^Additional context
src/geode/geometry/distance.cpp:502: +1, including nesting penalty of 0, nesting level increased to 1
if( ac > bb )
^src/geode/geometry/distance.cpp:504: +2, including nesting penalty of 1, nesting level increased to 2
if( std::log2( std::abs( ac ) / std::abs( ac - bb ) ) > 20 )
^src/geode/geometry/distance.cpp:511: +2, including nesting penalty of 1, nesting level increased to 2
if( bte <= ctd ) // s <= 0
^src/geode/geometry/distance.cpp:514: +3, including nesting penalty of 2, nesting level increased to 3
if( e <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:519: +4, including nesting penalty of 3, nesting level increased to 4
if( nd >= a )
^src/geode/geometry/distance.cpp:523: +1, nesting level increased to 4
else if( nd > 0 )
^src/geode/geometry/distance.cpp:529: +1, nesting level increased to 3
else if( e < c ) // 0 < t < 1
^src/geode/geometry/distance.cpp:534: +1, nesting level increased to 3
else // t >= 1
^src/geode/geometry/distance.cpp:539: +4, including nesting penalty of 3, nesting level increased to 4
if( bmd >= a )
^src/geode/geometry/distance.cpp:543: +1, nesting level increased to 4
else if( bmd > 0 )
^src/geode/geometry/distance.cpp:550: +1, nesting level increased to 2
else // s > 0
^src/geode/geometry/distance.cpp:552: +3, including nesting penalty of 2, nesting level increased to 3
if( std::log2( std::abs( bte ) / std::abs( bte - ctd ) ) > 20 )
^src/geode/geometry/distance.cpp:557: +3, including nesting penalty of 2, nesting level increased to 3
if( s >= det ) // s >= 1
^src/geode/geometry/distance.cpp:562: +4, including nesting penalty of 3, nesting level increased to 4
if( bpe <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:567: +5, including nesting penalty of 4, nesting level increased to 5
if( nd <= 0 )
^src/geode/geometry/distance.cpp:571: +1, nesting level increased to 5
else if( nd < a )
^src/geode/geometry/distance.cpp:577: +1, nesting level increased to 4
else if( bpe < c ) // 0 < t < 1
^src/geode/geometry/distance.cpp:582: +1, nesting level increased to 4
else // t >= 1
^src/geode/geometry/distance.cpp:587: +5, including nesting penalty of 4, nesting level increased to 5
if( bmd <= 0 )
^src/geode/geometry/distance.cpp:591: +1, nesting level increased to 5
else if( bmd < a )
^src/geode/geometry/distance.cpp:598: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:602: +4, including nesting penalty of 3, nesting level increased to 4
if( ate <= btd ) // t <= 0
^src/geode/geometry/distance.cpp:607: +5, including nesting penalty of 4, nesting level increased to 5
if( nd <= 0 )
^src/geode/geometry/distance.cpp:611: +1, nesting level increased to 5
else if( nd >= a )
^src/geode/geometry/distance.cpp:615: +1, nesting level increased to 5
else
^src/geode/geometry/distance.cpp:620: +1, nesting level increased to 4
else // t > 0
^src/geode/geometry/distance.cpp:622: +5, including nesting penalty of 4, nesting level increased to 5
if( std::log2( std::abs( ate ) / std::abs( ate - btd ) )
^src/geode/geometry/distance.cpp:628: +5, including nesting penalty of 4, nesting level increased to 5
if( t >= det ) // t >= 1
^src/geode/geometry/distance.cpp:633: +6, including nesting penalty of 5, nesting level increased to 6
if( bmd <= 0 )
^src/geode/geometry/distance.cpp:637: +1, nesting level increased to 6
else if( bmd >= a )
^src/geode/geometry/distance.cpp:641: +1, nesting level increased to 6
else
^src/geode/geometry/distance.cpp:646: +1, nesting level increased to 5
else // 0 < t < 1
^src/geode/geometry/distance.cpp:656: +1, nesting level increased to 1
else
^src/geode/geometry/distance.cpp:676: +2, including nesting penalty of 1, nesting level increased to 2
if( e <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:681: +3, including nesting penalty of 2, nesting level increased to 3
if( nd <= 0 ) // s <= 0
^src/geode/geometry/distance.cpp:686: +1, nesting level increased to 3
else if( nd >= a ) // s >= 1
^src/geode/geometry/distance.cpp:691: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:697: +1, nesting level increased to 2
else if( e >= c ) // t >= 1
^src/geode/geometry/distance.cpp:702: +3, including nesting penalty of 2, nesting level increased to 3
if( bmd <= 0 ) // s <= 0
^src/geode/geometry/distance.cpp:707: +1, nesting level increased to 3
else if( bmd >= a ) // s >= 1
^src/geode/geometry/distance.cpp:712: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:718: +1, nesting level increased to 2
else // 0 < t < 1
^src/geode/geometry/distance.cpp:733: +1, including nesting penalty of 0, nesting level increased to 1
if( distance < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:740: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest0 < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:747: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest1 < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:753: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest0 < distance )
^src/geode/geometry/distance.cpp:755: +2, including nesting penalty of 1, nesting level increased to 2
if( distance_to_closest1 < distance_to_closest0 )
^src/geode/geometry/distance.cpp:764: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest1 < distance )
^| if( det > 0 ) | ||
| if( ac > bb ) | ||
| { | ||
| if( std::log2( std::abs( ac ) / std::abs( ac - bb ) ) > 20 ) |
There was a problem hiding this comment.
warning: 20 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers]
if( std::log2( std::abs( ac ) / std::abs( ac - bb ) ) > 20 )
^| std::optional< std::tuple< double, | ||
| geode::Point< dimension >, | ||
| geode::Point< dimension > > > | ||
| approximate_segment_segment_distance( |
There was a problem hiding this comment.
warning: function 'approximate_segment_segment_distance' has cognitive complexity of 99 (threshold 10) [readability-function-cognitive-complexity]
approximate_segment_segment_distance(
^Additional context
src/geode/geometry/distance.cpp:504: +1, including nesting penalty of 0, nesting level increased to 1
if( ac > bb )
^src/geode/geometry/distance.cpp:506: +2, including nesting penalty of 1, nesting level increased to 2
if( std::log2( std::abs( ac ) / std::abs( ac - bb ) ) > 20 )
^src/geode/geometry/distance.cpp:515: +2, including nesting penalty of 1, nesting level increased to 2
if( bte <= ctd ) // s <= 0
^src/geode/geometry/distance.cpp:518: +3, including nesting penalty of 2, nesting level increased to 3
if( e <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:523: +4, including nesting penalty of 3, nesting level increased to 4
if( nd >= a )
^src/geode/geometry/distance.cpp:527: +1, nesting level increased to 4
else if( nd > 0 )
^src/geode/geometry/distance.cpp:533: +1, nesting level increased to 3
else if( e < c ) // 0 < t < 1
^src/geode/geometry/distance.cpp:538: +1, nesting level increased to 3
else // t >= 1
^src/geode/geometry/distance.cpp:543: +4, including nesting penalty of 3, nesting level increased to 4
if( bmd >= a )
^src/geode/geometry/distance.cpp:547: +1, nesting level increased to 4
else if( bmd > 0 )
^src/geode/geometry/distance.cpp:554: +1, nesting level increased to 2
else // s > 0
^src/geode/geometry/distance.cpp:556: +3, including nesting penalty of 2, nesting level increased to 3
if( std::log2( std::abs( bte ) / std::abs( bte - ctd ) ) > 20 )
^src/geode/geometry/distance.cpp:563: +3, including nesting penalty of 2, nesting level increased to 3
if( s >= det ) // s >= 1
^src/geode/geometry/distance.cpp:568: +4, including nesting penalty of 3, nesting level increased to 4
if( bpe <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:573: +5, including nesting penalty of 4, nesting level increased to 5
if( nd <= 0 )
^src/geode/geometry/distance.cpp:577: +1, nesting level increased to 5
else if( nd < a )
^src/geode/geometry/distance.cpp:583: +1, nesting level increased to 4
else if( bpe < c ) // 0 < t < 1
^src/geode/geometry/distance.cpp:588: +1, nesting level increased to 4
else // t >= 1
^src/geode/geometry/distance.cpp:593: +5, including nesting penalty of 4, nesting level increased to 5
if( bmd <= 0 )
^src/geode/geometry/distance.cpp:597: +1, nesting level increased to 5
else if( bmd < a )
^src/geode/geometry/distance.cpp:604: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:608: +4, including nesting penalty of 3, nesting level increased to 4
if( ate <= btd ) // t <= 0
^src/geode/geometry/distance.cpp:613: +5, including nesting penalty of 4, nesting level increased to 5
if( nd <= 0 )
^src/geode/geometry/distance.cpp:617: +1, nesting level increased to 5
else if( nd >= a )
^src/geode/geometry/distance.cpp:621: +1, nesting level increased to 5
else
^src/geode/geometry/distance.cpp:626: +1, nesting level increased to 4
else // t > 0
^src/geode/geometry/distance.cpp:628: +5, including nesting penalty of 4, nesting level increased to 5
if( std::log2( std::abs( ate ) / std::abs( ate - btd ) )
^src/geode/geometry/distance.cpp:636: +5, including nesting penalty of 4, nesting level increased to 5
if( t >= det ) // t >= 1
^src/geode/geometry/distance.cpp:641: +6, including nesting penalty of 5, nesting level increased to 6
if( bmd <= 0 )
^src/geode/geometry/distance.cpp:645: +1, nesting level increased to 6
else if( bmd >= a )
^src/geode/geometry/distance.cpp:649: +1, nesting level increased to 6
else
^src/geode/geometry/distance.cpp:654: +1, nesting level increased to 5
else // 0 < t < 1
^src/geode/geometry/distance.cpp:664: +1, nesting level increased to 1
else
^src/geode/geometry/distance.cpp:684: +2, including nesting penalty of 1, nesting level increased to 2
if( e <= 0 ) // t <= 0
^src/geode/geometry/distance.cpp:689: +3, including nesting penalty of 2, nesting level increased to 3
if( nd <= 0 ) // s <= 0
^src/geode/geometry/distance.cpp:694: +1, nesting level increased to 3
else if( nd >= a ) // s >= 1
^src/geode/geometry/distance.cpp:699: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:705: +1, nesting level increased to 2
else if( e >= c ) // t >= 1
^src/geode/geometry/distance.cpp:710: +3, including nesting penalty of 2, nesting level increased to 3
if( bmd <= 0 ) // s <= 0
^src/geode/geometry/distance.cpp:715: +1, nesting level increased to 3
else if( bmd >= a ) // s >= 1
^src/geode/geometry/distance.cpp:720: +1, nesting level increased to 3
else // 0 < s < 1
^src/geode/geometry/distance.cpp:726: +1, nesting level increased to 2
else // 0 < t < 1
^src/geode/geometry/distance.cpp:741: +1, including nesting penalty of 0, nesting level increased to 1
if( distance < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:748: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest0 < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:755: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest1 < geode::GLOBAL_EPSILON )
^src/geode/geometry/distance.cpp:761: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest0 < distance )
^src/geode/geometry/distance.cpp:763: +2, including nesting penalty of 1, nesting level increased to 2
if( distance_to_closest1 < distance_to_closest0 )
^src/geode/geometry/distance.cpp:772: +1, including nesting penalty of 0, nesting level increased to 1
if( distance_to_closest1 < distance )
^|
🎉 This PR is included in version 16.1.1-rc.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 16.2.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
…ce in case first method can't be precise enough