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
Cartesian two-dimensional point, also used for vectors.
Point3
Cartesian right-handed three-dimensional point/vector.
PointND
A point of dimension 1..16.
Line
Parametric line origin+t*direction; direction must be nonzero.
Ray
Parametric ray origin+t*direction, t>=0.
Segment
Closed segment with two endpoints; zero length is valid.
Instances
Plane
Plane normal dot x = offset, with a nonzero normal.
Triangle
Closed triangle; zero-area triangles are rejected by triangle operations.
Rectangle
Axis-aligned rectangle with ordered corners.
Circle
Circle with nonnegative radius.
Ellipse
Rotated ellipse: positive semiaxes, counterclockwise angle in radians.
Instances
Polygon
Simple polygon; vertices are implicitly closed and no duplicate endpoint is needed.
Instances
Sphere
Closed sphere, including a zero radius.
AABB
Ordered, closed axis-aligned bounds in 1..16 dimensions.
OBB
Oriented three-dimensional box: center, three orthonormal axes, half-extents.
Capsule
Capsule around the closed axis segment.
Instances
Cylinder
Finite cylinder with endpoint centers and radius; endpoints must differ.
Cone
Finite cone with apex, base center, and radius; axis must be nonzero.
Frustum
Convex frustum represented by six inward half-spaces n dot x >= offset.
Instances
Orientation
data Orientation Source #
Sign of an exact predicate on the input Double values.
Constructors
| Clockwise | |
| Collinear | |
| Counterclockwise |
Instances
| Show Orientation Source # | |
Defined in HMath.Geometry.Internal Methods showsPrec :: Int -> Orientation -> ShowS # show :: Orientation -> String # showList :: [Orientation] -> ShowS # | |
| Eq Orientation Source # | |
Defined in HMath.Geometry.Internal | |
| Ord Orientation Source # | |
Defined in HMath.Geometry.Internal Methods compare :: Orientation -> Orientation -> Ordering # (<) :: Orientation -> Orientation -> Bool # (<=) :: Orientation -> Orientation -> Bool # (>) :: Orientation -> Orientation -> Bool # (>=) :: Orientation -> Orientation -> Bool # max :: Orientation -> Orientation -> Orientation # min :: Orientation -> Orientation -> Orientation # | |
Location
Point position with boundary reported separately.
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.
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.