Sphere2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Sphere2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D sphere geometry.
6 > Created Time: 2017/04/04
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SPHERE2_H
10 #define CUBBYFLOW_SPHERE2_H
11 
12 #include <Core/Surface/Surface2.h>
13 
14 namespace CubbyFlow
15 {
22  class Sphere2 final : public Surface2
23  {
24  public:
25  class Builder;
26 
29 
31  double radius = 1.0;
32 
34  Sphere2(
35  const Transform2& transform = Transform2(),
36  bool isNormalFlipped = false);
37 
39  Sphere2(
40  const Vector2D& center,
41  double radius,
42  const Transform2& transform = Transform2(),
43  bool isNormalFlipped = false);
44 
46  Sphere2(const Sphere2& other);
47 
49  static Builder GetBuilder();
50 
51  private:
52  Vector2D ClosestPointLocal(const Vector2D& otherPoint) const override;
53 
54  double ClosestDistanceLocal(const Vector2D& otherPoint) const override;
55 
56  bool IntersectsLocal(const Ray2D& ray) const override;
57 
58  BoundingBox2D BoundingBoxLocal() const override;
59 
60  Vector2D ClosestNormalLocal(const Vector2D& otherPoint) const override;
61 
62  SurfaceRayIntersection2 ClosestIntersectionLocal(const Ray2D& ray) const override;
63  };
64 
66  using Sphere2Ptr = std::shared_ptr<Sphere2>;
67 
71  class Sphere2::Builder final : public SurfaceBuilderBase2<Sphere2::Builder>
72  {
73  public:
76 
78  Builder& WithRadius(double radius);
79 
81  Sphere2 Build() const;
82 
84  Sphere2Ptr MakeShared() const;
85 
86  private:
87  Vector2D m_center = { 0, 0 };
88  double m_radius = 0.0;
89  };
90 }
91 
92 #endif
2-D sphere geometry.
Definition: Sphere2.h:22
std::shared_ptr< Sphere2 > Sphere2Ptr
Shared pointer for the Sphere2 type.
Definition: Sphere2.h:66
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
2-D axis-aligned bounding box class.
Definition: BoundingBox2.h:44
bool isNormalFlipped
Flips normal.
Definition: Surface2.h:39
Definition: pybind11Utils.h:24
Sphere2Ptr MakeShared() const
Builds shared pointer of Sphere2 instance.
Builder & WithRadius(double radius)
Returns builder with sphere radius.
Builder & WithCenter(const Vector2D &center)
Returns builder with sphere center.
Vector2D center
Center of the sphere.
Definition: Sphere2.h:25
Sphere2 Build() const
Builds Sphere2.
Sphere2(const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
Constructs a sphere with center at (0, 0) and radius of 1.
Front-end to create Sphere2 objects step by step.
Definition: Sphere2.h:71
2-D vector class.
Definition: Vector2.h:26
double radius
Radius of the sphere.
Definition: Sphere2.h:31
static Builder GetBuilder()
Returns builder fox Sphere2.