ianmackenzie / elm-geometry-test / Geometry.Expect

This module contains functions that construct Expectations for elm-geometry types. In general, all expectations use an absolute-or-relative tolerance of 1e-12 meters; for example,

actualPoint |> Expect.point2d expectedPoint

will pass if the distance from actualPoint to expectedPoint is less than 1e-12 meters or if it is less than 1e-12 times the distance of actualPoint from the origin (so that a larger absolute tolerance is used for points far from the origin).

This module has been designed so that in most cases you can use

import Geometry.Expect as Expect

to 'merge' it with the Expect module from elm-explorations/test, without running into any naming conflicts; examples in this module assume the module has been imported this way.

Generic helpers

exactly : Basics.Float -> Basics.Float -> Expectation

Check if one Float value is exactly equal to another.

Note that this is usually only desirable in low-level numeric code and most tests should use Expect.float.

just : (actual -> Expectation) -> Maybe actual -> Expectation

Check if a Maybe value is of the form Just x and x satisfies the given expectation function. For example, since Vector2d.direction returns a Maybe Direction2d, you might test it like

Vector2d.meters 2 2
    |> Vector2d.direction
    |> Expect.just
        (Expect.direction2d (Direction2d.degrees 45))

Note that if you want to verify that a function returns Nothing, you can simply use Expect.equal:

Vector2d.meters 0 0
    |> Vector2d.direction
    |> Expect.equal Nothing

list : (a -> b -> Expectation) -> List a -> List b -> Expectation

Apply a given expectation function to successive pairs of items from two given lists, failing if any one of those expectations fails or if the two lists have different lengths.

Quantity equality

quantity : Quantity Basics.Float units -> Quantity Basics.Float units -> Expectation

Check that one Quantity value is approximately equal to another.

quantityWithin : Quantity Basics.Float units -> Quantity Basics.Float units -> Quantity Basics.Float units -> Expectation

Check that some Quantity value is equal to another within a specified absolute tolerance:

actualValue
    |> Expect.quantityWithin givenTolerance
        expectedValue

-- Passes:
Length.meters 1.05
    |> Expect.quantityWithin (Length.centimeters 10)
        (Length.meters 1)

-- Fails:
Length.meters 1.05
    |> Expect.quantityWithin (Length.centimeters 1)
        (Length.meters 1)

angle : Angle -> Angle -> Expectation

Check that one Angle is approximately equal to another.

Note that this will consider angles in the geometric sense, not the numerical sense; 0 degrees, 360 degrees, 720 degrees and -360 degrees are all considered to be equal. However, since Angle values are also Quantity values, you can use Expect.quantity if you do want a pure numerical comparison.

angleWithin : Angle -> Angle -> Angle -> Expectation

Check if two angles are equal within a given tolerance. Note that as with angle, this will properly handle angles that 'wrap around':

-- Passes because geometrically speaking, there's only
-- a 4 degree difference between 358 degrees and 2
-- degrees:
Angle.degrees 358
    |> Expect.angleWithin (Angle.degrees 5)
        (Angle.degrees 2)

Quantity comparison

These functions all behave just like the corresponding ones in elm-explorations/test. Unlike most other functions in this module, they do not implicitly include a tolerance.

quantityAtLeast : Quantity Basics.Float units -> Quantity Basics.Float units -> Expectation

quantityAtMost : Quantity Basics.Float units -> Quantity Basics.Float units -> Expectation

quantityGreaterThan : Quantity Basics.Float units -> Quantity Basics.Float units -> Expectation

quantityLessThan : Quantity Basics.Float units -> Quantity Basics.Float units -> Expectation

Intervals

quantityContainedIn : Quantity.Interval.Interval Basics.Float units -> Quantity Basics.Float units -> Expectation

Check whether a given quantity is contained within a given interval, within the default tolerance of 1e-12 units. (That is, a quantity just outside the interval will still be considered contained in the interval.)

Points

point2d : Point2d units coordinates -> Point2d units coordinates -> Expectation

Check that two Point2d values are approximately equal.

point2dWithin : Quantity Basics.Float units -> Point2d units coordinates -> Point2d units coordinates -> Expectation

Check that two Point2d values are equal to within the given tolerance (the distance between the two points is less than that tolerance).

point2dContainedIn : BoundingBox2d units coordinates -> Point2d units coordinates -> Expectation

Check that a Point2d is approximately contained in a given BoundingBox2d.

point3d : Point3d units coordinates -> Point3d units coordinates -> Expectation

Check that two Point3d values are approximately equal.

point3dWithin : Quantity Basics.Float units -> Point3d units coordinates -> Point3d units coordinates -> Expectation

Check that two Point3d values are equal to within the given tolerance (the distance between the two points is less than that tolerance).

point3dContainedIn : BoundingBox3d units coordinates -> Point3d units coordinates -> Expectation

Check that a Point3d is approximately contained in a given BoundingBox3d.

Vectors

vector2d : Vector2d units coordinates -> Vector2d units coordinates -> Expectation

Check that two Vector2d values are approximately equal.

vector2dWithin : Quantity Basics.Float units -> Vector2d units coordinates -> Vector2d units coordinates -> Expectation

Check that two Vector2d values are equal to within the given tolerance (the difference between the two vectors has magnitude less than that tolerance).

vector2dContainedIn : VectorBoundingBox2d units coordinates -> Vector2d units coordinates -> Expectation

Check that a Vector2d is approximately contained in a given VectorBoundingBox2d.

vector3d : Vector3d units coordinates -> Vector3d units coordinates -> Expectation

Check that two Vector3d values are approximately equal.

vector3dWithin : Quantity Basics.Float units -> Vector3d units coordinates -> Vector3d units coordinates -> Expectation

Check that two Vector3d values are equal to within the given tolerance (the difference between the two vectors has magnitude less than that tolerance).

vector3dContainedIn : VectorBoundingBox3d units coordinates -> Vector3d units coordinates -> Expectation

Check that a Vector3d is approximately contained in a given VectorBoundingBox3d.

Directions

direction2d : Direction2d coordinates -> Direction2d coordinates -> Expectation

Check that two Direction2d values are approximately equal.

direction2dWithin : Angle -> Direction2d coordinates -> Direction2d coordinates -> Expectation

Check that two Direction2d values are equal to within the given angular tolerance.

direction2dPerpendicularTo : Direction2d coordinates -> Direction2d coordinates -> Expectation

Check that one Direction2d is approximately perpendicular to another.

direction3d : Direction3d coordinates -> Direction3d coordinates -> Expectation

Check that two Direction3d values are approximately equal.

direction3dWithin : Angle -> Direction3d coordinates -> Direction3d coordinates -> Expectation

Check that two Direction3d values are equal to within the given angular tolerance.

direction3dPerpendicularTo : Direction3d coordinates -> Direction3d coordinates -> Expectation

Check that one Direction3d is approximately perpendicular to another.

Bounding boxes

boundingBox2d : BoundingBox2d units coordinates -> BoundingBox2d units coordinates -> Expectation

Check that two BoundingBox2d values are approximately equal (have the same min/max values).

boundingBox2dWithin : Quantity Basics.Float units -> BoundingBox2d units coordinates -> BoundingBox2d units coordinates -> Expectation

Check that two BoundingBox2d values are equal within the given tolerance (every min/max value of the first box is equal, to within the given tolerance, of the corresponding min/max value of the second box).

boundingBox3d : BoundingBox3d units coordinates -> BoundingBox3d units coordinates -> Expectation

Check that two BoundingBox3d values are approximately equal (have the same min/max values).

boundingBox3dWithin : Quantity Basics.Float units -> BoundingBox3d units coordinates -> BoundingBox3d units coordinates -> Expectation

Check that two BoundingBox3d values are equal within the given tolerance (every min/max value of the first box is equal, to within the given tolerance, of the corresponding min/max value of the second box).

Simple geometry

lineSegment2d : LineSegment2d units coordinates -> LineSegment2d units coordinates -> Expectation

Check that two LineSegment2d values are approximately equal (have the same endpoints).

lineSegment2dWithin : Quantity Basics.Float units -> LineSegment2d units coordinates -> LineSegment2d units coordinates -> Expectation

Check that two LineSegment2d values are equal within the given tolerance (the endpoints of one are equal to the endpoints of the other, within the given tolerance).

lineSegment3d : LineSegment3d units coordinates -> LineSegment3d units coordinates -> Expectation

Check that two LineSegment3d values are approximately equal (have the same endpoints).

lineSegment3dWithin : Quantity Basics.Float units -> LineSegment3d units coordinates -> LineSegment3d units coordinates -> Expectation

Check that two LineSegment3d values are equal within the given tolerance (the endpoints of one are equal to the endpoints of the other, within the given tolerance).

triangle2d : Triangle2d units coordinates -> Triangle2d units coordinates -> Expectation

Check that two Triangle2d values are approximately equal (have the same vertices).

triangle2dWithin : Quantity Basics.Float units -> Triangle2d units coordinates -> Triangle2d units coordinates -> Expectation

Check that two Triangle2d values are equal within the given tolerance (each vertex of the first triangle is equal to the corresponding vertex of the second triangle, within the given tolerance).

triangle3d : Triangle3d units coordinates -> Triangle3d units coordinates -> Expectation

Check that two Triangle3d values are approximately equal (have the same vertices).

triangle3dWithin : Quantity Basics.Float units -> Triangle3d units coordinates -> Triangle3d units coordinates -> Expectation

Check that two Triangle3d values are equal within the given tolerance (each vertex of the first triangle is equal to the corresponding vertex of the second triangle, within the given tolerance).

polyline2d : Polyline2d units coordinates -> Polyline2d units coordinates -> Expectation

Check that two Polyline2d values are approximately equal (have the same vertices).

polyline2dWithin : Quantity Basics.Float units -> Polyline2d units coordinates -> Polyline2d units coordinates -> Expectation

Check that two Polyline2d values are equal within the given tolerance (have the same number of vertices, and each vertex of the first polyline is equal to the corresponding vertex of the second polyline within the given tolerance).

polyline3d : Polyline3d units coordinates -> Polyline3d units coordinates -> Expectation

Check that two Polyline3d values are approximately equal (have the same vertices).

polyline3dWithin : Quantity Basics.Float units -> Polyline3d units coordinates -> Polyline3d units coordinates -> Expectation

Check that two Polyline3d values are equal within the given tolerance (have the same number of vertices, and each vertex of the first polyline is equal to the corresponding vertex of the second polyline within the given tolerance).

polygon2d : Polygon2d units coordinates -> Polygon2d units coordinates -> Expectation

Check that two Polygon2d values are approximately equal (have the same vertices).

polygon2dWithin : Quantity Basics.Float units -> Polygon2d units coordinates -> Polygon2d units coordinates -> Expectation

Check that two Polygon2d values are equal within the given tolerance (have the same number of vertices, and each vertex of the first polygon is equal to the corresponding vertex of the second polygon within the given tolerance).

Complex geometry

arc2d : Arc2d units coordinates -> Arc2d units coordinates -> Expectation

Check that two Arc2d values are approximately equal (have the same start point, end point and swept angle).

arc3d : Arc3d units coordinates -> Arc3d units coordinates -> Expectation

Check that two Arc3d values are approximately equal (have the same start point, end point, swept angle and axial direction).

circle2d : Circle2d units coordinates -> Circle2d units coordinates -> Expectation

Check that two Circle2d values are approximately equal (have the same center point and radius).

circle3d : Circle3d units coordinates -> Circle3d units coordinates -> Expectation

Check that two Circle3d values are approximately equal (have the same center point, axial direction and radius).

cubicSpline2d : CubicSpline2d units coordinates -> CubicSpline2d units coordinates -> Expectation

Check that two CubicSpline2d values are approximately equal (have the same control points).

cubicSpline3d : CubicSpline3d units coordinates -> CubicSpline3d units coordinates -> Expectation

Check that two CubicSpline3d values are approximately equal (have the same control points).

cylinder3d : Cylinder3d units coordinates -> Cylinder3d units coordinates -> Expectation

Check that two Cylinder3d values are approximately equal (have the same center point, axial direction, radius and length).

cone3d : Cone3d units coordinates -> Cone3d units coordinates -> Expectation

Check that two Cone3d values are approximately equal (have the same center point, axial direction, radius and length).

quadraticSpline2d : QuadraticSpline2d units coordinates -> QuadraticSpline2d units coordinates -> Expectation

Check that two QuadraticSpline2d values are approximately equal (have the same control points).

quadraticSpline3d : QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates -> Expectation

Check that two QuadraticSpline3d values are approximately equal (have the same control points).

sphere3d : Sphere3d units coordinates -> Sphere3d units coordinates -> Expectation

Check that two Sphere3d values are approximately equal (have the same center point and radius).

Datums

axis2d : Axis2d units coordinates -> Axis2d units coordinates -> Expectation

Check that two Axis2d values are approximately equal (have the same origin point and direction).

axis3d : Axis3d units coordinates -> Axis3d units coordinates -> Expectation

Check that two Axis3d values are approximately equal (have the same origin point and direction).

frame2d : Frame2d units coordinates defines -> Frame2d units coordinates defines -> Expectation

Check that two Frame2d values are approximately equal (have the same origin point and X/Y directions).

frame3d : Frame3d units coordinates defines -> Frame3d units coordinates defines -> Expectation

Check that two Frame3d values are approximately equal (have the same origin point and X/Y/Z directions).

plane3d : Plane3d units coordinates -> Plane3d units coordinates -> Expectation

Check that two Plane3d values are approximately equal (have the same origin point and normal direction).

sketchPlane3d : SketchPlane3d units coordinates defines -> SketchPlane3d units coordinates defines -> Expectation

Check that two SketchPlane3d values are approximately equal (have the same origin point and X/Y directions).

Advanced

These functions check for things like "directions have length 1", "bounding box min and max values are in the correct order", and "frame basis directions are mutually perpendicular". Since these properties are generally guaranteed by elm-geometry, it should only be necessary to use these expectation functions if you have some low-level code that calls functions such as Direction2d.unsafe or Frame3d.unsafe.

validDirection2d : Direction2d coordinates -> Expectation

validDirection3d : Direction3d coordinates -> Expectation

validBoundingBox2d : BoundingBox2d units coordinates -> Expectation

validBoundingBox3d : BoundingBox3d units coordinates -> Expectation

validFrame2d : Frame2d units coordinates defines -> Expectation

validFrame3d : Frame3d units coordinates defines -> Expectation

validSketchPlane3d : SketchPlane3d units coordinates defines -> Expectation