#pragma once #include #include "Plane.h" #include namespace J3ML::Geometry { /// Clamps the given input value to the range [min, max]. /** @see Clamp01(), Min(), Max(). */ template T Clamp(const T &val, const T &floor, const T &ceil) { assert(floor <= ceil); return val <= ceil ? (val >= floor ? val : floor) : ceil; } /// Clamps the given input value to the range [0, 1]. /** @see Clamp(), Min(), Max(). */ template T Clamp01(const T &val) { return Clamp(val, T(0), T(1)); } using LinearAlgebra::Vector3; class LineSegment { public: LineSegment(); LineSegment(const Vector3& a, const Vector3& b); Vector3 A; Vector3 B; bool Contains(const Vector3&) const; void ProjectToAxis(const Vector3 &direction, float &outMin, float &outMax) const; Vector3 GetPoint(float d) const; Vector3 ClosestPoint(const Vector3 &point, float &d) const; Vector3 ClosestPoint(const Ray &other, float &d, float &d2) const; float Distance(const Vector3 &point) const; float DistanceSq(const Vector3& point) const; float Distance(const Vector3 &point, float &d) const; float Distance(const Ray &other) const; float Distance(const Ray &other, float &d) const; float Distance(const Ray &other, float &d, float &d2) const; float Distance(const Line &other) const; float Distance(const Line &other, float &d) const; float Distance(const Line &other, float &d, float &d2) const; float Distance(const LineSegment &other) const; float Distance(const LineSegment &other, float &d) const; float Distance(const LineSegment &other, float &d, float &d2) const; float Distance(const Plane& other) const; Vector3 Dir() const; float Length() const; float LengthSq() const; float DistanceSq(const LineSegment &other) const; Vector3 ClosestPoint(const LineSegment &other, float &d, float &d2) const; Vector3 ClosestPoint(const Line &other, float &d, float &d2) const; }; }