Jet  v1.3.3
sphere2.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_SPHERE2_H_
8 #define INCLUDE_JET_SPHERE2_H_
9 
10 #include <jet/surface2.h>
11 #include <jet/bounding_box2.h>
12 
13 namespace jet {
14 
21 class Sphere2 final : public Surface2 {
22  public:
23  class Builder;
24 
27 
29  double radius = 1.0;
30 
33  const Transform2& transform = Transform2(),
34  bool isNormalFlipped = false);
35 
38  const Vector2D& center,
39  double radius,
40  const Transform2& transform = Transform2(),
41  bool isNormalFlipped = false);
42 
44  Sphere2(const Sphere2& other);
45 
47  static Builder builder();
48 
49  private:
50  Vector2D closestPointLocal(const Vector2D& otherPoint) const override;
51 
52  double closestDistanceLocal(const Vector2D& otherPoint) const override;
53 
54  bool intersectsLocal(const Ray2D& ray) const override;
55 
56  BoundingBox2D boundingBoxLocal() const override;
57 
58  Vector2D closestNormalLocal(const Vector2D& otherPoint) const override;
59 
60  SurfaceRayIntersection2 closestIntersectionLocal(
61  const Ray2D& ray) const override;
62 };
63 
65 typedef std::shared_ptr<Sphere2> Sphere2Ptr;
66 
67 
71 class Sphere2::Builder final : public SurfaceBuilderBase2<Sphere2::Builder> {
72  public:
75 
78 
80  Sphere2 build() const;
81 
84 
85  private:
86  Vector2D _center{0, 0};
87  double _radius = 0.0;
88 };
89 
90 } // namespace jet
91 
92 
93 #endif // INCLUDE_JET_SPHERE2_H_
surface2.h
jet::Sphere2Ptr
std::shared_ptr< Sphere2 > Sphere2Ptr
Shared pointer for the Sphere2 type.
Definition: sphere2.h:65
jet::Sphere2::Sphere2
Sphere2(const Sphere2 &other)
Copy constructor.
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::Transform2
Represents 2-D rigid body transform.
Definition: transform2.h:19
jet::Sphere2
2-D sphere geometry.
Definition: sphere2.h:21
jet::Sphere2::builder
static Builder builder()
Returns builder fox Sphere2.
jet::Sphere2::radius
double radius
Radius of the sphere.
Definition: sphere2.h:29
jet::Ray< T, 2 >
Class for 2-D ray.
Definition: ray2.h:21
jet::Sphere2::Builder
Front-end to create Sphere2 objects step by step.
Definition: sphere2.h:71
jet
Definition: advection_solver2.h:18
jet::Surface2::transform
Transform2 transform
Local-to-world transform.
Definition: surface2.h:30
jet::Sphere2::Builder::makeShared
Sphere2Ptr makeShared() const
Builds shared pointer of Sphere2 instance.
jet::Sphere2::Builder::build
Sphere2 build() const
Builds Sphere2.
jet::Sphere2::Sphere2
Sphere2(const Vector2D &center, double radius, const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
Constructs a sphere with center and radius.
jet::Sphere2::center
Vector2D center
Center of the sphere.
Definition: sphere2.h:23
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::SurfaceBuilderBase2
Base class for 2-D surface builder.
Definition: surface2.h:115
jet::Sphere2::Builder::withCenter
Builder & withCenter(const Vector2D &center)
Returns builder with sphere center.
bounding_box2.h
jet::BoundingBox< T, 2 >
2-D axis-aligned bounding box class.
Definition: bounding_box2.h:41
jet::Surface2
Abstract base class for 2-D surface.
Definition: surface2.h:27
jet::Sphere2::Sphere2
Sphere2(const Transform2 &transform=Transform2(), bool isNormalFlipped=false)
Constructs a sphere with center at (0, 0) and radius of 1.
jet::Sphere2::Builder::withRadius
Builder & withRadius(double radius)
Returns builder with sphere radius.