Skip to content

Commit 874499d

Browse files
doyubkimutilForever
authored andcommitted
Adding missing overrides for SurfaceToImplicit2 and 3 (#233)
1 parent fa9d970 commit 874499d

6 files changed

Lines changed: 129 additions & 61 deletions

File tree

include/jet/surface_to_implicit2.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class SurfaceToImplicit2 final : public ImplicitSurface2 {
3434
//! Copy constructor.
3535
SurfaceToImplicit2(const SurfaceToImplicit2& other);
3636

37+
//! Returns true if bounding box can be defined.
38+
bool isBounded() const override;
39+
40+
//! Returns true if the surface is a valid geometry.
41+
bool isValidGeometry() const override;
42+
3743
//! Returns the raw surface instance.
3844
Surface2Ptr surface() const;
3945

@@ -57,6 +63,8 @@ class SurfaceToImplicit2 final : public ImplicitSurface2 {
5763
SurfaceRayIntersection2 closestIntersectionLocal(
5864
const Ray2D& ray) const override;
5965

66+
bool isInsideLocal(const Vector2D& otherPoint) const override;
67+
6068
private:
6169
Surface2Ptr _surface;
6270
};

include/jet/surface_to_implicit3.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ class SurfaceToImplicit3 final : public ImplicitSurface3 {
2828
class Builder;
2929

3030
//! Constructs an instance with generic Surface3 instance.
31-
SurfaceToImplicit3(
32-
const Surface3Ptr& surface,
33-
const Transform3& transform = Transform3(),
34-
bool isNormalFlipped = false);
31+
SurfaceToImplicit3(const Surface3Ptr& surface,
32+
const Transform3& transform = Transform3(),
33+
bool isNormalFlipped = false);
3534

3635
//! Copy constructor.
3736
SurfaceToImplicit3(const SurfaceToImplicit3& other);
3837

38+
//! Returns true if bounding box can be defined.
39+
bool isBounded() const override;
40+
41+
//! Returns true if the surface is a valid geometry.
42+
bool isValidGeometry() const override;
43+
3944
//! Returns the raw surface instance.
4045
Surface3Ptr surface() const;
4146

@@ -51,22 +56,22 @@ class SurfaceToImplicit3 final : public ImplicitSurface3 {
5156

5257
BoundingBox3D boundingBoxLocal() const override;
5358

54-
Vector3D closestNormalLocal(
55-
const Vector3D& otherPoint) const override;
59+
Vector3D closestNormalLocal(const Vector3D& otherPoint) const override;
5660

5761
double signedDistanceLocal(const Vector3D& otherPoint) const override;
5862

5963
SurfaceRayIntersection3 closestIntersectionLocal(
6064
const Ray3D& ray) const override;
6165

66+
bool isInsideLocal(const Vector3D& otherPoint) const override;
67+
6268
private:
6369
Surface3Ptr _surface;
6470
};
6571

6672
//! Shared pointer for the SurfaceToImplicit3 type.
6773
typedef std::shared_ptr<SurfaceToImplicit3> SurfaceToImplicit3Ptr;
6874

69-
7075
//!
7176
//! \brief Front-end to create SurfaceToImplicit3 objects step by step.
7277
//!

src/jet/surface_to_implicit2.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,29 @@
44
// personal capacity and am not conveying any rights to any intellectual
55
// property of any third parties.
66

7-
#include <pch.h>
87
#include <jet/surface_to_implicit2.h>
8+
#include <pch.h>
99

1010
using namespace jet;
1111

12-
SurfaceToImplicit2::SurfaceToImplicit2(
13-
const Surface2Ptr& surface,
14-
const Transform2& transform,
15-
bool isNormalFlipped)
16-
: ImplicitSurface2(transform, isNormalFlipped)
17-
, _surface(surface) {
18-
}
12+
SurfaceToImplicit2::SurfaceToImplicit2(const Surface2Ptr& surface,
13+
const Transform2& transform,
14+
bool isNormalFlipped)
15+
: ImplicitSurface2(transform, isNormalFlipped), _surface(surface) {}
1916

20-
SurfaceToImplicit2::SurfaceToImplicit2(const SurfaceToImplicit2& other) :
21-
ImplicitSurface2(other),
22-
_surface(other._surface) {
23-
}
17+
SurfaceToImplicit2::SurfaceToImplicit2(const SurfaceToImplicit2& other)
18+
: ImplicitSurface2(other), _surface(other._surface) {}
19+
20+
bool SurfaceToImplicit2::isBounded() const { return _surface->isBounded(); }
2421

25-
Surface2Ptr SurfaceToImplicit2::surface() const {
26-
return _surface;
22+
bool SurfaceToImplicit2::isValidGeometry() const {
23+
return _surface->isValidGeometry();
2724
}
2825

26+
Surface2Ptr SurfaceToImplicit2::surface() const { return _surface; }
27+
28+
SurfaceToImplicit2::Builder SurfaceToImplicit2::builder() { return Builder(); }
29+
2930
Vector2D SurfaceToImplicit2::closestPointLocal(
3031
const Vector2D& otherPoint) const {
3132
return _surface->closestPoint(otherPoint);
@@ -54,6 +55,10 @@ BoundingBox2D SurfaceToImplicit2::boundingBoxLocal() const {
5455
return _surface->boundingBox();
5556
}
5657

58+
bool SurfaceToImplicit2::isInsideLocal(const Vector2D& otherPoint) const {
59+
return _surface->isInside(otherPoint);
60+
}
61+
5762
double SurfaceToImplicit2::signedDistanceLocal(
5863
const Vector2D& otherPoint) const {
5964
Vector2D x = _surface->closestPoint(otherPoint);
@@ -66,26 +71,18 @@ double SurfaceToImplicit2::signedDistanceLocal(
6671
}
6772
}
6873

69-
70-
SurfaceToImplicit2::Builder&
71-
SurfaceToImplicit2::Builder::withSurface(const Surface2Ptr& surface) {
74+
SurfaceToImplicit2::Builder& SurfaceToImplicit2::Builder::withSurface(
75+
const Surface2Ptr& surface) {
7276
_surface = surface;
7377
return *this;
7478
}
7579

76-
SurfaceToImplicit2
77-
SurfaceToImplicit2::Builder::build() const {
80+
SurfaceToImplicit2 SurfaceToImplicit2::Builder::build() const {
7881
return SurfaceToImplicit2(_surface, _transform, _isNormalFlipped);
7982
}
8083

81-
SurfaceToImplicit2Ptr
82-
SurfaceToImplicit2::Builder::makeShared() const {
84+
SurfaceToImplicit2Ptr SurfaceToImplicit2::Builder::makeShared() const {
8385
return std::shared_ptr<SurfaceToImplicit2>(
84-
new SurfaceToImplicit2(
85-
_surface,
86-
_transform,
87-
_isNormalFlipped),
88-
[] (SurfaceToImplicit2* obj) {
89-
delete obj;
90-
});
86+
new SurfaceToImplicit2(_surface, _transform, _isNormalFlipped),
87+
[](SurfaceToImplicit2* obj) { delete obj; });
9188
}

src/jet/surface_to_implicit3.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,35 @@
44
// personal capacity and am not conveying any rights to any intellectual
55
// property of any third parties.
66

7-
#include <pch.h>
87
#include <jet/surface_to_implicit3.h>
98
#include <jet/triangle_mesh3.h>
9+
#include <pch.h>
1010

1111
using namespace jet;
1212

13-
SurfaceToImplicit3::SurfaceToImplicit3(
14-
const Surface3Ptr& surface,
15-
const Transform3& transform,
16-
bool isNormalFlipped)
17-
: ImplicitSurface3(transform, isNormalFlipped)
18-
, _surface(surface) {
13+
SurfaceToImplicit3::SurfaceToImplicit3(const Surface3Ptr& surface,
14+
const Transform3& transform,
15+
bool isNormalFlipped)
16+
: ImplicitSurface3(transform, isNormalFlipped), _surface(surface) {
1917
if (std::dynamic_pointer_cast<TriangleMesh3>(surface) != nullptr) {
2018
JET_WARN << "Using TriangleMesh3 with SurfaceToImplicit3 can cause "
2119
<< "undefined behavior. Use ImplicitTriangleMesh3 instead.";
2220
}
2321
}
2422

25-
SurfaceToImplicit3::SurfaceToImplicit3(const SurfaceToImplicit3& other) :
26-
ImplicitSurface3(other),
27-
_surface(other._surface) {
28-
}
23+
SurfaceToImplicit3::SurfaceToImplicit3(const SurfaceToImplicit3& other)
24+
: ImplicitSurface3(other), _surface(other._surface) {}
25+
26+
bool SurfaceToImplicit3::isBounded() const { return _surface->isBounded(); }
2927

30-
Surface3Ptr SurfaceToImplicit3::surface() const {
31-
return _surface;
28+
bool SurfaceToImplicit3::isValidGeometry() const {
29+
return _surface->isValidGeometry();
3230
}
3331

32+
Surface3Ptr SurfaceToImplicit3::surface() const { return _surface; }
33+
34+
SurfaceToImplicit3::Builder SurfaceToImplicit3::builder() { return Builder(); }
35+
3436
Vector3D SurfaceToImplicit3::closestPointLocal(
3537
const Vector3D& otherPoint) const {
3638
return _surface->closestPoint(otherPoint);
@@ -71,26 +73,22 @@ double SurfaceToImplicit3::signedDistanceLocal(
7173
}
7274
}
7375

76+
bool SurfaceToImplicit3::isInsideLocal(const Vector3D& otherPoint) const {
77+
return _surface->isInside(otherPoint);
78+
}
7479

75-
SurfaceToImplicit3::Builder&
76-
SurfaceToImplicit3::Builder::withSurface(const Surface3Ptr& surface) {
80+
SurfaceToImplicit3::Builder& SurfaceToImplicit3::Builder::withSurface(
81+
const Surface3Ptr& surface) {
7782
_surface = surface;
7883
return *this;
7984
}
8085

81-
SurfaceToImplicit3
82-
SurfaceToImplicit3::Builder::build() const {
86+
SurfaceToImplicit3 SurfaceToImplicit3::Builder::build() const {
8387
return SurfaceToImplicit3(_surface, _transform, _isNormalFlipped);
8488
}
8589

86-
SurfaceToImplicit3Ptr
87-
SurfaceToImplicit3::Builder::makeShared() const {
90+
SurfaceToImplicit3Ptr SurfaceToImplicit3::Builder::makeShared() const {
8891
return std::shared_ptr<SurfaceToImplicit3>(
89-
new SurfaceToImplicit3(
90-
_surface,
91-
_transform,
92-
_isNormalFlipped),
93-
[] (SurfaceToImplicit3* obj) {
94-
delete obj;
95-
});
92+
new SurfaceToImplicit3(_surface, _transform, _isNormalFlipped),
93+
[](SurfaceToImplicit3* obj) { delete obj; });
9694
}

src/tests/unit_tests/surface_to_implicit2_tests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// property of any third parties.
66

77
#include <jet/box2.h>
8+
#include <jet/plane2.h>
9+
#include <jet/surface_set2.h>
810
#include <jet/surface_to_implicit2.h>
911

1012
#include <gtest/gtest.h>
@@ -129,3 +131,30 @@ TEST(SurfaceToImplicit2, ClosestNormal) {
129131
EXPECT_DOUBLE_EQ(boxNormal.x, s2iNormal.x);
130132
EXPECT_DOUBLE_EQ(boxNormal.y, s2iNormal.y);
131133
}
134+
135+
TEST(SurfaceToImplicit2, IsBounded) {
136+
Plane2Ptr plane =
137+
Plane2::builder().withPoint({0, 0}).withNormal({0, 1}).makeShared();
138+
SurfaceToImplicit2Ptr s2i =
139+
SurfaceToImplicit2::builder().withSurface(plane).makeShared();
140+
EXPECT_FALSE(s2i->isBounded());
141+
}
142+
143+
TEST(SurfaceToImplicit2, IsValidGeometry) {
144+
SurfaceSet2Ptr sset = SurfaceSet2::builder().makeShared();
145+
SurfaceToImplicit2Ptr s2i =
146+
SurfaceToImplicit2::builder().withSurface(sset).makeShared();
147+
EXPECT_FALSE(s2i->isValidGeometry());
148+
}
149+
150+
TEST(SurfaceToImplicit2, IsInside) {
151+
Plane2Ptr plane = Plane2::builder()
152+
.withPoint({0, 0})
153+
.withNormal({0, 1})
154+
.withTranslation({0, -1})
155+
.makeShared();
156+
SurfaceToImplicit2Ptr s2i =
157+
SurfaceToImplicit2::builder().withSurface(plane).makeShared();
158+
EXPECT_FALSE(s2i->isInside({0, -0.5}));
159+
EXPECT_TRUE(s2i->isInside({0, -1.5}));
160+
}

src/tests/unit_tests/surface_to_implicit3_tests.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// property of any third parties.
66

77
#include <jet/box3.h>
8+
#include <jet/plane3.h>
9+
#include <jet/surface_set3.h>
810
#include <jet/surface_to_implicit3.h>
911

1012
#include <gtest/gtest.h>
@@ -133,3 +135,32 @@ TEST(SurfaceToImplicit3, ClosestNormal) {
133135
EXPECT_DOUBLE_EQ(boxNormal.y, s2iNormal.y);
134136
EXPECT_DOUBLE_EQ(boxNormal.z, s2iNormal.z);
135137
}
138+
139+
TEST(SurfaceToImplicit3, IsBounded) {
140+
Plane3Ptr plane = Plane3::builder()
141+
.withPoint({0, 0, 0})
142+
.withNormal({0, 1, 0})
143+
.makeShared();
144+
SurfaceToImplicit3Ptr s2i =
145+
SurfaceToImplicit3::builder().withSurface(plane).makeShared();
146+
EXPECT_FALSE(s2i->isBounded());
147+
}
148+
149+
TEST(SurfaceToImplicit3, IsValidGeometry) {
150+
SurfaceSet3Ptr sset = SurfaceSet3::builder().makeShared();
151+
SurfaceToImplicit3Ptr s2i =
152+
SurfaceToImplicit3::builder().withSurface(sset).makeShared();
153+
EXPECT_FALSE(s2i->isValidGeometry());
154+
}
155+
156+
TEST(SurfaceToImplicit3, IsInside) {
157+
Plane3Ptr plane = Plane3::builder()
158+
.withPoint({0, 0, 0})
159+
.withNormal({0, 1, 0})
160+
.withTranslation({0, -1, 0})
161+
.makeShared();
162+
SurfaceToImplicit3Ptr s2i =
163+
SurfaceToImplicit3::builder().withSurface(plane).makeShared();
164+
EXPECT_FALSE(s2i->isInside({0, -0.5, 0}));
165+
EXPECT_TRUE(s2i->isInside({0, -1.5, 0}));
166+
}

0 commit comments

Comments
 (0)