hgeometry 0.1.0.0 → 0.1.1.0
raw patch · 4 files changed
+40/−17 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Data.Geometry.Line: inRange :: Ord a => a -> (a, a) -> Bool
+ Data.Geometry.Point: l22dist :: Num a => Point2' a -> Point2' a -> a
- Data.Geometry.Circle: inCircle :: (Ord a, Floating a) => Point2' a -> Circle2' a -> Bool
+ Data.Geometry.Circle: inCircle :: (Ord a, Num a) => Point2' a -> Circle2' a -> Bool
- Data.Geometry.Circle: inDisc :: (Floating a, Ord a) => Point2' a -> Disc2' a -> Bool
+ Data.Geometry.Circle: inDisc :: (Num a, Ord a) => Point2' a -> Disc2' a -> Bool
- Data.Geometry.Circle: insideCircle :: (Floating a, Ord a) => Point2' a -> Circle2' a -> Bool
+ Data.Geometry.Circle: insideCircle :: (Num a, Ord a) => Point2' a -> Circle2' a -> Bool
- Data.Geometry.Circle: insideDisc :: (Floating a, Ord a) => Point2' a -> Disc2' a -> Bool
+ Data.Geometry.Circle: insideDisc :: (Num a, Ord a) => Point2' a -> Disc2' a -> Bool
- Data.Geometry.Circle: onCircle :: (Eq a, Floating a) => Point2' a -> Circle2' a -> Bool
+ Data.Geometry.Circle: onCircle :: (Eq a, Num a) => Point2' a -> Circle2' a -> Bool
- Data.Geometry.Line: onLineSegment :: (Eq a, Floating a) => Point2' a -> LineSegment2' a -> Bool
+ Data.Geometry.Line: onLineSegment :: (Ord a, Fractional a) => Point2' a -> LineSegment2' a -> Bool
Files
- hgeometry.cabal +5/−2
- src/Data/Geometry/Circle.hs +13/−7
- src/Data/Geometry/Line.hs +17/−6
- src/Data/Geometry/Point.hs +5/−2
hgeometry.cabal view
@@ -11,13 +11,13 @@ -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.1.0.0+version: 0.1.1.0 -- A short (one-line) description of the package. synopsis: Geometry types in Haskell -- A longer description of the package.-description: Several basic geometry geometry types and functions on these types.+description: Several basic geometry types and functions on these types. -- The license under which the package is released. license: BSD3@@ -41,6 +41,9 @@ -- Constraint on the version of Cabal needed to build this package. cabal-version: >=1.8++-- -- Specify where we can find the source code+-- Hs-source-dirs: src library -- Specify where we can find the source code
src/Data/Geometry/Circle.hs view
@@ -68,22 +68,28 @@ -------------------------------------------------------------------------------- -- | Checking if points lie in or on a circle/disc ++-- | Squared distance to the center+l22ToCenter :: Num a => Point2' a -> Circle2' a -> a+l22ToCenter p (Circle2 q _) = l22dist p q+ -- | whether or not p lies in OR on the circle c-inCircle :: (Ord a, Floating a) => Point2' a -> Circle2' a -> Bool-p `inCircle` c = distanceToCenter p c <= radius c+inCircle :: (Ord a, Num a) => Point2' a -> Circle2' a -> Bool+p `inCircle` c = l22ToCenter p c <= (radius c)^2 -- | whether or not p lies strictly inside the circle c-insideCircle :: (Floating a, Ord a) => Point2' a -> Circle2' a -> Bool-p `insideCircle` c = distanceToCenter p c < radius c+insideCircle :: (Num a, Ord a) => Point2' a -> Circle2' a -> Bool+p `insideCircle` c = l22ToCenter p c < (radius c)^2 -- | whether or not p lies on the circle-onCircle :: (Eq a, Floating a) => Point2' a -> Circle2' a -> Bool-p `onCircle` c = distanceToCenter p c == radius c+onCircle :: (Eq a, Num a) => Point2' a -> Circle2' a -> Bool+p `onCircle` c = l22ToCenter p c == (radius c)^2 -- | whether or not a point lies in a disc: this includes its border-inDisc :: (Floating a, Ord a) => Point2' a -> Disc2' a -> Bool+inDisc :: (Num a, Ord a) => Point2' a -> Disc2' a -> Bool p `inDisc` (Disc2 c) = p `inCircle` c -- | whether or not a point lies strictly inside a disc.+insideDisc :: (Num a, Ord a) => Point2' a -> Disc2' a -> Bool p `insideDisc` (Disc2 c) = p `insideCircle` c
src/Data/Geometry/Line.hs view
@@ -91,12 +91,24 @@ linear :: Num a => a -> a -> a -> a linear t x y = (1-t)*x + t*y -onLineSegment :: (Eq a, Floating a) => Point2' a -> LineSegment2' a -> Bool-p `onLineSegment` l@(LineSegment2 s t) = p == pointAt lambda l+inRange :: Ord a => a -> (a,a) -> Bool+x `inRange` (a,b) = a <= x && x <= b++onLineSegment :: (Ord a, Fractional a) => Point2' a -> LineSegment2' a -> Bool+p `onLineSegment` l@(LineSegment2 s t) =+ if t == s then p == s else (lambda `inRange` (0,1) && p == pointAt lambda l) where- a = p |-| s- b = t |-| s- lambda = (a |@| b) / length l+ a = p |-| s -- the vector from s to p+ b = t |-| s -- the vector from s to t+ lambda = (a |@| b) / (len b)+ -- we translate such that s corresponds with the origin. In this coord system+ -- b represents the input line segment.+ -- We orthoganally project a onto b. Let c be this point (on the vector b)+ -- then : d = a |@| b / length b denotes the distance between (0,0) and c+ -- We can now get the lambda such that : c = linear (0,0) b by dividing+ -- d / length b. Hence in total we divide through (length b)^2. This means+ -- we can avoid computing the square root.+ len (Point2 (x,y)) = x^2 + y^2 class HasLength c where type PM c -- the precision model@@ -115,7 +127,6 @@ class LineLike c where -- | get the point at `time' t (t in [0,1]) pointAt :: Num a => a -> c a -> Point2' a- instance LineLike LineSegment2' where pointAt t (LineSegment2 (Point2 (px,py)) (Point2 (qx,qy))) =
src/Data/Geometry/Point.hs view
@@ -33,5 +33,8 @@ -- | euclidean distance between p and q dist :: Floating a => Point2' a -> Point2' a -> a-dist p q = let a = getX p - getX q- b = getY p - getY q in sqrt (a*a + b*b)+dist p q = sqrt $ l22dist p q++-- | Squared euclidean distance between p and q+l22dist :: Num a => Point2' a -> Point2' a -> a+l22dist p q = let (Point2 (a,b)) = q |-| p in a*a + b*b