Jet  v1.3.3
surface2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_SURFACE2_H_
8 #define INCLUDE_JET_SURFACE2_H_
9 
10 #include <jet/bounding_box2.h>
11 #include <jet/constants.h>
12 #include <jet/ray2.h>
13 #include <jet/transform2.h>
14 #include <memory>
15 
16 namespace jet {
17 
20  bool isIntersecting = false;
21  double distance = kMaxD;
24 };
25 
27 class Surface2 {
28  public:
31 
33  bool isNormalFlipped = false;
34 
37  bool isNormalFlipped = false);
38 
40  Surface2(const Surface2& other);
41 
43  virtual ~Surface2();
44 
47  Vector2D closestPoint(const Vector2D& otherPoint) const;
48 
51 
53  bool intersects(const Ray2D& ray) const;
54 
57  double closestDistance(const Vector2D& otherPoint) const;
58 
61 
64  Vector2D closestNormal(const Vector2D& otherPoint) const;
65 
67  virtual void updateQueryEngine();
68 
70  virtual bool isBounded() const;
71 
73  virtual bool isValidGeometry() const;
74 
77  bool isInside(const Vector2D& otherPoint) const;
78 
79  protected:
82  virtual Vector2D closestPointLocal(const Vector2D& otherPoint) const = 0;
83 
85  virtual BoundingBox2D boundingBoxLocal() const = 0;
86 
89  const Ray2D& ray) const = 0;
90 
93  virtual Vector2D closestNormalLocal(const Vector2D& otherPoint) const = 0;
94 
97  virtual bool intersectsLocal(const Ray2D& ray) const;
98 
101  virtual double closestDistanceLocal(const Vector2D& otherPoint) const;
102 
105  virtual bool isInsideLocal(const Vector2D& otherPoint) const;
106 };
107 
109 typedef std::shared_ptr<Surface2> Surface2Ptr;
110 
114 template <typename DerivedBuilder>
116  public:
118  DerivedBuilder& withIsNormalFlipped(bool isNormalFlipped);
119 
121  DerivedBuilder& withTranslation(const Vector2D& translation);
122 
124  DerivedBuilder& withOrientation(double orientation);
125 
127  DerivedBuilder& withTransform(const Transform2& transform);
128 
129  protected:
130  bool _isNormalFlipped = false;
132 };
133 
134 template <typename T>
136  _isNormalFlipped = isNormalFlipped;
137  return static_cast<T&>(*this);
138 }
139 
140 template <typename T>
142  _transform.setTranslation(translation);
143  return static_cast<T&>(*this);
144 }
145 
146 template <typename T>
148  _transform.setOrientation(orientation);
149  return static_cast<T&>(*this);
150 }
151 
152 template <typename T>
154  _transform = transform;
155  return static_cast<T&>(*this);
156 }
157 
158 } // namespace jet
159 
160 #endif // INCLUDE_JET_SURFACE2_H_
jet::SurfaceRayIntersection2
Struct that represents ray-surface intersection point.
Definition: surface2.h:19
jet::Surface2::isNormalFlipped
bool isNormalFlipped
Flips normal.
Definition: surface2.h:33
jet::Surface2::~Surface2
virtual ~Surface2()
Default destructor.
jet::Transform2
Represents 2-D rigid body transform.
Definition: transform2.h:19
jet::Surface2::closestPoint
Vector2D closestPoint(const Vector2D &otherPoint) const
transform2.h
jet::Surface2::closestPointLocal
virtual Vector2D closestPointLocal(const Vector2D &otherPoint) const =0
jet::Surface2::boundingBoxLocal
virtual BoundingBox2D boundingBoxLocal() const =0
Returns the bounding box of this surface object in local frame.
jet::Surface2::closestDistanceLocal
virtual double closestDistanceLocal(const Vector2D &otherPoint) const
jet::Surface2::closestDistance
double closestDistance(const Vector2D &otherPoint) const
jet::SurfaceBuilderBase2::_isNormalFlipped
bool _isNormalFlipped
Definition: surface2.h:130
jet::SurfaceBuilderBase2::withIsNormalFlipped
DerivedBuilder & withIsNormalFlipped(bool isNormalFlipped)
Returns builder with flipped normal flag.
Definition: surface2.h:135
jet::Surface2::closestNormal
Vector2D closestNormal(const Vector2D &otherPoint) const
jet::Ray< T, 2 >
Class for 2-D ray.
Definition: ray2.h:21
jet::Surface2::boundingBox
BoundingBox2D boundingBox() const
Returns the bounding box of this surface object.
jet::SurfaceRayIntersection2::point
Vector2D point
Definition: surface2.h:22
jet::SurfaceRayIntersection2::isIntersecting
bool isIntersecting
Definition: surface2.h:20
jet::Surface2::isValidGeometry
virtual bool isValidGeometry() const
Returns true if the surface is a valid geometry.
jet::Surface2::Surface2
Surface2(const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
Constructs a surface with normal direction.
jet
Definition: advection_solver2.h:18
jet::Surface2::transform
Transform2 transform
Local-to-world transform.
Definition: surface2.h:30
ray2.h
jet::Surface2::closestIntersection
SurfaceRayIntersection2 closestIntersection(const Ray2D &ray) const
Returns the closest intersection point for given ray.
jet::Surface2Ptr
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: surface2.h:109
jet::Surface2::intersectsLocal
virtual bool intersectsLocal(const Ray2D &ray) const
jet::Surface2::isInsideLocal
virtual bool isInsideLocal(const Vector2D &otherPoint) const
jet::SurfaceRayIntersection2::normal
Vector2D normal
Definition: surface2.h:23
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::Surface2::closestIntersectionLocal
virtual SurfaceRayIntersection2 closestIntersectionLocal(const Ray2D &ray) const =0
Returns the closest intersection point for given ray in local frame.
jet::SurfaceBuilderBase2
Base class for 2-D surface builder.
Definition: surface2.h:115
jet::Surface2::updateQueryEngine
virtual void updateQueryEngine()
Updates internal spatial query engine.
jet::kMaxD
constexpr double kMaxD
Max double.
Definition: constants.h:88
bounding_box2.h
jet::BoundingBox< T, 2 >
2-D axis-aligned bounding box class.
Definition: bounding_box2.h:41
jet::SurfaceBuilderBase2::withOrientation
DerivedBuilder & withOrientation(double orientation)
Returns builder with orientation.
Definition: surface2.h:147
jet::SurfaceBuilderBase2::_transform
Transform2 _transform
Definition: surface2.h:131
jet::Surface2
Abstract base class for 2-D surface.
Definition: surface2.h:27
jet::Surface2::intersects
bool intersects(const Ray2D &ray) const
Returns true if the given ray intersects with this surface object.
jet::SurfaceRayIntersection2::distance
double distance
Definition: surface2.h:21
constants.h
jet::Surface2::isBounded
virtual bool isBounded() const
Returns true if bounding box can be defined.
jet::Surface2::isInside
bool isInside(const Vector2D &otherPoint) const
jet::SurfaceBuilderBase2::withTranslation
DerivedBuilder & withTranslation(const Vector2D &translation)
Returns builder with translation.
Definition: surface2.h:141
jet::Surface2::Surface2
Surface2(const Surface2 &other)
Copy constructor.
jet::SurfaceBuilderBase2::withTransform
DerivedBuilder & withTransform(const Transform2 &transform)
Returns builder with transform.
Definition: surface2.h:153
jet::Surface2::closestNormalLocal
virtual Vector2D closestNormalLocal(const Vector2D &otherPoint) const =0