Skip to content

Commit 7c973ee

Browse files
Merge pull request #1032 from Geode-solutions/fix/basic-obj-degen
fix(BasicObjects): add is_degenerated
2 parents 11e15b3 + ba20e6c commit 7c973ee

File tree

12 files changed

+83
-40
lines changed

12 files changed

+83
-40
lines changed

include/geode/geometry/basic_objects/infinite_line.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ namespace geode
3131
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerInfiniteLine );
3232
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerRay );
3333
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
34-
template < typename PointType, index_t dimension >
35-
class GenericSegment;
3634
FORWARD_DECLARATION_DIMENSION_CLASS( Segment );
37-
FORWARD_DECLARATION_DIMENSION_CLASS( OwnerSegment );
3835

3936
template < index_t dimension >
4037
using RefPoint = std::reference_wrapper< const Point< dimension > >;
@@ -47,9 +44,7 @@ namespace geode
4744
{
4845
public:
4946
GenericLine( const Vector< dimension >& direction, PointType origin );
50-
51-
explicit GenericLine(
52-
const GenericSegment< PointType, dimension >& segment );
47+
explicit GenericLine( const Segment< dimension >& segment );
5348
GenericLine( const GenericLine< PointType, dimension >& other );
5449
GenericLine< PointType, dimension >& operator=(
5550
const GenericLine< PointType, dimension >& other );
@@ -75,7 +70,7 @@ namespace geode
7570
explicit OwnerInfiniteLine(
7671
const Vector< dimension >& direction, Point< dimension > origin );
7772

78-
OwnerInfiniteLine( const Segment< dimension >& segment );
73+
explicit OwnerInfiniteLine( const Segment< dimension >& segment );
7974
OwnerInfiniteLine( const OwnerInfiniteLine< dimension >& other );
8075
OwnerInfiniteLine< dimension >& operator=(
8176
const OwnerInfiniteLine< dimension >& other );
@@ -94,7 +89,7 @@ namespace geode
9489
explicit OwnerRay(
9590
const Vector< dimension >& direction, Point< dimension > origin );
9691

97-
OwnerRay( const Segment< dimension >& segment );
92+
explicit OwnerRay( const Segment< dimension >& segment );
9893
OwnerRay( const OwnerRay< dimension >& other );
9994
OwnerRay< dimension >& operator=( const OwnerRay< dimension >& other );
10095
OwnerRay( OwnerRay< dimension >&& other ) noexcept;
@@ -111,7 +106,7 @@ namespace geode
111106
public:
112107
InfiniteLine( const Vector< dimension >& direction,
113108
const Point< dimension >& origin );
114-
InfiniteLine( const Segment< dimension >& segment );
109+
explicit InfiniteLine( const Segment< dimension >& segment );
115110

116111
InfiniteLine( const InfiniteLine< dimension >& other );
117112
InfiniteLine( const OwnerInfiniteLine< dimension >& other );

include/geode/geometry/basic_objects/plane.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
namespace geode
3030
{
3131
FORWARD_DECLARATION_DIMENSION_CLASS( Point );
32+
FORWARD_DECLARATION_DIMENSION_CLASS( Triangle );
33+
ALIAS_3D( Triangle );
3234
class OwnerPlane;
3335

3436
template < index_t dimension >
@@ -43,7 +45,7 @@ namespace geode
4345
{
4446
public:
4547
GenericPlane( const Vector3D& normal, PointType origin );
46-
48+
explicit GenericPlane( const Triangle3D& triangle );
4749
GenericPlane( const GenericPlane& other );
4850
GenericPlane& operator=( const GenericPlane& other );
4951
GenericPlane( GenericPlane&& other ) noexcept;
@@ -64,6 +66,7 @@ namespace geode
6466

6567
public:
6668
explicit OwnerPlane( const Vector3D& normal, Point3D origin );
69+
explicit OwnerPlane( const Triangle3D& triangle );
6770
OwnerPlane( const OwnerPlane& other );
6871
OwnerPlane& operator=( const OwnerPlane& other );
6972
OwnerPlane( OwnerPlane&& other ) noexcept;
@@ -76,7 +79,7 @@ namespace geode
7679

7780
public:
7881
Plane( const Vector3D& normal, const Point3D& origin );
79-
82+
explicit Plane( const Triangle3D& triangle );
8083
Plane( const Plane& other );
8184
Plane( const OwnerPlane& other );
8285
Plane& operator=( const Plane& other );

include/geode/geometry/basic_objects/segment.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace geode
6060
void set_point( local_index_t vertex, PointType point );
6161
[[nodiscard]] const std::array< PointType, 2 >& vertices() const;
6262
[[nodiscard]] BoundingBox< dimension > bounding_box() const;
63+
[[nodiscard]] bool is_degenerated() const;
6364

6465
private:
6566
std::array< PointType, 2 > vertices_;

include/geode/geometry/basic_objects/tetrahedron.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace geode
6464
void set_point( local_index_t vertex, PointType point );
6565
[[nodiscard]] const std::array< PointType, 4 >& vertices() const;
6666
[[nodiscard]] BoundingBox3D bounding_box() const;
67+
[[nodiscard]] bool is_degenerated() const;
6768

6869
private:
6970
std::array< PointType, 4 > vertices_;

include/geode/geometry/basic_objects/triangle.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace geode
8585
[[nodiscard]] BoundingBox< dimension > bounding_box() const;
8686
[[nodiscard]] local_index_t longest_edge_index() const;
8787
[[nodiscard]] double minimum_height() const;
88+
[[nodiscard]] bool is_degenerated() const;
8889

8990
private:
9091
std::array< PointType, 3 > vertices_;

src/geode/geometry/basic_objects/infinite_line.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace geode
3535
}
3636
template < typename PointType, index_t dimension >
3737
GenericLine< PointType, dimension >::GenericLine(
38-
const GenericSegment< PointType, dimension >& segment )
38+
const Segment< dimension >& segment )
3939
: GenericLine( segment.normalized_direction(), segment.vertices()[0] )
4040
{
4141
}
@@ -77,8 +77,7 @@ namespace geode
7777
template < index_t dimension >
7878
OwnerInfiniteLine< dimension >::OwnerInfiniteLine(
7979
const Segment< dimension >& segment )
80-
: OwnerInfiniteLine(
81-
segment.normalized_direction(), segment.vertices()[0] )
80+
: Base( segment )
8281
{
8382
}
8483
template < index_t dimension >
@@ -104,7 +103,7 @@ namespace geode
104103
template < index_t dimension >
105104
InfiniteLine< dimension >::InfiniteLine(
106105
const Segment< dimension >& segment )
107-
: InfiniteLine( segment.normalized_direction(), segment.vertices()[0] )
106+
: Base( segment )
108107
{
109108
}
110109
template < index_t dimension >
@@ -135,7 +134,7 @@ namespace geode
135134
}
136135
template < index_t dimension >
137136
OwnerRay< dimension >::OwnerRay( const Segment< dimension >& segment )
138-
: OwnerRay( segment.normalized_direction(), segment.vertices()[0] )
137+
: Base( segment )
139138
{
140139
}
141140
template < index_t dimension >
@@ -159,7 +158,7 @@ namespace geode
159158
}
160159
template < index_t dimension >
161160
Ray< dimension >::Ray( const Segment< dimension >& segment )
162-
: Ray( segment.normalized_direction(), segment.vertices()[0] )
161+
: Base( segment )
163162
{
164163
}
165164
template < index_t dimension >

src/geode/geometry/basic_objects/plane.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <geode/geometry/basic_objects/plane.hpp>
2525

26+
#include <geode/geometry/basic_objects/triangle.hpp>
27+
2628
namespace geode
2729
{
2830
template < typename PointType >
@@ -31,6 +33,13 @@ namespace geode
3133
: normal_( normal.normalize() ), origin_( std::move( origin ) )
3234
{
3335
}
36+
template < typename PointType >
37+
GenericPlane< PointType >::GenericPlane( const Triangle3D& triangle )
38+
: normal_( triangle.normal().value() ),
39+
origin_( triangle.vertices()[0] )
40+
{
41+
}
42+
3443
template < typename PointType >
3544
GenericPlane< PointType >::GenericPlane( const GenericPlane& ) = default;
3645
template < typename PointType >
@@ -69,6 +78,8 @@ namespace geode
6978
: Base( normal, std::move( origin ) )
7079
{
7180
}
81+
OwnerPlane::OwnerPlane( const Triangle3D& triangle ) : Base( triangle ) {}
82+
7283
OwnerPlane::OwnerPlane( const OwnerPlane& ) = default;
7384
OwnerPlane& OwnerPlane::operator=( const OwnerPlane& ) = default;
7485
OwnerPlane::OwnerPlane( OwnerPlane&& ) noexcept = default;
@@ -78,6 +89,8 @@ namespace geode
7889
: Base( normal, origin )
7990
{
8091
}
92+
Plane::Plane( const Triangle3D& triangle ) : Base( triangle ) {}
93+
8194
Plane::Plane( const Plane& ) = default;
8295
Plane::Plane( const OwnerPlane& other )
8396
: Base( other.normal(), other.origin() )

src/geode/geometry/basic_objects/segment.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ namespace geode
102102
return bbox;
103103
}
104104

105+
template < typename PointType, index_t dimension >
106+
bool GenericSegment< PointType, dimension >::is_degenerated() const
107+
{
108+
return length() <= GLOBAL_EPSILON;
109+
}
110+
105111
template < index_t dimension >
106112
OwnerSegment< dimension >::OwnerSegment(
107113
Point< dimension > point0, Point< dimension > point1 ) noexcept

src/geode/geometry/basic_objects/tetrahedron.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
#include <geode/geometry/basic_objects/tetrahedron.hpp>
2525

26+
#include <geode/geometry/basic_objects/plane.hpp>
27+
#include <geode/geometry/basic_objects/triangle.hpp>
2628
#include <geode/geometry/bounding_box.hpp>
29+
#include <geode/geometry/distance.hpp>
2730

2831
namespace geode
2932
{
@@ -79,6 +82,23 @@ namespace geode
7982
return bbox;
8083
}
8184

85+
template < typename PointType >
86+
bool GenericTetrahedron< PointType >::is_degenerated() const
87+
{
88+
const Point3D& point0 = vertices_.at( 0 );
89+
const Point3D& point1 = vertices_.at( 1 );
90+
const Point3D& point2 = vertices_.at( 2 );
91+
const Triangle3D triangle{ point0, point1, point2 };
92+
if( triangle.is_degenerated() )
93+
{
94+
return true;
95+
}
96+
const Point3D& point3 = vertices_.at( 3 );
97+
return std::get< 0 >(
98+
point_plane_distance( point3, Plane{ triangle } ) )
99+
<= GLOBAL_EPSILON;
100+
}
101+
82102
OwnerTetrahedron::OwnerTetrahedron( Point3D point0,
83103
Point3D point1,
84104
Point3D point2,

src/geode/geometry/basic_objects/triangle.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <absl/algorithm/container.h>
3131

3232
#include <geode/geometry/barycentric_coordinates.hpp>
33+
#include <geode/geometry/basic_objects/infinite_line.hpp>
3334
#include <geode/geometry/basic_objects/plane.hpp>
3435
#include <geode/geometry/basic_objects/segment.hpp>
3536
#include <geode/geometry/bounding_box.hpp>
@@ -269,6 +270,21 @@ namespace geode
269270
return point_segment_distance( opposite_vertex, longest_edge );
270271
}
271272

273+
template < typename PointType, index_t dimension >
274+
bool GenericTriangle< PointType, dimension >::is_degenerated() const
275+
{
276+
const Point< dimension >& point0 = vertices_.at( 0 );
277+
const Point< dimension >& point1 = vertices_.at( 1 );
278+
const Segment< dimension > edge{ point0, point1 };
279+
if( edge.is_degenerated() )
280+
{
281+
return true;
282+
}
283+
const Point< dimension >& point2 = vertices_.at( 2 );
284+
return point_line_distance( point2, InfiniteLine< dimension >{ edge } )
285+
<= GLOBAL_EPSILON;
286+
}
287+
272288
template < index_t dimension >
273289
OwnerTriangle< dimension >::OwnerTriangle( Point< dimension > point0,
274290
Point< dimension > point1,

0 commit comments

Comments
 (0)