Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
LinearIntersection.hpp
Go to the documentation of this file.
1#pragma once
2#include <fishnet/Vec2D.hpp>
3#include <fishnet/Option.hpp>
5
6namespace fishnet::geometry{
7
15constexpr static fishnet::Option<Vec2DReal> inline linearIntersection(ILine auto const& l, ILine auto const & r) noexcept {
16 if (l.isParallel(r))
17 return {};
18 auto dThis = Vec2DReal(l.direction());
19 const auto & p = l.p();
20 const auto & q = l.q();
21 const auto & s = r.p();
22 const auto & t = r.q();
23 using namespace fishnet::math;
24 DEFAULT_FLOATING_POINT denominator = (p.x - q.x) * (s.y - t.y) - (p.y - q.y) *(s.x - t.x);
25 DEFAULT_FLOATING_POINT lambda = ((p.x - s.x) * (s.y - t.y) - (p.y - s.y) * (s.x - t.x)) /denominator;
26 Vec2DReal intersectionOfLines = p + (dThis * lambda);
27 return intersectionOfLines;
28}
29
37constexpr static fishnet::Option<Vec2DReal> inline linearIntersection(LinearGeometry auto const& lhs, LinearGeometry auto const& rhs) requires(!ILine<decltype(lhs)> || !ILine<decltype(rhs)>) {
38 return linearIntersection(lhs.toLine(),rhs.toLine()).filter([&lhs,&rhs](const auto & intersection){return lhs.contains(intersection) && rhs.contains(intersection);});
39}
40
41constexpr static bool inline areParallel(LinearGeometry auto const & lhs, LinearGeometry auto const & rhs) noexcept {
42 return lhs.direction().isParallel(rhs.direction());
43}
44
45constexpr static bool intersect(LinearGeometry auto const & lhs,LinearGeometry auto const& rhs) noexcept {
46 return linearIntersection(lhs,rhs).has_value();
47}
48}
Definition Option.hpp:13
Option< T > filter(fishnet::util::Predicate< T > auto const &predicate)
If the Option has a value and the predicate returns true, return the Option. Otherwise,...
Definition Option.hpp:136
Implementation of a two-dimensional vector.
Definition Vec2D.hpp:16
Interface for a line A line is defined through two points p and q, defining a direction vector.
Definition ILine.hpp:76
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
Vec2D< fishnet::math::DEFAULT_FLOATING_POINT > Vec2DReal
Definition Vec2D.hpp:220
Definition NumericConcepts.hpp:4
double DEFAULT_FLOATING_POINT
Definition NumericConcepts.hpp:12