Skip to content

Commit fa9d970

Browse files
doyubkimutilForever
authored andcommitted
Adding isInside to the surface classes (#232)
1 parent 6e2623a commit fa9d970

22 files changed

Lines changed: 214 additions & 22 deletions

include/jet/implicit_surface2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class ImplicitSurface2 : public Surface2 {
3535

3636
private:
3737
double closestDistanceLocal(const Vector2D& otherPoint) const override;
38+
39+
bool isInsideLocal(const Vector2D& otherPoint) const override;
3840
};
3941

4042
//! Shared pointer type for the ImplicitSurface2.

include/jet/implicit_surface3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class ImplicitSurface3 : public Surface3 {
3535

3636
private:
3737
double closestDistanceLocal(const Vector3D& otherPoint) const override;
38+
39+
bool isInsideLocal(const Vector3D& otherPoint) const override;
3840
};
3941

4042
//! Shared pointer type for the ImplicitSurface3.

include/jet/implicit_surface_set2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class ImplicitSurfaceSet2 final : public ImplicitSurface2 {
8383
SurfaceRayIntersection2 closestIntersectionLocal(
8484
const Ray2D& ray) const override;
8585

86+
bool isInsideLocal(const Vector2D& otherPoint) const override;
87+
8688
// ImplicitSurface2 implementations
8789

8890
double signedDistanceLocal(const Vector2D& otherPoint) const override;

include/jet/implicit_surface_set3.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class ImplicitSurfaceSet3 final : public ImplicitSurface3 {
8383
SurfaceRayIntersection3 closestIntersectionLocal(
8484
const Ray3D& ray) const override;
8585

86+
bool isInsideLocal(const Vector3D& otherPoint) const override;
87+
8688
// ImplicitSurface3 implementations
8789

8890
double signedDistanceLocal(const Vector3D& otherPoint) const override;

include/jet/surface2.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class Surface2 {
7272
//! Returns true if the surface is a valid geometry.
7373
virtual bool isValidGeometry() const;
7474

75+
//! Returns true if \p otherPoint is inside the volume defined by the
76+
//! surface.
77+
bool isInside(const Vector2D& otherPoint) const;
78+
7579
protected:
7680
//! Returns the closest point from the given point \p otherPoint to the
7781
//! surface in local frame.
@@ -95,6 +99,10 @@ class Surface2 {
9599
//! Returns the closest distance from the given point \p otherPoint to the
96100
//! point on the surface in local frame.
97101
virtual double closestDistanceLocal(const Vector2D& otherPoint) const;
102+
103+
//! Returns true if \p otherPoint is inside by given \p depth the volume
104+
//! defined by the surface in local frame.
105+
virtual bool isInsideLocal(const Vector2D& otherPoint) const;
98106
};
99107

100108
//! Shared pointer for the Surface2 type.

include/jet/surface3.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ class Surface3 {
7272
//! Returns true if the surface is a valid geometry.
7373
virtual bool isValidGeometry() const;
7474

75+
//! Returns true if \p otherPoint is inside the volume defined by the
76+
//! surface.
77+
bool isInside(const Vector3D& otherPoint) const;
78+
7579
protected:
7680
//! Returns the closest point from the given point \p otherPoint to the
7781
//! surface in local frame.
@@ -95,6 +99,10 @@ class Surface3 {
9599
//! Returns the closest distance from the given point \p otherPoint to the
96100
//! point on the surface in local frame.
97101
virtual double closestDistanceLocal(const Vector3D& otherPoint) const;
102+
103+
//! Returns true if \p otherPoint is inside by given \p depth the volume
104+
//! defined by the surface in local frame.
105+
virtual bool isInsideLocal(const Vector3D& otherPoint) const;
98106
};
99107

100108
//! Shared pointer for the Surface3 type.

include/jet/surface_set2.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class SurfaceSet2 final : public Surface2 {
7575
SurfaceRayIntersection2 closestIntersectionLocal(
7676
const Ray2D& ray) const override;
7777

78+
bool isInsideLocal(const Vector2D& otherPoint) const override;
79+
7880
void invalidateBvh();
7981

8082
void buildBvh() const;
@@ -86,7 +88,8 @@ typedef std::shared_ptr<SurfaceSet2> SurfaceSet2Ptr;
8688
//!
8789
//! \brief Front-end to create SurfaceSet2 objects step by step.
8890
//!
89-
class SurfaceSet2::Builder final : public SurfaceBuilderBase2<SurfaceSet2> {
91+
class SurfaceSet2::Builder final
92+
: public SurfaceBuilderBase2<SurfaceSet2::Builder> {
9093
public:
9194
//! Returns builder with other surfaces.
9295
Builder& withSurfaces(const std::vector<Surface2Ptr>& others);

include/jet/surface_set3.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class SurfaceSet3 final : public Surface3 {
7575
SurfaceRayIntersection3 closestIntersectionLocal(
7676
const Ray3D& ray) const override;
7777

78+
bool isInsideLocal(const Vector3D& otherPoint) const override;
79+
7880
void invalidateBvh();
7981

8082
void buildBvh() const;
@@ -86,7 +88,8 @@ typedef std::shared_ptr<SurfaceSet3> SurfaceSet3Ptr;
8688
//!
8789
//! \brief Front-end to create SurfaceSet3 objects step by step.
8890
//!
89-
class SurfaceSet3::Builder final : public SurfaceBuilderBase3<SurfaceSet3> {
91+
class SurfaceSet3::Builder final
92+
: public SurfaceBuilderBase3<SurfaceSet3::Builder> {
9093
public:
9194
//! Returns builder with other surfaces.
9295
Builder& withSurfaces(const std::vector<Surface3Ptr>& others);

src/jet/collider2.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ void Collider2::getClosestPoint(const Surface2Ptr& surface,
9696

9797
bool Collider2::isPenetrating(const ColliderQueryResult& colliderPoint,
9898
const Vector2D& position, double radius) {
99-
// If the new candidate position of the particle is on the other side of
100-
// the surface OR the new distance to the surface is less than the
101-
// particle's radius, this particle is in colliding state.
102-
return (position - colliderPoint.point).dot(colliderPoint.normal) < 0.0 ||
103-
colliderPoint.distance < radius;
99+
// If the new candidate position of the particle is inside
100+
// the volume defined by the surface OR the new distance to the surface is
101+
// less than the particle's radius, this particle is in colliding state.
102+
return _surface->isInside(position) || colliderPoint.distance < radius;
104103
}
105104

106105
void Collider2::update(double currentTimeInSeconds,

src/jet/collider3.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ void Collider3::getClosestPoint(const Surface3Ptr& surface,
9696

9797
bool Collider3::isPenetrating(const ColliderQueryResult& colliderPoint,
9898
const Vector3D& position, double radius) {
99-
// If the new candidate position of the particle is on the other side of
100-
// the surface OR the new distance to the surface is less than the
101-
// particle's radius, this particle is in colliding state.
102-
return (position - colliderPoint.point).dot(colliderPoint.normal) < 0.0 ||
103-
colliderPoint.distance < radius;
99+
// If the new candidate position of the particle is inside
100+
// the volume defined by the surface OR the new distance to the surface is
101+
// less than the particle's radius, this particle is in colliding state.
102+
return _surface->isInside(position) || colliderPoint.distance < radius;
104103
}
105104

106105
void Collider3::update(double currentTimeInSeconds,

0 commit comments

Comments
 (0)