Skip to content

Commit 51b031e

Browse files
committed
pierre's comment
1 parent 3ed9855 commit 51b031e

File tree

7 files changed

+45
-36
lines changed

7 files changed

+45
-36
lines changed

include/geode/geometry/basic_objects/ellipse.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ namespace geode
5959
other ) noexcept;
6060

6161
[[nodiscard]] const Point< dimension >& center() const;
62-
[[nodiscard]] const Frame< dimension >& axis() const;
62+
[[nodiscard]] const Frame< dimension >& axes() const;
6363

6464
private:
6565
PointType center_;
66-
FrameType axis_;
66+
FrameType axes_;
6767
};
6868

6969
template < index_t dimension >
@@ -76,7 +76,7 @@ namespace geode
7676

7777
public:
7878
explicit OwnerEllipse(
79-
Point< dimension > center, Frame< dimension > axis );
79+
Point< dimension > center, Frame< dimension > axes );
8080

8181
OwnerEllipse( const OwnerEllipse< dimension >& other );
8282
OwnerEllipse< dimension >& operator=(
@@ -98,7 +98,7 @@ namespace geode
9898

9999
public:
100100
Ellipse(
101-
const Point< dimension >& center, const Frame< dimension >& axis );
101+
const Point< dimension >& center, const Frame< dimension >& axes );
102102
Ellipse( const Ellipse< dimension >& other );
103103
Ellipse( const OwnerEllipse< dimension >& other );
104104
Ellipse< dimension >& operator=( const Ellipse< dimension >& other );

include/geode/geometry/distance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ namespace geode
233233
point_disk_distance( const Point3D& point, const Disk& disk );
234234

235235
/*!
236-
* Compute the smallest distance between a point and a ellipse
236+
* Compute the smallest distance between a point and an ellipse
237237
* @return a tuple containing:
238238
* - the smallest distance.
239239
* - the closest point on the ellipse.

include/geode/geometry/intersection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ namespace geode
234234
const Plane& plane0, const Plane& plane1 );
235235

236236
/*!
237-
* Compute the intersection between a segment and a ellipse
237+
* Compute the intersection between a segment and an ellipse
238238
* @return an optional of the intersection points.
239239
*/
240240
template < index_t dimension >
@@ -245,7 +245,7 @@ namespace geode
245245
const Ellipse< dimension >& ellipse );
246246

247247
/*!
248-
* Compute the intersection between a line and a ellipse
248+
* Compute the intersection between a line and an ellipse
249249
* @return an optional of the intersection points.
250250
*/
251251
template < index_t dimension >

src/geode/geometry/basic_objects/ellipse.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ namespace geode
2727
{
2828
template < typename PointType, typename FrameType, index_t dimension >
2929
GenericEllipse< PointType, FrameType, dimension >::GenericEllipse(
30-
PointType center, FrameType axis )
31-
: center_( std::move( center ) ), axis_( std::move( axis ) )
30+
PointType center, FrameType axes )
31+
: center_( std::move( center ) ), axes_( std::move( axes ) )
3232
{
3333
}
3434
template < typename PointType, typename FrameType, index_t dimension >
@@ -58,15 +58,15 @@ namespace geode
5858
}
5959
template < typename PointType, typename FrameType, index_t dimension >
6060
const Frame< dimension >&
61-
GenericEllipse< PointType, FrameType, dimension >::axis() const
61+
GenericEllipse< PointType, FrameType, dimension >::axes() const
6262
{
63-
return axis_;
63+
return axes_;
6464
}
6565

6666
template < index_t dimension >
6767
OwnerEllipse< dimension >::OwnerEllipse(
68-
Point< dimension > center, Frame< dimension > axis )
69-
: Base( std::move( center ), std::move( axis ) )
68+
Point< dimension > center, Frame< dimension > axes )
69+
: Base( std::move( center ), std::move( axes ) )
7070
{
7171
}
7272
template < index_t dimension >
@@ -84,15 +84,15 @@ namespace geode
8484

8585
template < index_t dimension >
8686
Ellipse< dimension >::Ellipse(
87-
const Point< dimension >& center, const Frame< dimension >& axis )
88-
: Base( center, axis )
87+
const Point< dimension >& center, const Frame< dimension >& axes )
88+
: Base( center, axes )
8989
{
9090
}
9191
template < index_t dimension >
9292
Ellipse< dimension >::Ellipse( const Ellipse< dimension >& ) = default;
9393
template < index_t dimension >
9494
Ellipse< dimension >::Ellipse( const OwnerEllipse< dimension >& other )
95-
: Base( other.center(), other.axis() )
95+
: Base( other.center(), other.axes() )
9696
{
9797
}
9898
template < index_t dimension >

src/geode/geometry/distance.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ namespace geode
12901290
for( const auto i : geode::LRange{ dimension } )
12911291
{
12921292
auto& [extent, axis] = axis_sorted_by_decreasing_extent.at( i );
1293-
extent = ellipse.axis().direction( i ).length();
1293+
extent = ellipse.axes().direction( i ).length();
12941294
axis = i;
12951295
};
12961296
absl::c_sort( axis_sorted_by_decreasing_extent,
@@ -1309,7 +1309,7 @@ namespace geode
13091309
for( const auto i : geode::LRange{ dimension } )
13101310
{
13111311
const auto j = axis_sorted_by_decreasing_extent[i].second;
1312-
extents[i] = ellipse.axis().direction( j ).length();
1312+
extents[i] = ellipse.axes().direction( j ).length();
13131313
locY[i] = std::fabs( query_point_coordinates[j] );
13141314
}
13151315
auto [squared_distance_special, closest_point_coordinates] =
@@ -1340,7 +1340,7 @@ namespace geode
13401340
for( const auto i : geode::LRange{ dimension } )
13411341
{
13421342
point_coordinates[i] = center_to_point.dot(
1343-
ellipse.axis().direction( i ).normalize() );
1343+
ellipse.axes().direction( i ).normalize() );
13441344
}
13451345
auto& [distance, closest_point] = result;
13461346
const auto [squared_distance, closest_point_result] =
@@ -1349,7 +1349,7 @@ namespace geode
13491349
closest_point = ellipse.center();
13501350
for( const auto i : geode::LRange{ dimension } )
13511351
{
1352-
closest_point += ellipse.axis().direction( i ).normalize()
1352+
closest_point += ellipse.axes().direction( i ).normalize()
13531353
* closest_point_result.value( i );
13541354
}
13551355
return result;

src/geode/geometry/intersection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,8 @@ namespace geode
10201020
geode::SquareMatrix< dimension > M( 0 );
10211021
for( const auto i : geode::LRange{ dimension } )
10221022
{
1023-
const auto ratio = ellipse.axis().direction( i ).normalize()
1024-
* ( 1 / ellipse.axis().direction( i ).length() );
1023+
const auto ratio = ellipse.axes().direction( i ).normalize()
1024+
* ( 1 / ellipse.axes().direction( i ).length() );
10251025
geode::SquareMatrix< dimension > M_i;
10261026
for( const auto j : geode::LRange{ dimension } )
10271027
{
@@ -1077,7 +1077,7 @@ namespace geode
10771077
return { std::move( results ),
10781078
{ first_correctness, second_correctness } };
10791079
}
1080-
else if( discr > -GLOBAL_EPSILON )
1080+
if( discr > -GLOBAL_EPSILON )
10811081
{
10821082
absl::InlinedVector< Point< dimension >, 2 > results;
10831083
results.reserve( 1 );

tests/geometry/test-distance.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,30 @@ void test_point_segment_distance_3d()
105105
distance = geode::point_segment_distance( a, segment3D );
106106
OPENGEODE_EXCEPTION( distance < geode::GLOBAL_EPSILON
107107
&& geode::point_segment_projection( a, segment3D )
108-
.inexact_equal( a ),
108+
.inexact_equal( a ),
109109
"[Test] Wrong result for point_segment_distance with query Point3D "
110110
"a" );
111111

112112
distance = geode::point_segment_distance( b, segment3D );
113113
OPENGEODE_EXCEPTION( distance < geode::GLOBAL_EPSILON
114114
&& geode::point_segment_projection( b, segment3D )
115-
.inexact_equal( b ),
115+
.inexact_equal( b ),
116116
"[Test] Wrong result for point_segment_distance with query Point3D "
117117
"b" );
118118

119119
const geode::Point3D q1{ { 0.0, 0.0, 0.0 } };
120120
distance = geode::point_segment_distance( q1, segment3D );
121121
OPENGEODE_EXCEPTION( distance < geode::GLOBAL_EPSILON
122122
&& geode::point_segment_projection( q1, segment3D )
123-
.inexact_equal( q1 ),
123+
.inexact_equal( q1 ),
124124
"[Test] Wrong result for point_segment_distance with query Point3D "
125125
"q1" );
126126

127127
const geode::Point3D q2{ { 10.0, 10.0, 10.0 } };
128128
distance = geode::point_segment_distance( q2, segment3D );
129129
OPENGEODE_EXCEPTION( distance == std::sqrt( 170 )
130130
&& geode::point_segment_projection( q2, segment3D )
131-
.inexact_equal( a ),
131+
.inexact_equal( a ),
132132
"[Test] Wrong result for point_segment_distance with query Point3D "
133133
"q2" );
134134

@@ -137,7 +137,7 @@ void test_point_segment_distance_3d()
137137
const geode::Point3D result_q3{ { 0.0, 0.0, 0.0 } };
138138
OPENGEODE_EXCEPTION( distance == std::sqrt( 26 )
139139
&& geode::point_segment_projection( q3, segment3D )
140-
.inexact_equal( result_q3 ),
140+
.inexact_equal( result_q3 ),
141141
"[Test] Wrong result for point_segment_distance with query Point3D "
142142
"q3" );
143143

@@ -149,7 +149,7 @@ void test_point_segment_distance_3d()
149149
std::sqrt( 5.05 * 5.05 + 0.75 * 0.75 + 0.65 * 0.65 ) - distance )
150150
< geode::GLOBAL_EPSILON
151151
&& geode::point_segment_projection( q4, segment3D )
152-
.inexact_equal( result_q4 ),
152+
.inexact_equal( result_q4 ),
153153
"[Test] Wrong result for point_segment_distance with query Point3D "
154154
"q4" );
155155
}
@@ -597,7 +597,7 @@ void test_point_line_distance_2d()
597597
OPENGEODE_EXCEPTION(
598598
std::fabs( std::sqrt( 26 ) - distance ) < geode::GLOBAL_EPSILON
599599
&& geode::point_line_projection( q2, line2D )
600-
.inexact_equal( result_q2 ),
600+
.inexact_equal( result_q2 ),
601601
"[Test] Wrong result for point_line_distance with query Point2D "
602602
"q2" );
603603
}
@@ -647,7 +647,7 @@ void test_point_line_signed_distance_2d()
647647
OPENGEODE_EXCEPTION(
648648
std::fabs( std::sqrt( 26 ) - distance ) < geode::GLOBAL_EPSILON
649649
&& geode::point_line_projection( q3, line2D )
650-
.inexact_equal( result_q3 ),
650+
.inexact_equal( result_q3 ),
651651
"[Test] Wrong result for point_line_signed_distance with query Point2D "
652652
"q3" );
653653

@@ -657,7 +657,7 @@ void test_point_line_signed_distance_2d()
657657
OPENGEODE_EXCEPTION(
658658
std::fabs( -std::sqrt( 26 ) - distance ) < geode::GLOBAL_EPSILON
659659
&& geode::point_line_projection( q4, line2D )
660-
.inexact_equal( result_q3 ),
660+
.inexact_equal( result_q3 ),
661661
"[Test] Wrong result for point_line_signed_distance with query Point2D "
662662
"q4" );
663663
}
@@ -699,7 +699,7 @@ void test_point_line_distance_3d()
699699
OPENGEODE_EXCEPTION(
700700
std::fabs( std::sqrt( 26 ) - distance ) < geode::GLOBAL_EPSILON
701701
&& geode::point_line_projection( q2, line3D )
702-
.inexact_equal( result_q2 ),
702+
.inexact_equal( result_q2 ),
703703
"[Test] Wrong result for point_line_distance with query Point3D "
704704
"q2" );
705705
}
@@ -1127,14 +1127,16 @@ void test_point_ellipse_distance_2d_not_aligned()
11271127
{
11281128
const geode::Point2D center{ { 0.0, 0.0 } };
11291129
const geode::Vector2D first_axis{ { 1.0, 1.0 } };
1130-
const geode::Vector2D second_axis{ { -1.0, 1.0 } };
1130+
const geode::Vector2D second_axis{ { -2.0, 2.0 } };
11311131
const geode::Frame2D frame{ { first_axis, second_axis } };
11321132
const geode::Ellipse2D ellipse{ center, frame };
11331133
const geode::Point2D point{ { 2.0, 2.0 } };
11341134
const auto [distance, closest_point] =
11351135
geode::point_ellipse_distance( point, ellipse );
11361136
const geode::Point2D result{ { 1.0, 1.0 } };
1137-
OPENGEODE_EXCEPTION( closest_point.inexact_equal( result ),
1137+
OPENGEODE_EXCEPTION(
1138+
std::fabs( std::sqrt( 2 ) - distance ) < geode::GLOBAL_EPSILON
1139+
&& closest_point.inexact_equal( result ),
11381140
"[Test] Wrong result for point_ellipse_distance_2d_not_aligned" );
11391141
}
11401142

@@ -1180,11 +1182,18 @@ void test_point_ellipse_distance_3d()
11801182
&& outside3_closest_point.inexact_equal( result_outside3 ),
11811183
"[Test] Wrong result for point_ellipse_distance_3d with outside3 "
11821184
"point" );
1185+
const auto [inside_distance, inside_closest_point] =
1186+
geode::point_ellipse_distance( center, ellipse );
1187+
const geode::Point3D result_inside{ { 0, 0, 1 } };
1188+
OPENGEODE_EXCEPTION(
1189+
inside_distance == 1
1190+
&& inside_closest_point.inexact_equal( result_inside ),
1191+
"[Test] Wrong result for point_ellipse_distance_3d with inside "
1192+
"point" );
11831193
}
11841194

11851195
void test_point_ellipse_distance()
11861196
{
1187-
geode::Logger::set_level( geode::Logger::LEVEL::trace );
11881197
test_point_ellipse_distance_2d();
11891198
test_point_ellipse_distance_3d();
11901199
test_point_ellipse_distance_2d_not_aligned();

0 commit comments

Comments
 (0)