CVB++ 15.0
circle.hpp
1#pragma once
2
3#include "global.hpp"
4
5#include "point_2d.hpp"
6
7namespace Cvb
8{
9
10CVB_BEGIN_INLINE_NS
11
13
18class Circle final
19{
20 public:
21
23
26 Circle() noexcept = default;
27
29
34 Circle(Point2D<double> center, double radius) noexcept
35 : center_(center)
36 , radius_(std::abs(radius))
37 {
38 }
39
41
45 Point2D<double> Center() const noexcept
46 {
47 return center_;
48 }
49
51
55 void SetCenter(Point2D<double> center) noexcept
56 {
57 center_ = center;
58 }
59
61
65 double Radius() const noexcept
66 {
67 return radius_;
68 }
69
71
75 void SetRadius(double radius) noexcept
76 {
77 radius_ = std::abs(radius);
78 }
79
81
86 bool Contains(Point2D<double> point) const noexcept
87 {
88 auto delta = point - center_;
89 return delta.Length() <= radius_;
90 }
91
93
99 bool IsOnRadius(Point2D<double> point, double epsilon) const noexcept
100 {
101 auto delta = point - center_;
102 return std::abs(delta.Length() - radius_) < epsilon;
103 }
104
105
106
108
113 bool operator==(const Circle& circle) const noexcept
114 {
115 return (center_ == circle.center_
116 && radius_ == circle.radius_);
117 }
118
119
121
126 bool operator!=(const Circle& circle) const noexcept
127 {
128 return !(*this == circle);
129 }
130
131 private:
132
133 Point2D<double> center_;
134 double radius_ = 0.0;
135
136};
137
138
139CVB_END_INLINE_NS
140
141}
Class representing a circle.
Definition: circle.hpp:19
Point2D< double > Center() const noexcept
Gets the center of the circle.
Definition: circle.hpp:45
bool IsOnRadius(Point2D< double > point, double epsilon) const noexcept
Check whether a point is on the radius of a circle.
Definition: circle.hpp:99
double Radius() const noexcept
Gets the radius of the circle.
Definition: circle.hpp:65
Circle() noexcept=default
Create default circle.
bool operator==(const Circle &circle) const noexcept
Compares to an other circle.
Definition: circle.hpp:113
void SetRadius(double radius) noexcept
Sets the radius of the circle.
Definition: circle.hpp:75
bool Contains(Point2D< double > point) const noexcept
Check whether a point is inside or outside a circle.
Definition: circle.hpp:86
void SetCenter(Point2D< double > center) noexcept
Sets the center of the circle.
Definition: circle.hpp:55
bool operator!=(const Circle &circle) const noexcept
Compares to an other circle.
Definition: circle.hpp:126
Multi-purpose 2D vector class.
Definition: point_2d.hpp:20
T Length() const noexcept
Gets the length of the vector represented by this point object.
Definition: point_2d.hpp:128
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15