Skip to content

HMath.Geometry.Internal

Module index · Numerical conventions

Description

Shared finite Euclidean geometry. Coordinates are bounded by 1e50 to keep Double products representable; exact Rational predicates determine signs. Public checked operations validate constructors, including raw record values.

On this page

API Purpose
Point2 Cartesian two-dimensional point, also used for vectors.
P2 Declaration and type contract below.
Point3 Cartesian right-handed three-dimensional point/vector.
P3 Declaration and type contract below.
PointND A point of dimension 1..16.
PointND Declaration and type contract below.
Line Parametric line origin+t*direction; direction must be nonzero.
Line Declaration and type contract below.
Ray Parametric ray origin+t*direction, t>=0.
Ray Declaration and type contract below.
Segment Closed segment with two endpoints; zero length is valid.
Segment Declaration and type contract below.
Plane Plane normal dot x = offset, with a nonzero normal.
Plane Declaration and type contract below.
Triangle Closed triangle; zero-area triangles are rejected by triangle operations.
Triangle Declaration and type contract below.
Rectangle Axis-aligned rectangle with ordered corners.
Rectangle Declaration and type contract below.
Circle Circle with nonnegative radius.
Circle Declaration and type contract below.
Ellipse Rotated ellipse: positive semiaxes, counterclockwise angle in radians.
Ellipse Declaration and type contract below.
Polygon Simple polygon; vertices are implicitly closed and no duplicate endpoint is needed.
Polygon Declaration and type contract below.
Sphere Closed sphere, including a zero radius.
Sphere Declaration and type contract below.
AABB Ordered, closed axis-aligned bounds in 1..16 dimensions.
AABB Declaration and type contract below.
OBB Oriented three-dimensional box: center, three orthonormal axes, half-extents.
OBB Declaration and type contract below.
Capsule Capsule around the closed axis segment.
Capsule Declaration and type contract below.
Cylinder Finite cylinder with endpoint centers and radius; endpoints must differ.
Cylinder Declaration and type contract below.
Cone Finite cone with apex, base center, and radius; axis must be nonzero.
Cone Declaration and type contract below.
Frustum Convex frustum represented by six inward half-spaces n dot x >= offset.
Frustum Declaration and type contract below.
Orientation Sign of an exact predicate on the input Double values.
Clockwise Declaration and type contract below.
Collinear Declaration and type contract below.
Counterclockwise Declaration and type contract below.
Location Point position with boundary reported separately.
Outside Declaration and type contract below.
Boundary Declaration and type contract below.
Inside Declaration and type contract below.
finite Test whether a Double is neither NaN nor infinite.
require Given predicate then diagnostic text, return Right () if satisfied or Left (DomainError text).
coord Accept a finite geometry coordinate only when its absolute value is <=1e50, bounding downstream Double products.
coords2 Extract [x,y] from a Point2 without validation.
coords3 Extract [x,y,z] from a Point3 without validation.
coordsND Extract ordered coordinate list from a PointND without validation.
check2 Validate both Point2 coordinates as finite with absolute magnitude <=1e50; invalid data returns DomainError.
check3 Validate all Point3 coordinates as finite with absolute magnitude <=1e50; invalid data returns DomainError.
checkND Require 1..16 coordinates, all finite and bounded by 1e50 in magnitude.
checkPair Validate both ND points and require equal dimensions.
checked Return the supplied list if every Double is finite, otherwise Left NonFiniteResult.
point2 Given x,y, construct Point2 after bounded finite-coordinate validation.
point3 Given x,y,z, construct Point3 after bounded finite-coordinate validation.
pointND Construct a checked ND point from 1..16 bounded finite coordinates.
dot Unchecked sum of pairwise list products using zipWith; unequal lists truncate to the shorter length.
norm Return scaled Euclidean list norm to reduce intermediate overflow; empty/all-zero list yields zero.
sub Unchecked coordinatewise left-minus-right list subtraction, truncating to the shorter list on mismatch.
plus Unchecked coordinatewise list addition, truncating to the shorter list on mismatch.
scale Given Double scalar then coordinate list, return all coordinates multiplied by it without validation.
cross Return right-handed cross product of two Point3 vectors.
add2 Add Point2 coordinates componentwise without validation.
sub2 Subtract right Point2 coordinates from left, without validation.
scale2 Given scalar then Point2, scale both coordinates without validation.
cross2 Return 2D determinant axby-aybx as Double without validation.
dot2 Return 2D dot product axbx+ayby without validation.
norm2 Return scaled Euclidean length of a Point2 without checked finite validation.
from3 Convert a list of exactly three Doubles to Point3; all other lengths return origin P3 0 0 0.
edges Pair each polygon-list element with its cyclic successor, including the last-to-first edge.
orientExact Given finite points a,b,c, compute exact Rational determinant of their represented Double coordinates.
orient Compare orientExact determinant with zero, returning GT for counterclockwise, EQ for collinear, LT for clockwise.
onSegment Given endpoints a,b then point p, test exact collinearity and inclusive coordinate bounds.
checkPolygon Validate a simple polygon with 3..256 bounded finite vertices, no adjacent duplicates, nonzero area and no nonadjacent edge intersection.
signedArea Return oriented shoelace area using exact Rational intermediate arithmetic on finite Double coordinates.
ccw Return polygon vertices in counterclockwise order by reversing negative signed area; zero-area input remains unchanged.
locateUnchecked Given valid simple polygon vertices then finite Point2, return Boundary for an edge point, otherwise Inside/Outside by ray parity.
firstOr Given fallback then list, return its first element or the fallback for empty input.

Documentation

Point2

data Point2 Source #

Cartesian two-dimensional point, also used for vectors.

Constructors

P2 Double Double 

Instances

Instances details
Show Point2 Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Point2 Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Point2 -> Point2 -> Bool #

(/=) :: Point2 -> Point2 -> Bool #

Ord Point2 Source # 
Instance details

Defined in HMath.Geometry.Internal

Point3

data Point3 Source #

Cartesian right-handed three-dimensional point/vector.

Constructors

P3 Double Double Double 

Instances

Instances details
Show Point3 Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Point3 Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Point3 -> Point3 -> Bool #

(/=) :: Point3 -> Point3 -> Bool #

Ord Point3 Source # 
Instance details

Defined in HMath.Geometry.Internal

PointND

newtype PointND Source #

A point of dimension 1..16.

Constructors

PointND [Double] 

Instances

Instances details
Show PointND Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq PointND Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: PointND -> PointND -> Bool #

(/=) :: PointND -> PointND -> Bool #

Ord PointND Source # 
Instance details

Defined in HMath.Geometry.Internal

Line

data Line Source #

Parametric line origin+t*direction; direction must be nonzero.

Constructors

Line PointND PointND 

Instances

Instances details
Show Line Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

showsPrec :: Int -> Line -> ShowS #

show :: Line -> String #

showList :: [Line] -> ShowS #

Eq Line Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Line -> Line -> Bool #

(/=) :: Line -> Line -> Bool #

Ray

data Ray Source #

Parametric ray origin+t*direction, t>=0.

Constructors

Ray Point3 Point3 

Instances

Instances details
Show Ray Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

showsPrec :: Int -> Ray -> ShowS #

show :: Ray -> String #

showList :: [Ray] -> ShowS #

Eq Ray Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Ray -> Ray -> Bool #

(/=) :: Ray -> Ray -> Bool #

Segment

data Segment Source #

Closed segment with two endpoints; zero length is valid.

Constructors

Segment PointND PointND 

Instances

Instances details
Show Segment Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Segment Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Segment -> Segment -> Bool #

(/=) :: Segment -> Segment -> Bool #

Plane

data Plane Source #

Plane normal dot x = offset, with a nonzero normal.

Constructors

Plane Point3 Double 

Instances

Instances details
Show Plane Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

showsPrec :: Int -> Plane -> ShowS #

show :: Plane -> String #

showList :: [Plane] -> ShowS #

Eq Plane Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Plane -> Plane -> Bool #

(/=) :: Plane -> Plane -> Bool #

Triangle

data Triangle Source #

Closed triangle; zero-area triangles are rejected by triangle operations.

Instances

Instances details
Show Triangle Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Triangle Source # 
Instance details

Defined in HMath.Geometry.Internal

Rectangle

data Rectangle Source #

Axis-aligned rectangle with ordered corners.

Constructors

Rectangle Point2 Point2 

Instances

Instances details
Show Rectangle Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Rectangle Source # 
Instance details

Defined in HMath.Geometry.Internal

Circle

data Circle Source #

Circle with nonnegative radius.

Constructors

Circle Point2 Double 

Instances

Instances details
Show Circle Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Circle Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Circle -> Circle -> Bool #

(/=) :: Circle -> Circle -> Bool #

Ellipse

data Ellipse Source #

Rotated ellipse: positive semiaxes, counterclockwise angle in radians.

Instances

Instances details
Show Ellipse Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Ellipse Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Ellipse -> Ellipse -> Bool #

(/=) :: Ellipse -> Ellipse -> Bool #

Polygon

newtype Polygon Source #

Simple polygon; vertices are implicitly closed and no duplicate endpoint is needed.

Constructors

Polygon [Point2] 

Instances

Instances details
Show Polygon Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Polygon Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Polygon -> Polygon -> Bool #

(/=) :: Polygon -> Polygon -> Bool #

Sphere

data Sphere Source #

Closed sphere, including a zero radius.

Constructors

Sphere Point3 Double 

Instances

Instances details
Show Sphere Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Sphere Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Sphere -> Sphere -> Bool #

(/=) :: Sphere -> Sphere -> Bool #

AABB

data AABB Source #

Ordered, closed axis-aligned bounds in 1..16 dimensions.

Constructors

AABB PointND PointND 

Instances

Instances details
Show AABB Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

showsPrec :: Int -> AABB -> ShowS #

show :: AABB -> String #

showList :: [AABB] -> ShowS #

Eq AABB Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: AABB -> AABB -> Bool #

(/=) :: AABB -> AABB -> Bool #

OBB

data OBB Source #

Oriented three-dimensional box: center, three orthonormal axes, half-extents.

Constructors

OBB Point3 [Point3] Point3 

Instances

Instances details
Show OBB Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

showsPrec :: Int -> OBB -> ShowS #

show :: OBB -> String #

showList :: [OBB] -> ShowS #

Eq OBB Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: OBB -> OBB -> Bool #

(/=) :: OBB -> OBB -> Bool #

Capsule

data Capsule Source #

Capsule around the closed axis segment.

Constructors

Capsule Point3 Point3 Double 

Instances

Instances details
Show Capsule Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Capsule Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Capsule -> Capsule -> Bool #

(/=) :: Capsule -> Capsule -> Bool #

Cylinder

data Cylinder Source #

Finite cylinder with endpoint centers and radius; endpoints must differ.

Instances

Instances details
Show Cylinder Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Cylinder Source # 
Instance details

Defined in HMath.Geometry.Internal

Cone

data Cone Source #

Finite cone with apex, base center, and radius; axis must be nonzero.

Constructors

Cone Point3 Point3 Double 

Instances

Instances details
Show Cone Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

showsPrec :: Int -> Cone -> ShowS #

show :: Cone -> String #

showList :: [Cone] -> ShowS #

Eq Cone Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Cone -> Cone -> Bool #

(/=) :: Cone -> Cone -> Bool #

Frustum

newtype Frustum Source #

Convex frustum represented by six inward half-spaces n dot x >= offset.

Constructors

Frustum [Plane] 

Instances

Instances details
Show Frustum Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Frustum Source # 
Instance details

Defined in HMath.Geometry.Internal

Methods

(==) :: Frustum -> Frustum -> Bool #

(/=) :: Frustum -> Frustum -> Bool #

Orientation

data Orientation Source #

Sign of an exact predicate on the input Double values.

Location

data Location Source #

Point position with boundary reported separately.

Constructors

Outside 
Boundary 
Inside 

Instances

Instances details
Show Location Source # 
Instance details

Defined in HMath.Geometry.Internal

Eq Location Source # 
Instance details

Defined in HMath.Geometry.Internal

Ord Location Source # 
Instance details

Defined in HMath.Geometry.Internal

finite

finite :: Double -> Bool Source #

Test whether a Double is neither NaN nor infinite. This alone does not impose the geometry coordinate magnitude cap.

require

require :: Bool -> String -> Either MathError () Source #

Given predicate then diagnostic text, return Right () if satisfied or Left (DomainError text).

coord

coord :: Double -> Bool Source #

Accept a finite geometry coordinate only when its absolute value is <=1e50, bounding downstream Double products.

coords2

coords2 :: Point2 -> [Double] Source #

Extract [x,y] from a Point2 without validation.

coords3

coords3 :: Point3 -> [Double] Source #

Extract [x,y,z] from a Point3 without validation.

coordsND

coordsND :: PointND -> [Double] Source #

Extract ordered coordinate list from a PointND without validation.

check2

check2 :: Point2 -> Either MathError () Source #

Validate both Point2 coordinates as finite with absolute magnitude <=1e50; invalid data returns DomainError.

check3

check3 :: Point3 -> Either MathError () Source #

Validate all Point3 coordinates as finite with absolute magnitude <=1e50; invalid data returns DomainError.

checkND

checkND :: PointND -> Either MathError () Source #

Require 1..16 coordinates, all finite and bounded by 1e50 in magnitude. Invalid PointND returns DomainError.

checkPair

checkPair :: PointND -> PointND -> Either MathError () Source #

Validate both ND points and require equal dimensions. Invalid coordinatesrankmismatch return DomainError.

checked

checked :: [Double] -> Either MathError [Double] Source #

Return the supplied list if every Double is finite, otherwise Left NonFiniteResult. This checks numerical results without the coordinate magnitude cap.

point2

point2 :: Double -> Double -> Either MathError Point2 Source #

Given x,y, construct Point2 after bounded finite-coordinate validation. Invalid values return DomainError.

point3

point3 :: Double -> Double -> Double -> Either MathError Point3 Source #

Given x,y,z, construct Point3 after bounded finite-coordinate validation. Invalid values return DomainError.

pointND

pointND :: [Double] -> Either MathError PointND Source #

Construct a checked ND point from 1..16 bounded finite coordinates. Invalid dimension/value returns DomainError.

dot

dot :: [Double] -> [Double] -> Double Source #

Unchecked sum of pairwise list products using zipWith; unequal lists truncate to the shorter length. Checked geometry callers must validate matching dimensions first.

norm

norm :: [Double] -> Double Source #

Return scaled Euclidean list norm to reduce intermediate overflow; empty/all-zero list yields zero. No finiteness check is added.

sub

sub :: [Double] -> [Double] -> [Double] Source #

Unchecked coordinatewise left-minus-right list subtraction, truncating to the shorter list on mismatch.

plus

plus :: [Double] -> [Double] -> [Double] Source #

Unchecked coordinatewise list addition, truncating to the shorter list on mismatch.

scale

scale :: Double -> [Double] -> [Double] Source #

Given Double scalar then coordinate list, return all coordinates multiplied by it without validation.

cross

cross :: Point3 -> Point3 -> Point3 Source #

Return right-handed cross product of two Point3 vectors. Coordinates/results are unchecked at this helper boundary.

add2

add2 :: Point2 -> Point2 -> Point2 Source #

Add Point2 coordinates componentwise without validation.

sub2

sub2 :: Point2 -> Point2 -> Point2 Source #

Subtract right Point2 coordinates from left, without validation.

scale2

scale2 :: Double -> Point2 -> Point2 Source #

Given scalar then Point2, scale both coordinates without validation.

cross2

cross2 :: Point2 -> Point2 -> Double Source #

Return 2D determinant ax*by-ay*bx as Double without validation.

dot2

dot2 :: Point2 -> Point2 -> Double Source #

Return 2D dot product ax*bx+ay*by without validation.

norm2

norm2 :: Point2 -> Double Source #

Return scaled Euclidean length of a Point2 without checked finite validation.

from3

from3 :: [Double] -> Point3 Source #

Convert a list of exactly three Doubles to Point3; all other lengths return origin P3 0 0 0. This helper does not validate finite coordinates.

edges

edges :: [a] -> [(a, a)] Source #

Pair each polygon-list element with its cyclic successor, including the last-to-first edge. Empty list returns []; singleton returns one self-pair.

orientExact

orientExact :: Point2 -> Point2 -> Point2 -> Rational Source #

Given finite points a,b,c, compute exact Rational determinant of their represented Double coordinates. Positive is counterclockwise, zero collinear; non-finite inputs violate this unchecked helper's precondition.

orient

orient :: Point2 -> Point2 -> Point2 -> Ordering Source #

Compare orientExact determinant with zero, returning GT for counterclockwise, EQ for collinear, LT for clockwise. Inputs must already be finite.

onSegment

onSegment :: Point2 -> Point2 -> Point2 -> Bool Source #

Given endpoints a,b then point p, test exact collinearity and inclusive coordinate bounds. Finite input validation belongs to the checked caller.

checkPolygon

checkPolygon :: Polygon -> Either MathError [Point2] Source #

Validate a simple polygon with 3..256 bounded finite vertices, no adjacent duplicates, nonzero area and no nonadjacent edge intersection. Return validated vertices or DomainError.

signedArea

signedArea :: [Point2] -> Double Source #

Return oriented shoelace area using exact Rational intermediate arithmetic on finite Double coordinates. Positive means counterclockwise. This helper does not validate polygon simplicity.

ccw

ccw :: [Point2] -> [Point2] Source #

Return polygon vertices in counterclockwise order by reversing negative signed area; zero-area input remains unchanged. Validation is the caller's responsibility.

locateUnchecked

locateUnchecked :: [Point2] -> Point2 -> Location Source #

Given valid simple polygon vertices then finite Point2, return Boundary for an edge point, otherwise Inside/Outside by ray parity. This helper performs no constructor validation.

firstOr

firstOr :: a -> [a] -> a Source #

Given fallback then list, return its first element or the fallback for empty input. Example: firstOr 0 [] == 0.