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
20
23 Line2D() noexcept = default;
24
26
31 Line2D(Point2D<double> normal, double distance) noexcept
32 : normal_(normal)
33 , distance_(distance)
34 {
35 normal_.SetLength(1.0);
36 }
37
39
45 {
46 Point2D<double> tmp = p2 - p1;
47 tmp = Point2D<double>(tmp.Y(), -tmp.X());
48 SetNormal(tmp);
49 SetDistance(normal_ * p1);
50 }
51
53
57 Point2D<double> Normal() const noexcept
58 {
59 return normal_;
60 }
61
63
68 {
69 normal_ = normal;
70 normal.SetLength(1);
71 }
72
74
78 double Distance() const noexcept
79 {
80 return distance_;
81 }
82
84
88 void SetDistance(double distance) noexcept
89 {
90 distance_ = distance;
91 }
92
94
99 bool operator==(const Line2D& line) const noexcept
100 {
101 return (normal_ == line.normal_
102 && distance_ == line.distance_);
103 }
104
105
107
112 bool operator!=(const Line2D& line) const noexcept
113 {
114 return !(*this == line);
115 }
116
117 private:
118
119
120 Point2D<double> normal_;
121 double distance_ = 0.0;
122};
123
124CVB_END_INLINE_NS
125
126}
Object representing an infinite line in 2 dimensional space.
Definition: line_2d.hpp:16
Line2D() noexcept=default
Create default line.
double Distance() const noexcept
Gets the distance of the line from the origin.
Definition: line_2d.hpp:78
Point2D< double > Normal() const noexcept
Gets the normal vector of the line.
Definition: line_2d.hpp:57
void SetDistance(double distance) noexcept
Sets the distance of the line from the origin.
Definition: line_2d.hpp:88
bool operator==(const Line2D &line) const noexcept
Compares to an other line.
Definition: line_2d.hpp:99
bool operator!=(const Line2D &line) const noexcept
Compares to an other line.
Definition: line_2d.hpp:112
Line2D(Point2D< double > p1, Point2D< double > p2) noexcept
Create a line object.
Definition: line_2d.hpp:44
void SetNormal(Point2D< double > normal)
Sets the normal vector of the line.
Definition: line_2d.hpp:67
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:88
T Y() const noexcept
Gets the y-component of the point.
Definition: point_2d.hpp:108
void SetLength(T length) noexcept
Sets the length of the vector represented by this point object.
Definition: point_2d.hpp:139
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15