-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Coordinate systems -- -- Coordinate systems @package Cartesian @version 0.1.0.1 module Cartesian.Plane.Utilities -- | Applies a function to each component in a vector dotmap :: (a -> b) -> Complex a -> Complex b dotwise :: (a -> a -> b) -> Complex a -> Complex a -> Complex b -- | Negates the real component (X) flipx :: Complex Double -> Complex Double -- | Negates the imaginary component (Y) flipy :: Complex Double -> Complex Double -- | Creates a number on the real line (where the imaginary part is 0) real :: Double -> Complex Double -- | Creates a number on the imaginary line (where the real part is 0) imag :: Double -> Complex Double -- | Vector and coordinate system utilities. module Cartesian.Space data Vector num Vector :: num -> num -> num -> Vector num data Line num Line :: (Vector num) -> (Vector num) -> Line num -- | Why the hell did I write this useless function? vector :: Num a => a -> a -> a -> Vector a -- | 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 argument (Vector 0 0 0) = -- 0 argument (Vector x y z) = atan $ y/x -- -- Vector -> (magnitude, argument) polar :: (Floating a, Eq a) => -- Vector a -> (a, a) polar v@(Vector x y) = (magnitude v, argument v) -- -- Intersect TODO: Math notes, MathJax or LaTex TODO: Intersect for -- curves (functions) and single points (?) TODO: Polymorphic, typeclass -- (lines, shapes, ranges, etc.) (?) intersect :: Num a => Line a -> Line a -> Maybe (Vector a) intersects :: Num a => Line a -> Line a -> 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). The -- Z-component is ignored. Fails for vertical and horizontal lines. -- -- TODO: Use Maybe (?) coefficients :: (Fractional a, Eq a) => Line a -> Maybe (a, a) instance (GHC.Float.Floating a, GHC.Classes.Eq a) => GHC.Num.Num (Cartesian.Space.Vector a) 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.BoundingBox.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.Plane.BoundingBox -- | TODO: Better name (?) TODO: Don't make assumptions about WHICH corners -- they are (✓) fromCorners :: RealFloat f => Complex f -> Complex f -> BoundingBox f -- | Creates a bounding box from a topleft and size vector. fromCornerAndSize :: RealFloat f => Complex f -> Complex f -> BoundingBox f -- | Top Left Bottom Right fromSides :: RealFloat f => f -> f -> f -> f -> BoundingBox f intersect :: (RealFloat f, Ord f) => BoundingBox f -> BoundingBox f -> Maybe (BoundingBox f) 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) module Cartesian.Lenses size :: Lens' (BoundingBox f_a79V) (Complex f_a79V) centre :: Lens' (BoundingBox f_a79V) (Complex f_a79V)