Portability | GHC |
---|---|
Stability | highly unstable |
Maintainer | Stephen Tetley <stephen.tetley@gmail.com> |
Base geometric types and operations.
- quarter_pi :: Floating u => u
- half_pi :: Floating u => u
- two_pi :: Floating u => u
- data Matrix2'2 u = M2'2 !u !u !u !u
- type DMatrix2'2 = Matrix2'2 Double
- identity2'2 :: Num u => Matrix2'2 u
- det2'2 :: Num u => Matrix2'2 u -> u
- transpose2'2 :: Matrix2'2 u -> Matrix2'2 u
- data LineEquation u = LineEquation {
- line_eqn_A :: !u
- line_eqn_B :: !u
- line_eqn_C :: !u
- type DLineEquation = LineEquation Double
- lineEquation :: Num u => Point2 u -> Point2 u -> LineEquation u
- pointViaX :: Fractional u => u -> LineEquation u -> Point2 u
- pointViaY :: Fractional u => u -> LineEquation u -> Point2 u
- pointLineDistance :: Floating u => Point2 u -> LineEquation u -> u
- data LineSegment u = LineSegment (Point2 u) (Point2 u)
- type DLineSegment = LineSegment Double
- rectangleLineSegments :: Num u => u -> u -> Point2 u -> [LineSegment u]
- polygonLineSegments :: [Point2 u] -> [LineSegment u]
- data BezierCurve u = BezierCurve !(Point2 u) !(Point2 u) !(Point2 u) !(Point2 u)
- type DBezierCurve = BezierCurve Double
- bezierLength :: (Floating u, Ord u, Tolerance u) => BezierCurve u -> u
- subdivide :: Fractional u => BezierCurve u -> (BezierCurve u, BezierCurve u)
- subdividet :: Real u => u -> BezierCurve u -> (BezierCurve u, BezierCurve u)
- bezierArcPoints :: Floating u => Radian -> u -> Radian -> Point2 u -> [Point2 u]
- bezierMinorArc :: Floating u => Radian -> u -> Radian -> Point2 u -> BezierCurve u
- affineComb :: Real u => u -> Point2 u -> Point2 u -> Point2 u
- midpoint :: Fractional u => Point2 u -> Point2 u -> Point2 u
- lineAngle :: (Floating u, Real u) => Point2 u -> Point2 u -> Radian
constants
quarter_pi :: Floating u => uSource
2x2 Matrix
2x2 matrix, considered to be in row-major form.
(M2'2 a b c d)
M2'2 !u !u !u !u |
type DMatrix2'2 = Matrix2'2 DoubleSource
identity2'2 :: Num u => Matrix2'2 uSource
Construct the identity 2x2 matrix:
(M2'2 1 0 0 1 )
transpose2'2 :: Matrix2'2 u -> Matrix2'2 uSource
Transpose a 2x2 matrix.
Line in equational form
data LineEquation u Source
Line in equational form, i.e. Ax + By + C = 0
.
LineEquation | |
|
Eq u => Eq (LineEquation u) | |
Show u => Show (LineEquation u) |
lineEquation :: Num u => Point2 u -> Point2 u -> LineEquation uSource
lineEquation
: point1 * point2 -> LineEquation
Construct a line in equational form bisecting the supplied points.
pointViaX :: Fractional u => u -> LineEquation u -> Point2 uSource
pointViaX
: x * line_equation -> Point
Calculate the point on the line for the supplied x
value.
pointViaY :: Fractional u => u -> LineEquation u -> Point2 uSource
pointViaY
: y * line_equation -> Point
Calculate the point on the line for the supplied y
value.
pointLineDistance :: Floating u => Point2 u -> LineEquation u -> uSource
pointLineDistance
: point -> line -> Distance
Find the distance from a point to a line in equational form using this formula:
P(u,v) L: Ax + By + C = 0 (A*u) + (B*v) + C ----------------- sqrt $ (A^2) +(B^2)
A positive distance indicates the point is above the line, negative indicates below.
Line segment
data LineSegment u Source
LineSegment (Point2 u) (Point2 u) |
(Ord u, Tolerance u) => Eq (LineSegment u) | |
(Ord u, Tolerance u) => Ord (LineSegment u) | |
Show u => Show (LineSegment u) |
type DLineSegment = LineSegment DoubleSource
rectangleLineSegments :: Num u => u -> u -> Point2 u -> [LineSegment u]Source
rectangleLineSegments
: half_width * half_height -> [LineSegment]
Compute the line segments of a rectangle.
polygonLineSegments :: [Point2 u] -> [LineSegment u]Source
polygonLineSegments
: [point] -> [LineSegment]
Build the line segments of a polygon fome a list of its vertices.
Cubic Bezier curves
data BezierCurve u Source
A Strict cubic Bezier curve.
BezierCurve !(Point2 u) !(Point2 u) !(Point2 u) !(Point2 u) |
(Ord u, Tolerance u) => Eq (BezierCurve u) | |
(Ord u, Tolerance u) => Ord (BezierCurve u) | |
Show u => Show (BezierCurve u) |
type DBezierCurve = BezierCurve DoubleSource
bezierLength :: (Floating u, Ord u, Tolerance u) => BezierCurve u -> uSource
bezierLength
: start_point * control_1 * control_2 *
end_point -> Length
Find the length of a Bezier curve. The result is an approximation, with the tolerance is 0.1 of a point. This seems good enough for drawing (potentially the tolerance could be larger still).
The result is found through repeated subdivision so the calculation is potentially costly.
subdivide :: Fractional u => BezierCurve u -> (BezierCurve u, BezierCurve u)Source
Curve subdivision via de Casteljau's algorithm.
subdividet :: Real u => u -> BezierCurve u -> (BezierCurve u, BezierCurve u)Source
subdivide with an affine weight along the line...
bezierArcPoints :: Floating u => Radian -> u -> Radian -> Point2 u -> [Point2 u]Source
bezierArcPoints
: apex_angle * radius * rotation * center -> [Point]
ang should be in the range 0 < ang < 360deg.
if 0 < ang <= 90 returns 4 points if 90 < ang <= 180 returns 7 points if 180 < ang <= 270 returns 10 points if 270 < ang < 360 returns 13 points
bezierMinorArc :: Floating u => Radian -> u -> Radian -> Point2 u -> BezierCurve uSource
bezierMinorArc
: apex_angle * radius * rotation * center -> BezierCurve
ang should be in the range 0 < ang <= 90deg.