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
11CVB_BEGIN_INLINE_NS
12
14
19class Ellipse final
20{
21 public:
22
24
31 Ellipse(Point2D<double> center, double radiusA, double radiusB, Angle rotation)
32 : center_(center)
33 , radiusA_(std::max(std::abs(radiusA), std::abs(radiusB)))
34 , radiusB_(std::min(std::abs(radiusA), std::abs(radiusB)))
35 , rotation_(rotation)
36 {
37 rotation_.SetIsTrimmed(true);
38
39 if(radiusA < 0.0)
40 throw std::invalid_argument("invalid radius value");
41 if(radiusB < 0.0)
42 throw std::invalid_argument("invalid radius value");
43 }
44
46
50 Point2D<double> Center() const noexcept
51 {
52 return center_;
53 }
54
56
60 void SetCenter(Point2D<double> center) noexcept
61 {
62 center_ = center;
63 }
64
66
70 double RadiusA() const noexcept
71 {
72 return radiusA_;
73 }
74
76
80 void SetRadiusA(double radiusA)
81 {
82 if (radiusA <= radiusB_)
83 throw std::invalid_argument("invalid radius value");
84 radiusA_ = std::abs(radiusA);
85 }
86
88
92 double RadiusB() const noexcept
93 {
94 return radiusB_;
95 }
96
98
102 void SetRadiusB(double radiusB)
103 {
104 if (radiusB < 0.0 || radiusB > radiusA_)
105 throw std::invalid_argument("invalid radius value");
106 radiusB_ = std::abs(radiusB);
107 }
108
110
114 Angle Rotation() const noexcept
115 {
116 return rotation_;
117 }
118
120
124 void SetRotation(Angle rotation) noexcept
125 {
126 rotation_ = rotation;
127 rotation_.SetIsTrimmed(true);
128 }
129
131
136 bool operator==(const Ellipse& ellipse) const noexcept
137 {
138 return (center_ == ellipse.center_
139 && radiusA_ == ellipse.radiusA_
140 && radiusB_ == ellipse.radiusB_
141 && rotation_ == ellipse.rotation_);
142 }
143
144
146
151 bool operator!=(const Ellipse& ellipse) const noexcept
152 {
153 return !(*this == ellipse);
154 }
155
156 private:
157
158 Point2D<double> center_;
159 double radiusA_;
160 double radiusB_;
161 Angle rotation_;
162
163};
164
165
166CVB_END_INLINE_NS
167
168}
Object for convenient and type - safe handling of angles.
Definition: angle.hpp:19
void SetIsTrimmed(bool trim) noexcept
Set trimming of the value of the angle to the range -PI...PI.
Definition: angle.hpp:119
Class representing an ellipse.
Definition: ellipse.hpp:20
void SetRadiusB(double radiusB)
Sets the smaller radius of the ellipse.
Definition: ellipse.hpp:102
Point2D< double > Center() const noexcept
Gets the center of the ellipse.
Definition: ellipse.hpp:50
void SetRotation(Angle rotation) noexcept
Sets the angle by which the ellipse is rotated.
Definition: ellipse.hpp:124
bool operator==(const Ellipse &ellipse) const noexcept
Compares to an other ellipse.
Definition: ellipse.hpp:136
void SetRadiusA(double radiusA)
Sets the larger radius A of the ellipse.
Definition: ellipse.hpp:80
double RadiusB() const noexcept
Gets the larger radius of the ellipse.
Definition: ellipse.hpp:92
Angle Rotation() const noexcept
Gets the angle by which the ellipse is rotated.
Definition: ellipse.hpp:114
void SetCenter(Point2D< double > center) noexcept
Sets the center of the ellipse.
Definition: ellipse.hpp:60
double RadiusA() const noexcept
Gets the larger radius of the ellipse.
Definition: ellipse.hpp:70
bool operator!=(const Ellipse &ellipse) const noexcept
Compares to an other ellipse.
Definition: ellipse.hpp:151
Ellipse(Point2D< double > center, double radiusA, double radiusB, Angle rotation)
Create an ellipse.
Definition: ellipse.hpp:31
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24