CVB++ 15.0
ellipse.hpp
1#pragma once
2
3#include "global.hpp"
4
5#include "point_2d.hpp"
6#include "angle.hpp"
7
8namespace Cvb
9{
10
11 CVB_BEGIN_INLINE_NS
12
14
19 class Ellipse final
20 {
21 public:
23
30 Ellipse(Point2D<double> center, double radiusA, double radiusB, Angle rotation)
31 : center_(center)
32 , radiusA_(std::max(std::abs(radiusA), std::abs(radiusB)))
33 , radiusB_(std::min(std::abs(radiusA), std::abs(radiusB)))
34 , rotation_(rotation)
35 {
36 rotation_.SetIsTrimmed(true);
37
38 if (radiusA < 0.0)
39 throw std::invalid_argument("invalid radius value");
40 if (radiusB < 0.0)
41 throw std::invalid_argument("invalid radius value");
42 }
43
45
49 Point2D<double> Center() const noexcept
50 {
51 return center_;
52 }
53
55
59 void SetCenter(Point2D<double> center) noexcept
60 {
61 center_ = center;
62 }
63
65
69 double RadiusA() const noexcept
70 {
71 return radiusA_;
72 }
73
75
79 void SetRadiusA(double radiusA)
80 {
81 if (radiusA <= radiusB_)
82 throw std::invalid_argument("invalid radius value");
83 radiusA_ = std::abs(radiusA);
84 }
85
87
91 double RadiusB() const noexcept
92 {
93 return radiusB_;
94 }
95
97
101 void SetRadiusB(double radiusB)
102 {
103 if (radiusB < 0.0 || radiusB > radiusA_)
104 throw std::invalid_argument("invalid radius value");
105 radiusB_ = std::abs(radiusB);
106 }
107
109
113 Angle Rotation() const noexcept
114 {
115 return rotation_;
116 }
117
119
123 void SetRotation(Angle rotation) noexcept
124 {
125 rotation_ = rotation;
126 rotation_.SetIsTrimmed(true);
127 }
128
130
135 bool operator==(const Ellipse &ellipse) const noexcept
136 {
137 return (center_ == ellipse.center_ && radiusA_ == ellipse.radiusA_ && radiusB_ == ellipse.radiusB_
138 && rotation_ == ellipse.rotation_);
139 }
140
142
147 bool operator!=(const Ellipse &ellipse) const noexcept
148 {
149 return !(*this == ellipse);
150 }
151
152 private:
153 Point2D<double> center_;
154 double radiusA_;
155 double radiusB_;
156 Angle rotation_;
157 };
158
159 CVB_END_INLINE_NS
160
161} // namespace Cvb
Object for convenient and type - safe handling of angles.
Definition angle.hpp:16
void SetRadiusB(double radiusB)
Sets the smaller radius of the ellipse.
Definition ellipse.hpp:101
Point2D< double > Center() const noexcept
Gets the center of the ellipse.
Definition ellipse.hpp:49
void SetRotation(Angle rotation) noexcept
Sets the angle by which the ellipse is rotated.
Definition ellipse.hpp:123
bool operator==(const Ellipse &ellipse) const noexcept
Compares to an other ellipse.
Definition ellipse.hpp:135
void SetRadiusA(double radiusA)
Sets the larger radius A of the ellipse.
Definition ellipse.hpp:79
double RadiusB() const noexcept
Gets the larger radius of the ellipse.
Definition ellipse.hpp:91
Angle Rotation() const noexcept
Gets the angle by which the ellipse is rotated.
Definition ellipse.hpp:113
void SetCenter(Point2D< double > center) noexcept
Sets the center of the ellipse.
Definition ellipse.hpp:59
double RadiusA() const noexcept
Gets the larger radius of the ellipse.
Definition ellipse.hpp:69
bool operator!=(const Ellipse &ellipse) const noexcept
Compares to an other ellipse.
Definition ellipse.hpp:147
Ellipse(Point2D< double > center, double radiusA, double radiusB, Angle rotation)
Create an ellipse.
Definition ellipse.hpp:30
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17