-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Coordinate systems -- -- Coordinate systems @package Cartesian @version 0.2.0.0 module Cartesian.Plane.Types -- | TODO: Anchors (eg. C, N, S, E W and combinations thereof, perhaps -- represented as relative Vectors) data BoundingBox f BoundingBox :: Complex f -> Complex f -> BoundingBox f [_centre] :: BoundingBox f -> Complex f [_size] :: BoundingBox f -> Complex f instance GHC.Show.Show f => GHC.Show.Show (Cartesian.Plane.Types.BoundingBox f) module Cartesian.Plane.Lenses -- | TODO: Make sure invariants remain true (eg. left < right) TODO: -- Make coordinate-system independent (eg. direction of axes) makeBoundingBoxSideLens :: RealFloat f => (BoundingBox f -> f) -> (BoundingBox f -> f -> (f, f, f, f)) -> Lens (BoundingBox f) (BoundingBox f) f f centre :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) (Complex f) (Complex f) size :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) (Complex f) (Complex f) left :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f right :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f top :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f bottom :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f leftpad :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f rightpad :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f toppad :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f bottompad :: RealFloat f => Lens (BoundingBox f) (BoundingBox f) f f module Cartesian.Types module Cartesian.Space.Types data Vector3D f Vector3D :: f -> f -> f -> Vector3D f data Line f Line :: (Vector3D f) -> (Vector3D f) -> Line f -- | data BoundingBox f = BoundingBox { _centre :: Vector f, _size :: -- Vector f } -- -- TODO: Refactor. A lot. instance Cartesian.Internal.Types.Vector Cartesian.Space.Types.Vector3D instance (GHC.Float.Floating v, GHC.Classes.Eq v) => GHC.Num.Num (Cartesian.Space.Types.Vector3D v) instance Cartesian.Internal.Types.HasX (Cartesian.Space.Types.Vector3D f) f instance Cartesian.Internal.Types.HasY (Cartesian.Space.Types.Vector3D f) f instance Cartesian.Internal.Types.HasZ (Cartesian.Space.Types.Vector3D f) f module Cartesian.Space.Lenses -- | Vector and coordinate system utilities. module Cartesian.Space module Cartesian.Plane -- | TODO: Rename (?) data Vector num Vector :: num -> num -> Vector num data Line num Line :: (Vector num) -> (Vector num) -> Line num -- | TODO: Rename (eg. Shape) (?) type Polygon num = [Vector num] data Linear num Linear :: num -> num -> Linear num [intercept] :: Linear num -> num [slope] :: Linear num -> num -- | type Domain -- -- Determines if a point lies within a polygon using the odd-even method. -- -- TODO: Use epsilon (?) TODO: How to treat points that lie on an edge inside :: Num n => Polygon n -> Vector n -> Bool -- | abs v * signum v == v -- | Performs component-wise operations dotwise :: (a -> b -> c) -> Vector a -> Vector b -> Vector c -- | Dot product of two vectors dot :: Floating a => Vector a -> Vector a -> a -- | Euclidean distance between two points euclidean :: Floating a => Vector a -> Vector a -> a magnitude :: (Floating a, Eq a) => Vector a -> a mag :: (Floating a, Eq a) => Vector a -> a -- | Angle (in radians) between the positive X-axis and the vector argument :: (Floating a, Eq a) => Vector a -> a arg :: (Floating a, Eq a) => Vector a -> a -- | Vector -> (magnitude, argument) polar :: (Floating a, Eq a) => Vector a -> (a, a) -- | Yields the point at which two finite lines intersect. The lines are -- defined inclusively by their endpoints. The result is wrapped in a -- Maybe value to account for non-intersecting lines. -- -- TODO: Move equation solving to separate function (two linear -- functions) TODO: Simplify logic by considering f(x) = y for vertical -- lines (?) TODO: Return Either instead of Maybe (eg. Left "parallel") -- (?) -- -- TODO: Math notes, MathJax or LaTex TODO: Intersect for curves -- (functions) and single points (?) TODO: Polymorphic, typeclass (lines, -- shapes, ranges, etc.) (?) intersect :: RealFrac n => Line n -> Line n -> Maybe (Vector n) -- | inside :: (Num n, Ord n) => Triangle n -> Point n -> Bool -- inside _ _ = False intersects :: RealFrac r => Line r -> Line r -> Bool -- | Yields the overlap of two closed intervals (n ∈ R) TODO: Normalise -- intervals (eg. (12, 5) -> (5, 12)) overlap :: Real a => (a, a) -> (a, a) -> Maybe (a, a) -- | TODO: Intersect Rectangles -- -- Coefficients for the linear function of a Line (slope, intercept). -- Fails for vertical and horizontal lines. -- -- TODO: Use Maybe (?) TODO: Rename (eg. toLinear, function) (?) coefficients :: (Fractional a, Eq a) => Line a -> Maybe (a, a) -- | Solves a linear equation for x (f(x) = g(x)) TODO: Use Epsilon (?) solve :: (Fractional n, Eq n) => Linear n -> Linear n -> Maybe n instance GHC.Show.Show num => GHC.Show.Show (Cartesian.Plane.Vector num) instance GHC.Classes.Eq num => GHC.Classes.Eq (Cartesian.Plane.Vector num) instance (GHC.Float.Floating a, GHC.Classes.Eq a) => GHC.Num.Num (Cartesian.Plane.Vector a)