Box2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Box2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D box geometry.
6 > Created Time: 2017/06/21
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_BOX2_H
10 #define CUBBYFLOW_BOX2_H
11 
12 #include <Core/Surface/Surface2.h>
13 
14 namespace CubbyFlow
15 {
23  class Box2 final : public Surface2
24  {
25  public:
26  class Builder;
27 
30 
32  Box2(const Transform2& transform = Transform2(), bool isNormalFlipped = false);
33 
35  Box2(const Vector2D& lowerCorner, const Vector2D& upperCorner,
36  const Transform2& transform = Transform2(), bool isNormalFlipped = false);
37 
39  Box2(const BoundingBox2D& boundingBox, const Transform2& transform = Transform2(), bool isNormalFlipped = false);
40 
42  Box2(const Box2& other);
43 
45  static Builder GetBuilder();
46 
47  protected:
48  // Surface2 implementations
49  Vector2D ClosestPointLocal(const Vector2D& otherPoint) const override;
50 
51  bool IntersectsLocal(const Ray2D& ray) const override;
52 
53  BoundingBox2D BoundingBoxLocal() const override;
54 
55  Vector2D ClosestNormalLocal(const Vector2D& otherPoint) const override;
56 
57  SurfaceRayIntersection2 ClosestIntersectionLocal(const Ray2D& ray) const override;
58  };
59 
61  using Box2Ptr = std::shared_ptr<Box2>;
62 
66  class Box2::Builder final : public SurfaceBuilderBase2<Box2::Builder>
67  {
68  public:
70  Builder& WithLowerCorner(const Vector2D& pt);
71 
73  Builder& WithUpperCorner(const Vector2D& pt);
74 
77 
79  Box2 Build() const;
80 
82  Box2Ptr MakeShared() const;
83 
84  private:
85  Vector2D m_lowerCorner{ 0, 0 };
86  Vector2D m_upperCorner{ 1, 1 };
87  };
88 }
89 
90 #endif
Box2 Build() const
Builds Box2.
SurfaceRayIntersection2 ClosestIntersectionLocal(const Ray2D &ray) const override
Returns the closest intersection point for given ray in local frame.
Base class for 2-D surface builder.
Definition: Surface2.h:106
Class for 2-D ray.
Definition: Ray2.h:23
Builder & WithLowerCorner(const Vector2D &pt)
Returns builder with lower corner set.
BoundingBox2D BoundingBoxLocal() const override
Returns the bounding box of this surface object in local frame.
Represents 2-D rigid body transform.
Definition: Transform2.h:21
BoundingBox2< double > BoundingBox2D
Double-type 2-D BoundingBox.
Definition: BoundingBox2.h:126
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
Builder & WithUpperCorner(const Vector2D &pt)
Returns builder with upper corner set.
Vector2D ClosestPointLocal(const Vector2D &otherPoint) const override
Box2(const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
Constructs (0, 0) x (1, 1) box.
static Builder GetBuilder()
Returns builder fox Box2.
2-D axis-aligned bounding box class.
Definition: BoundingBox2.h:44
Box2Ptr MakeShared() const
Builds shared pointer of Box2 instance.
bool isNormalFlipped
Flips normal.
Definition: Surface2.h:39
Definition: pybind11Utils.h:24
Front-end to create Box2 objects step by step.
Definition: Box2.h:66
Vector2< double > Vector2D
Double-type 2D vector.
Definition: Vector2.h:341
2-D box geometry.
Definition: Box2.h:23
bool IntersectsLocal(const Ray2D &ray) const override
std::shared_ptr< Box2 > Box2Ptr
Shared pointer type for the Box2.
Definition: Box2.h:61
2-D vector class.
Definition: Vector2.h:26
Builder & WithBoundingBox(const BoundingBox2D &bbox)
Returns builder with bounding box.
BoundingBox2D bound
Bounding box of this box.
Definition: Box2.h:29
Vector2D ClosestNormalLocal(const Vector2D &otherPoint) const override