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
10CVB_BEGIN_INLINE_NS
11
13
15class Line2D final
16{
17public:
18
19
21
26 Line2D(Point2D<double> normal, double distance) noexcept
27 : normal_(normal)
28 , distance_(distance)
29 {
30 normal_.SetLength(1.0);
31 }
32
34
40 {
41 Point2D<double> tmp = p2 - p1;
42 tmp = Point2D<double>(tmp.Y(), -tmp.X());
43 SetNormal(tmp);
44 SetDistance(normal_ * p1);
45 }
46
48
52 Point2D<double> Normal() const noexcept
53 {
54 return normal_;
55 }
56
58
63 {
64 normal_ = normal;
65 normal.SetLength(1);
66 }
67
69
73 double Distance() const noexcept
74 {
75 return distance_;
76 }
77
79
83 void SetDistance(double distance) noexcept
84 {
85 distance_ = distance;
86 }
87
89
94 bool operator==(const Line2D& line) const noexcept
95 {
96 return (normal_ == line.normal_
97 && distance_ == line.distance_);
98 }
99
100
102
107 bool operator!=(const Line2D& line) const noexcept
108 {
109 return !(*this == line);
110 }
111
112 private:
113
114
115 Point2D<double> normal_;
116 double distance_ = 0.0;
117};
118
119CVB_END_INLINE_NS
120
121}
Object representing an infinite line in 2 dimensional space.
Definition: line_2d.hpp:16
Line2D(Point2D< double > normal, double distance) noexcept
Create a line object.
Definition: line_2d.hpp:26
double Distance() const noexcept
Gets the distance of the line from the origin.
Definition: line_2d.hpp:73
Point2D< double > Normal() const noexcept
Gets the normal vector of the line.
Definition: line_2d.hpp:52
void SetDistance(double distance) noexcept
Sets the distance of the line from the origin.
Definition: line_2d.hpp:83
bool operator==(const Line2D &line) const noexcept
Compares to an other line.
Definition: line_2d.hpp:94
bool operator!=(const Line2D &line) const noexcept
Compares to an other line.
Definition: line_2d.hpp:107
Line2D(Point2D< double > p1, Point2D< double > p2) noexcept
Create a line object.
Definition: line_2d.hpp:39
void SetNormal(Point2D< double > normal)
Sets the normal vector of the line.
Definition: line_2d.hpp:62
T X() const noexcept
Gets the x-component of the point.
Definition: point_2d.hpp:86
T Y() const noexcept
Gets the y-component of the point.
Definition: point_2d.hpp:106
void SetLength(T length) noexcept
Sets the length of the vector represented by this point object.
Definition: point_2d.hpp:137
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24