Pangolin
Header-only C++20 plane computational geometry library
Loading...
Searching...
No Matches
distancel1.hpp File Reference

Manhattan (L1) distance between shapes. More...

#include "implementation/distance.hpp"
#include <cmath>
#include <numbers>

Go to the source code of this file.

Namespaces

namespace  pgl

Macros

#define PGL_HPI_DISTANCE_L1(ConceptName, ArgType)

Detailed Description

Manhattan (L1) distance between shapes.

Mirrors the shape coverage of distance.hpp's squaredDistance, but for the L1 metric |dx| + |dy| instead of the Euclidean one. Every overload is templated on a ResultNumber coordinate type exactly like squaredDistance, and shares its caveat: an integer ResultNumber divides (and therefore truncates) whenever the true distance is fractional, which happens for any segment/ray/line that isn't axis-aligned. Request a floating-point or pgl::Rational ResultNumber for an accurate result.

L1 and LInf are implemented independently in this file and in distancelinf.hpp respectively – neither is derived from the other via a coordinate transform.

Macro Definition Documentation

◆ PGL_HPI_DISTANCE_L1

#define PGL_HPI_DISTANCE_L1 ( ConceptName,
ArgType )
Value:
template <class PointType, class LabelType> \
template <class ResultNumber, ConceptName ArgType> \
constexpr auto HalfplaneIntersection<PointType, LabelType>::distanceL1( \
const ArgType& other) const { \
if (intersects(other)) { \
return ResultNumber{}; \
} \
return detail::regionEdgesDistanceL1<ResultNumber>(*this, other); \
}