geom2d 0.1.2.1 → 0.1.3.1
raw patch · 5 files changed
+33/−14 lines, 5 filesdep ~QuickCheckPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: QuickCheck
API changes (from Hackage documentation)
+ Geom2d.Point: scaleTo :: (Scale p, Point p, Eq a, Floating a) => a -> p a -> Maybe (p a)
+ Geom2d.Shape: convexHull :: (Num (p a), Fractional a, Ord a, Scale p, Point p) => [p a] -> Maybe (Shape p a)
- Geom2d.Point: normalize :: (Scale p, Point p, Fractional a, Eq a, Floating a) => p a -> Maybe (p a)
+ Geom2d.Point: normalize :: (Scale p, Point p, Eq a, Floating a) => p a -> Maybe (p a)
Files
- Geom2d/Point.hs +6/−1
- Geom2d/Shape.hs +5/−0
- Geom2d/Shape/Internal.hs +7/−3
- Test/Point.hs +7/−2
- geom2d.cabal +8/−8
Geom2d/Point.hs view
@@ -4,6 +4,7 @@ , Triangle , Scale (..) , normalize+ , scaleTo , magnitude , dot , cross@@ -63,7 +64,11 @@ scale s (Point' (a,b)) = Point' (a * s, b * s) -- | Normalizes a scaleable point to length 1.-normalize :: (Scale p, Point p, Fractional a, Eq a, Floating a) =>+normalize :: (Scale p, Point p, Eq a, Floating a) => p a -> Maybe (p a) normalize v | magnitude v == 0 = Nothing | otherwise = Just $ scale (1/magnitude v) v++scaleTo :: (Scale p, Point p, Eq a, Floating a) =>+ a -> p a -> Maybe (p a)+scaleTo s vec = scale s <$> normalize vec
Geom2d/Shape.hs view
@@ -3,6 +3,7 @@ , Spatial (..) , circle , rectangle+ , convexHull ) where@@ -18,3 +19,7 @@ rectangle :: (Translate p, Eq a, RealFloat a, Point p, Rotation p) => p a -> a -> a -> Maybe (Shape p a) rectangle m a b = ShapePolygon <$> rectangleInt m a b++convexHull :: (Num (p a), Fractional a, Ord a, Scale p, Point p) =>+ [p a] -> Maybe (Shape p a)+convexHull list = ShapePolygon <$> convexHull' list
Geom2d/Shape/Internal.hs view
@@ -30,7 +30,7 @@ import Geom2d.Point.Internal import Geom2d.Rotation import Geom2d.Translate-import Test.QuickCheck+import Test.QuickCheck hiding (scale) data Circle p a = Circle (p a) a deriving (Show,Read,Eq) @@ -129,9 +129,13 @@ instance (Eq (p a), Num (p a), RealFloat a, Point p) => Intersect (Polygon p a) (Polygon p a) where intersect poly1@(Polygon p1 vs1) poly2@(Polygon p2 vs2) =- let verts1 = map (p1+) vs1- verts2 = map (p2+) vs2+ let verts1 :: [p a]+ verts1 = map (p1+) vs1+ edges1 :: [FinLine p a] edges1 = zipWith FinLine verts1 (tail verts1 ++ [head verts1])+ verts2 :: [p a]+ verts2 = map (p2+) vs2+ edges2 :: [FinLine p a] edges2 = zipWith FinLine verts2 (tail verts2 ++ [head verts2]) in any (uncurry intersect) [ (v1,v2) | v1 <- edges1, v2 <- edges2 ] ||
Test/Point.hs view
@@ -5,8 +5,7 @@ import Data.Maybe import Geom2d.Point import Geom2d.Rotation-import Test.QuickCheck-import Test.QuickCheck.All+import Test.QuickCheck hiding (scale) import Test.Utils import Data.Fixed @@ -42,6 +41,12 @@ maybe (magnitude v ~== 0) ( (~== 1).magnitude ) ( normalize v)++prop_scaleTo :: Point' Float -> Float -> Bool+prop_scaleTo vector x =+ fromMaybe (magnitude vector == 0) $ do+ scaledVector <- scaleTo x vector+ return (magnitude scaledVector ~== abs x) prop_point_point' :: Point' Integer -> Bool prop_point_point' = mkpropPoint
geom2d.cabal view
@@ -1,5 +1,5 @@ name: geom2d-version: 0.1.2.1+version: 0.1.3.1 synopsis: package for geometry in euklidean 2d space description: This package provides tools for dealing with geometric objects in 2D space.@@ -24,7 +24,7 @@ , Geom2d.Rotation, Geom2d other-extensions: MultiParamTypeClasses, FlexibleContexts, TemplateHaskell , ScopedTypeVariables- build-depends: base >=4.8 && <4.9, QuickCheck >=2.7 && <2.8+ build-depends: base >=4.8 && <4.9, QuickCheck >=2.7 && <2.9 , ieee754 >=0.7 && <0.8 default-language: Haskell2010 ghc-options: -Wall@@ -34,39 +34,39 @@ type: exitcode-stdio-1.0 main-is: Test/Point.hs build-depends: base >= 4.8 && < 4.9, ieee754 >= 0.7 && < 0.8- , QuickCheck >= 2.7 && < 2.8+ , QuickCheck >= 2.7 && < 2.9 Test-Suite line default-language: Haskell2010 type: exitcode-stdio-1.0 main-is: Test/Line.hs build-depends: base >= 4.8 && < 4.9, ieee754 >= 0.7 && < 0.8- , QuickCheck >= 2.7 && < 2.8+ , QuickCheck >= 2.7 && < 2.9 Test-Suite intersect default-language: Haskell2010 type: exitcode-stdio-1.0 main-is: Test/Intersect.hs build-depends: base >= 4.8 && < 4.9, ieee754 >= 0.7 && < 0.8- , QuickCheck >= 2.7 && < 2.8+ , QuickCheck >= 2.7 && < 2.9 Test-Suite distance default-language: Haskell2010 type: exitcode-stdio-1.0 main-is: Test/Distance.hs build-depends: base >= 4.8 && < 4.9, ieee754 >= 0.7 && < 0.8- , QuickCheck >= 2.7 && < 2.8+ , QuickCheck >= 2.7 && < 2.9 Test-Suite translate default-language: Haskell2010 type: exitcode-stdio-1.0 main-is: Test/Translate.hs build-depends: base >= 4.8 && < 4.9, ieee754 >= 0.7 && < 0.8- , QuickCheck >= 2.7 && < 2.8+ , QuickCheck >= 2.7 && < 2.9 Test-Suite shape default-language: Haskell2010 type: exitcode-stdio-1.0 main-is: Test/Shape.hs build-depends: base >= 4.8 && < 4.9, ieee754 >= 0.7 && < 0.8- , QuickCheck >= 2.7 && < 2.8+ , QuickCheck >= 2.7 && < 2.9