CVB++ 15.0
circle.hpp
1#pragma once
2
3#include "global.hpp"
4
5#include "point_2d.hpp"
6
7namespace Cvb
8{
9
10 CVB_BEGIN_INLINE_NS
11
13
18 class Circle final
19 {
20 public:
22
25 Circle() noexcept = default;
26
28
33 Circle(Point2D<double> center, double radius) noexcept
34 : center_(center)
35 , radius_(std::abs(radius))
36 {
37 }
38
40
44 Point2D<double> Center() const noexcept
45 {
46 return center_;
47 }
48
50
54 void SetCenter(Point2D<double> center) noexcept
55 {
56 center_ = center;
57 }
58
60
64 double Radius() const noexcept
65 {
66 return radius_;
67 }
68
70
74 void SetRadius(double radius) noexcept
75 {
76 radius_ = std::abs(radius);
77 }
78
80
85 bool Contains(Point2D<double> point) const noexcept
86 {
87 auto delta = point - center_;
88 return delta.Length() <= radius_;
89 }
90
92
98 bool IsOnRadius(Point2D<double> point, double epsilon) const noexcept
99 {
100 auto delta = point - center_;
101 return std::abs(delta.Length() - radius_) < epsilon;
102 }
103
105
110 bool operator==(const Circle &circle) const noexcept
111 {
112 return (center_ == circle.center_ && radius_ == circle.radius_);
113 }
114
116
121 bool operator!=(const Circle &circle) const noexcept
122 {
123 return !(*this == circle);
124 }
125
126 private:
127 Point2D<double> center_;
128 double radius_ = 0.0;
129 };
130
131 CVB_END_INLINE_NS
132
133} // namespace Cvb
Point2D< double > Center() const noexcept
Gets the center of the circle.
Definition circle.hpp:44
bool IsOnRadius(Point2D< double > point, double epsilon) const noexcept
Check whether a point is on the radius of a circle.
Definition circle.hpp:98
double Radius() const noexcept
Gets the radius of the circle.
Definition circle.hpp:64
Circle() noexcept=default
Create default circle.
bool operator==(const Circle &circle) const noexcept
Compares to an other circle.
Definition circle.hpp:110
void SetRadius(double radius) noexcept
Sets the radius of the circle.
Definition circle.hpp:74
bool Contains(Point2D< double > point) const noexcept
Check whether a point is inside or outside a circle.
Definition circle.hpp:85
void SetCenter(Point2D< double > center) noexcept
Sets the center of the circle.
Definition circle.hpp:54
bool operator!=(const Circle &circle) const noexcept
Compares to an other circle.
Definition circle.hpp:121
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17