13template<fishnet::math::Number T = fishnet::math::DEFAULT_NUMERIC>
25 template<fishnet::math::Number U,
typename = std::enable_if_t<!std::is_same_v<U,T> && std::is_same_v<T,fishnet::math::DEFAULT_NUMERIC>>>
28 template<fishnet::math::Number U,
typename = std::enable_if_t<!std::is_same_v<U,T> && std::is_same_v<T,fishnet::math::DEFAULT_NUMERIC>>>
40 return Segment(this->_q,this->_p);
49 return _p.
x > _q.
x ? _p:_q;
50 return _p.
y > _q.
y ? _p:_q;
55 return _p.
x < _q.
x ? _p:_q;
56 return _p.
y < _q.
y ? _p:_q;
61 return _p.
y < _q.
y ? _p : _q;
62 return _p.
x < _q.
x ? _p : _q;
67 return _p.
y > _q.
y ? _p : _q;
68 return _p.
x > _q.
x ? _p : _q;
72 return _p == point or _q == point;
122 return (this->_p == other.p() or this->_p == other.q() or this->_q == other.q() or this->_q == other.p())
124 && not other.contains(*
this);
127 template<fishnet::math::Number U>
129 return (this->_p == other.p() and this->_q == other.q()) or (this->_q==other.p() and this->_p == other.q());
143 FLOAT_TYPE lambdaY = FLOAT_TYPE(point.y - _p.
y) / FLOAT_TYPE(dir.y);
144 FLOAT_TYPE tolerance = EPSILON / fabs(FLOAT_TYPE(dir.y));
145 return lambdaY >= 0.0 - tolerance and lambdaY <= 1.0 + tolerance and fabs(_p.
x - point.x) < EPSILON;
148 FLOAT_TYPE lambdaX = FLOAT_TYPE(point.x - _p.
x) / FLOAT_TYPE(dir.x);
149 FLOAT_TYPE tolerance = EPSILON / fabs(FLOAT_TYPE(dir.x));
150 return lambdaX >= 0.0 - tolerance and lambdaX <= 1.0 + tolerance and fabs(_p.
y - point.y) < EPSILON;
152 FLOAT_TYPE lambdaX = FLOAT_TYPE(point.x - _p.
x) / FLOAT_TYPE(dir.x);
153 FLOAT_TYPE lambdaY = FLOAT_TYPE(point.y - _p.
y) / FLOAT_TYPE(dir.y);
154 return fabs(lambdaX - lambdaY) < EPSILON and lambdaX >= 0.0 - EPSILON and lambdaY <= 1.0 + EPSILON;
159 auto orthogonalLine =
Line(point, point + orthogonalDirection);
167 std::array<fishnet::math::DEFAULT_FLOATING_POINT,4> candidates {
168 other.distance(this->_p),
169 other.distance(this->_q),
173 return *std::ranges::min_element(candidates);
180 constexpr size_t hash() const noexcept {
181 return this->_p.
hash() ^ this->_q.
hash();
188static_assert(ISegment<Segment<double>>);
189static_assert(LinearGeometry<Segment<double>>);
191template class Segment<fishnet::math::DEFAULT_NUMERIC>;
Implementation of a line.
Definition Line.hpp:14
Implementation of a segment.
Definition Segment.hpp:14
constexpr const Vec2D< T > & rightEndpoint() const noexcept
Definition Segment.hpp:65
constexpr Line< T > toLine() const noexcept
Definition Segment.hpp:83
constexpr fishnet::math::DEFAULT_FLOATING_POINT distance(ISegment auto const &other) const noexcept
Definition Segment.hpp:166
constexpr bool isValid() const noexcept
Definition Segment.hpp:79
constexpr Segment(Vec2D< T > p, Vec2D< U > q)
Definition Segment.hpp:26
constexpr bool intersects(LinearGeometry auto const &other) const noexcept
Definition Segment.hpp:91
constexpr const Vec2D< T > & p() const noexcept
Definition Segment.hpp:31
constexpr Vec2D< T > direction() const noexcept
Definition Segment.hpp:43
constexpr bool operator==(const Segment< U > &other) const noexcept
Definition Segment.hpp:128
constexpr fishnet::math::DEFAULT_FLOATING_POINT distance(IPoint auto const &point) const noexcept
Definition Segment.hpp:157
constexpr const Vec2D< T > & leftEndpoint() const noexcept
Definition Segment.hpp:59
constexpr const Vec2D< T > & lowerEndpoint() const noexcept
Definition Segment.hpp:53
constexpr const Vec2D< T > & q() const noexcept
Definition Segment.hpp:35
T numeric_type
Definition Segment.hpp:20
constexpr bool isEndpoint(IPoint auto const &point) const noexcept
Definition Segment.hpp:71
constexpr std::string toString() const noexcept
Definition Segment.hpp:184
constexpr bool contains(ISegment auto const &other) const noexcept
Definition Segment.hpp:108
constexpr bool overlaps(ISegment auto const &other) const noexcept
Two Segments have an Overlay if the are contained on the same line: -> the Segments must be parallel ...
Definition Segment.hpp:104
constexpr Segment< T > flip() const noexcept
Definition Segment.hpp:39
constexpr bool touches(ISegment auto const &other) const noexcept
Two Segments touch each other when one endpoint is equal and neither Segment is fully contained in th...
Definition Segment.hpp:121
constexpr fishnet::math::DEFAULT_FLOATING_POINT length() const noexcept
Definition Segment.hpp:75
constexpr bool isParallel(LinearGeometry auto const &other) const noexcept
Definition Segment.hpp:87
constexpr bool contains(IPoint auto const &point) const noexcept
Definition Segment.hpp:132
static constexpr GeometryType type
Definition Segment.hpp:21
constexpr const Vec2D< T > & upperEndpoint() const noexcept
Definition Segment.hpp:47
constexpr fishnet::Option< Vec2DReal > intersection(LinearGeometry auto const &other) const noexcept
Definition Segment.hpp:176
constexpr Segment(Vec2D< U > p, Vec2D< T > q)
Definition Segment.hpp:29
constexpr size_t hash() const noexcept
Definition Segment.hpp:180
constexpr Segment(Vec2D< T > p, Vec2D< T > q)
Definition Segment.hpp:23
Implementation of a two-dimensional vector.
Definition Vec2D.hpp:16
T y
Definition Vec2D.hpp:21
T x
Definition Vec2D.hpp:20
constexpr fishnet::math::DEFAULT_FLOATING_POINT length() const
Definition Vec2D.hpp:142
constexpr size_t hash() const noexcept
Definition Vec2D.hpp:179
constexpr std::string toString() const noexcept
Definition Vec2D.hpp:185
constexpr fishnet::math::DEFAULT_FLOATING_POINT distance(const IPoint auto &other) const
Definition Vec2D.hpp:146
constexpr Vec2D< T > orthogonal() const noexcept
Definition Vec2D.hpp:150
Interface for a point.
Definition IPoint.hpp:92
Interface for a segment A segment is formed between two points p and q, containing only the points on...
Definition ISegment.hpp:105
Definition IGeometry.hpp:13
Definition BoundingBoxWrapper.hpp:5
static constexpr fishnet::Option< Vec2DReal > linearIntersection(ILine auto const &l, ILine auto const &r) noexcept
Computation of line intersection.
Definition LinearIntersection.hpp:15
static constexpr bool areParallel(LinearGeometry auto const &lhs, LinearGeometry auto const &rhs) noexcept
Definition LinearIntersection.hpp:41
static constexpr bool intersect(LinearGeometry auto const &lhs, LinearGeometry auto const &rhs) noexcept
Definition LinearIntersection.hpp:45
GeometryType
Definition GeometryBase.hpp:6
constexpr bool areEqual(T lhs, U rhs) noexcept
Definition Constants.hpp:31
static constexpr DEFAULT_FLOATING_POINT EPSILON
Definition Constants.hpp:20
double DEFAULT_FLOATING_POINT
Definition NumericConcepts.hpp:12