Plane2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Plane2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D plane geometry.
6 > Created Time: 2017/06/18
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_PLANE2_H
10 #define CUBBYFLOW_PLANE2_H
11 
12 #include <Core/Surface/Surface2.h>
13 
14 namespace CubbyFlow
15 {
22  class Plane2 final : public Surface2
23  {
24  public:
25  class Builder;
26 
29 
32 
34  Plane2(const Transform2& transform = Transform2(), bool isNormalFlipped = false);
35 
37  Plane2(const Vector2D& normal, const Vector2D& point,
38  const Transform2& transform = Transform2(), bool isNormalFlipped = false);
39 
41  Plane2(const Plane2& other);
42 
44  static Builder GetBuilder();
45 
46  private:
47  Vector2D ClosestPointLocal(const Vector2D& otherPoint) const override;
48 
49  bool IntersectsLocal(const Ray2D& ray) const override;
50 
51  BoundingBox2D BoundingBoxLocal() const override;
52 
53  Vector2D ClosestNormalLocal(const Vector2D& otherPoint) const override;
54 
55  SurfaceRayIntersection2 ClosestIntersectionLocal(const Ray2D& ray) const override;
56  };
57 
59  using Plane2Ptr = std::shared_ptr<Plane2>;
60 
64  class Plane2::Builder final : public SurfaceBuilderBase2<Plane2::Builder>
65  {
66  public:
69 
72 
74  Plane2 Build() const;
75 
77  Plane2Ptr MakeShared() const;
78 
79  private:
80  Vector2D m_normal{ 0, 1 };
81  Vector2D m_point{ 0, 0 };
82  };
83 }
84 
85 #endif
Builder & WithPoint(const Vector2D &point)
Returns builder with point on the plane.
Vector2D point
Point that lies on the plane.
Definition: Plane2.h:31
Plane2 Build() const
Builds Plane2.
Builder & WithNormal(const Vector2D &normal)
Returns builder with plane normal.
Base class for 2-D surface builder.
Definition: Surface2.h:106
Class for 2-D ray.
Definition: Ray2.h:23
Represents 2-D rigid body transform.
Definition: Transform2.h:21
Transform2 transform
Local-to-world transform.
Definition: Surface2.h:36
Structure that represents ray-surface intersection point.
Definition: Surface2.h:23
Abstract base class for 2-D surface.
Definition: Surface2.h:32
static Builder GetBuilder()
Returns builder fox Plane2.
Plane2Ptr MakeShared() const
Builds shared pointer of Plane2 instance.
Front-end to create Plane2 objects step by step.
Definition: Plane2.h:64
2-D plane geometry.
Definition: Plane2.h:22
Vector2D normal
Plane normal.
Definition: Plane2.h:28
2-D axis-aligned bounding box class.
Definition: BoundingBox2.h:44
bool isNormalFlipped
Flips normal.
Definition: Surface2.h:39
Definition: pybind11Utils.h:24
Vector2< double > Vector2D
Double-type 2D vector.
Definition: Vector2.h:341
std::shared_ptr< Plane2 > Plane2Ptr
Shared pointer for the Plane2 type.
Definition: Plane2.h:59
Plane2(const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
Constructs a plane that crosses (0, 0) with surface normal (0, 1).
2-D vector class.
Definition: Vector2.h:26