17 #ifndef GZ_MATH_LINE2_HH_
18 #define GZ_MATH_LINE2_HH_
22 #include <gz/math/config.hh>
27 inline namespace GZ_MATH_VERSION_NAMESPACE {
40 this->Set(_ptA, _ptB);
48 public:
Line2(T _x1, T _y1, T _x2, T _y2)
50 this->Set(_x1, _y1, _x2, _y2);
68 public:
void Set(T _x1, T _y1, T _x2, T _y2)
70 this->pts[0].Set(_x1, _y1);
71 this->pts[1].Set(_x2, _y2);
82 return (this->pts[0].X() - this->pts[1].X()) *
83 (_line[0].Y() -_line[1].Y()) -
84 (this->pts[0].Y() - this->pts[1].Y()) *
85 (_line[0].X() - _line[1].X());
95 return (_pt.
Y() - this->pts[0].Y()) *
96 (this->pts[1].X() - this->pts[0].X()) -
97 (_pt.
X() - this->pts[0].X()) *
98 (this->pts[1].Y() - this->pts[0].Y());
108 double _epsilon = 1e-6)
const
111 static_cast<T
>(0),
static_cast<T
>(_epsilon));
122 double _epsilon = 1e-6)
const
125 static_cast<T
>(0),
static_cast<T
>(_epsilon));
136 double _epsilon = 1e-6)
const
138 return this->Parallel(_line, _epsilon) &&
139 this->Intersect(_line, _epsilon);
148 double _epsilon = 1e-6)
const
150 return this->Collinear(_pt, _epsilon) && this->Within(_pt, _epsilon);
161 double _epsilon = 1e-6)
const
163 auto eps =
static_cast<T
>(_epsilon);
164 return _pt.
X() <=
std::max(this->pts[0].X(),
165 this->pts[1].X()) + eps &&
167 this->pts[1].X()) - eps &&
169 this->pts[1].Y()) + eps &&
171 this->pts[1].Y()) - eps;
180 double _epsilon = 1e-6)
const
183 return this->Intersect(_line, ignore, _epsilon);
195 double _epsilon = 1e-6)
const
197 T d = this->CrossProduct(_line);
201 if (
math::equal(d,
static_cast<T
>(0),
static_cast<T
>(_epsilon)))
204 if (this->Within(_line[0], _epsilon))
210 else if (this->Within(_line[1], _epsilon))
220 _pt.
X((_line[0].X() - _line[1].X()) *
221 (this->pts[0].X() * this->pts[1].Y() -
222 this->pts[0].Y() * this->pts[1].X()) -
223 (this->pts[0].X() - this->pts[1].X()) *
224 (_line[0].X() * _line[1].Y() - _line[0].Y() * _line[1].X()));
226 _pt.
Y((_line[0].Y() - _line[1].Y()) *
227 (this->pts[0].X() * this->pts[1].Y() -
228 this->pts[0].Y() * this->pts[1].X()) -
229 (this->pts[0].Y() - this->pts[1].Y()) *
230 (_line[0].X() * _line[1].Y() - _line[0].Y() * _line[1].X()));
234 if (_pt.
X() <
std::min(this->pts[0].X(), this->pts[1].X()) ||
235 _pt.
X() >
std::max(this->pts[0].X(), this->pts[1].X()) ||
236 _pt.
X() <
std::min(_line[0].X(), _line[1].X()) ||
237 _pt.
X() >
std::max(_line[0].X(), _line[1].X()))
242 if (_pt.
Y() <
std::min(this->pts[0].Y(), this->pts[1].Y()) ||
243 _pt.
Y() >
std::max(this->pts[0].Y(), this->pts[1].Y()) ||
244 _pt.
Y() <
std::min(_line[0].Y(), _line[1].Y()) ||
245 _pt.
Y() >
std::max(_line[0].Y(), _line[1].Y()))
257 return static_cast<T
>(this->pts[0].Distance(this->pts[1]));
264 if (
math::equal(this->pts[1].X(), this->pts[0].X()))
267 return (this->pts[1].Y() - this->pts[0].Y()) /
268 static_cast<double>(this->pts[1].X() - this->pts[0].X());
276 return this->pts[0] == _line[0] && this->pts[1] == _line[1];
284 return !(*
this == _line);
302 _out << _line[0] <<
" " << _line[1];