CVB++ 15.0
line_2d.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
15 class Line2D final
16 {
17 public:
19
22 Line2D() noexcept = default;
23
25
30 Line2D(Point2D<double> normal, double distance) noexcept
31 : normal_(normal)
32 , distance_(distance)
33 {
34 normal_.SetLength(1.0);
35 }
36
38
44 {
45 Point2D<double> tmp = p2 - p1;
46 tmp = Point2D<double>(tmp.Y(), -tmp.X());
47 SetNormal(tmp);
48 SetDistance(normal_ * p1);
49 }
50
52
56 Point2D<double> Normal() const noexcept
57 {
58 return normal_;
59 }
60
62
67 {
68 normal_ = normal;
69 normal.SetLength(1);
70 }
71
73
77 double Distance() const noexcept
78 {
79 return distance_;
80 }
81
83
87 void SetDistance(double distance) noexcept
88 {
89 distance_ = distance;
90 }
91
93
98 bool operator==(const Line2D &line) const noexcept
99 {
100 return (normal_ == line.normal_ && distance_ == line.distance_);
101 }
102
104
109 bool operator!=(const Line2D &line) const noexcept
110 {
111 return !(*this == line);
112 }
113
114 private:
115 Point2D<double> normal_;
116 double distance_ = 0.0;
117 };
118
119 CVB_END_INLINE_NS
120
121} // namespace Cvb
Line2D() noexcept=default
Create default line.
double Distance() const noexcept
Gets the distance of the line from the origin.
Definition line_2d.hpp:77
Point2D< double > Normal() const noexcept
Gets the normal vector of the line.
Definition line_2d.hpp:56
void SetDistance(double distance) noexcept
Sets the distance of the line from the origin.
Definition line_2d.hpp:87
bool operator==(const Line2D &line) const noexcept
Compares to an other line.
Definition line_2d.hpp:98
bool operator!=(const Line2D &line) const noexcept
Compares to an other line.
Definition line_2d.hpp:109
Line2D(Point2D< double > p1, Point2D< double > p2) noexcept
Create a line object.
Definition line_2d.hpp:43
void SetNormal(Point2D< double > normal)
Sets the normal vector of the line.
Definition line_2d.hpp:66
Multi-purpose 2D vector class.
Definition point_2d.hpp:20
T X() const noexcept
Gets the x-component of the point.
Definition point_2d.hpp:84
T Y() const noexcept
Gets the y-component of the point.
Definition point_2d.hpp:104
void SetLength(T length) noexcept
Sets the length of the vector represented by this point object.
Definition point_2d.hpp:135
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17