CVB++ 14.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
28 Circle(Point2D<double> center, double radius) noexcept
29 : center_(center)
30 , radius_(std::abs(radius))
31 {
32 }
33
35
39 Point2D<double> Center() const noexcept
40 {
41 return center_;
42 }
43
45
49 void SetCenter(Point2D<double> center) noexcept
50 {
51 center_ = center;
52 }
53
55
59 double Radius() const noexcept
60 {
61 return radius_;
62 }
63
65
69 void SetRadius(double radius) noexcept
70 {
71 radius_ = std::abs(radius);
72 }
73
75
80 bool Contains(Point2D<double> point) const noexcept
81 {
82 auto delta = point - center_;
83 return delta.Length() <= radius_;
84 }
85
87
93 bool IsOnRadius(Point2D<double> point, double epsilon) const noexcept
94 {
95 auto delta = point - center_;
96 return std::abs(delta.Length() - radius_) < epsilon;
97 }
98
99
100
102
107 bool operator==(const Circle& circle) const noexcept
108 {
109 return (center_ == circle.center_
110 && radius_ == circle.radius_);
111 }
112
113
115
120 bool operator!=(const Circle& circle) const noexcept
121 {
122 return !(*this == circle);
123 }
124
125 private:
126
127 Point2D<double> center_;
128 double radius_ = 0.0;
129
130};
131
132
133CVB_END_INLINE_NS
134
135}
Class representing a circle.
Definition: circle.hpp:19
Circle(Point2D< double > center, double radius) noexcept
Create a circle.
Definition: circle.hpp:28
Point2D< double > Center() const noexcept
Gets the center of the circle.
Definition: circle.hpp:39
bool IsOnRadius(Point2D< double > point, double epsilon) const noexcept
Check whether a point is on the radius of a circle.
Definition: circle.hpp:93
double Radius() const noexcept
Gets the radius of the circle.
Definition: circle.hpp:59
bool operator==(const Circle &circle) const noexcept
Compares to an other circle.
Definition: circle.hpp:107
void SetRadius(double radius) noexcept
Sets the radius of the circle.
Definition: circle.hpp:69
bool Contains(Point2D< double > point) const noexcept
Check whether a point is inside or outside a circle.
Definition: circle.hpp:80
void SetCenter(Point2D< double > center) noexcept
Sets the center of the circle.
Definition: circle.hpp:49
bool operator!=(const Circle &circle) const noexcept
Compares to an other circle.
Definition: circle.hpp:120
T Length() const noexcept
Gets the length of the vector represented by this point object.
Definition: point_2d.hpp:126
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24