diff --git a/hgeometry-examples/bapc2012/Gunslinger.hs b/hgeometry-examples/bapc2012/Gunslinger.hs index fd65df2f9..c08305fa6 100644 --- a/hgeometry-examples/bapc2012/Gunslinger.hs +++ b/hgeometry-examples/bapc2012/Gunslinger.hs @@ -1,7 +1,6 @@ module Main where import Control.Lens -import Data.Default.Class import Data.Fixed import qualified Data.Foldable as F import qualified Data.List as List @@ -83,9 +82,6 @@ instance Show Answer where data Kind = Luke | Hatch | Dalton deriving (Show,Eq) -instance Default Kind where - def = Dalton -- if we have to invent a value; invent a dalton. - data Input = Input { _luke :: Point 2 Int , _hatch :: Point 2 Int , _daltons :: [Point 2 Int] diff --git a/hgeometry-examples/polyLineDrawing/Main.hs b/hgeometry-examples/polyLineDrawing/Main.hs index f26021d08..3d4918ca1 100644 --- a/hgeometry-examples/polyLineDrawing/Main.hs +++ b/hgeometry-examples/polyLineDrawing/Main.hs @@ -138,9 +138,6 @@ makeLenses ''Model instance KnownNat p => ToMisoString (RealNumber p) where toMisoString = toMisoString . toFixed -instance Default (Point 2 R :+ Int) where - def = origin :+ 0 - ---------------------------------------- initialModel :: Model diff --git a/hgeometry-examples/polygonTriangulation/Main.hs b/hgeometry-examples/polygonTriangulation/Main.hs index 0a089f406..09b6e5a2e 100644 --- a/hgeometry-examples/polygonTriangulation/Main.hs +++ b/hgeometry-examples/polygonTriangulation/Main.hs @@ -21,8 +21,6 @@ import Miso import Miso.String (MisoString,ToMisoString(..), ms) import Miso.Svg hiding (height_, id_, style_, width_) -import Data.Default.Class - -------------------------------------------------------------------------------- type R = RealNumber 5 diff --git a/hgeometry-examples/voronoiDiagram/Main.hs b/hgeometry-examples/voronoiDiagram/Main.hs index cc6470ab6..1bc3e19d1 100644 --- a/hgeometry-examples/voronoiDiagram/Main.hs +++ b/hgeometry-examples/voronoiDiagram/Main.hs @@ -20,8 +20,6 @@ import Miso import Miso.String (MisoString,ToMisoString(..), ms) import Miso.Svg hiding (height_, id_, style_, width_) -import Data.Default.Class - -------------------------------------------------------------------------------- type R = RealNumber 5 @@ -37,9 +35,6 @@ makeLenses ''Model instance KnownNat p => ToMisoString (RealNumber p) where toMisoString = toMisoString . toFixed -instance Default (Point 2 R :+ Int) where - def = origin :+ 0 - ---------------------------------------- initialModel :: Model diff --git a/hgeometry/bench/Util.hs b/hgeometry/bench/Util.hs index e58473483..f00769e1e 100644 --- a/hgeometry/bench/Util.hs +++ b/hgeometry/bench/Util.hs @@ -19,7 +19,7 @@ import System.Random.Stateful -- | Generate an infinite list random points in a sufficiently large -- bounding box. randomPoints :: forall point r. ( UniformRange point - , Point_ point 2 r + , ConstructablePoint_ point 2 r , Num r ) => StdGen -- ^ generator to use diff --git a/hgeometry/hgeometry.cabal b/hgeometry/hgeometry.cabal index 387f3c65a..b65889da1 100644 --- a/hgeometry/hgeometry.cabal +++ b/hgeometry/hgeometry.cabal @@ -392,11 +392,11 @@ library HGeometry.LineSegment.Intersection.Naive HGeometry.LineSegment.Intersection.BentleyOttmann - HGeometry.LowerEnvelope - HGeometry.LowerEnvelope.Naive - HGeometry.LowerEnvelope.VertexForm - HGeometry.LowerEnvelope.AdjListForm - HGeometry.LowerEnvelope.Connected + HGeometry.Plane.LowerEnvelope + HGeometry.Plane.LowerEnvelope.Naive + HGeometry.Plane.LowerEnvelope.VertexForm + HGeometry.Plane.LowerEnvelope.AdjListForm + HGeometry.Plane.LowerEnvelope.Connected HGeometry.VoronoiDiagram @@ -427,14 +427,14 @@ library HGeometry.LineSegment.Intersection.Types - HGeometry.LowerEnvelope.Type - HGeometry.LowerEnvelope.Connected.Type - HGeometry.LowerEnvelope.Connected.FromVertexForm - -- HGeometry.LowerEnvelope.Sample + HGeometry.Plane.LowerEnvelope.Type + HGeometry.Plane.LowerEnvelope.Connected.Type + HGeometry.Plane.LowerEnvelope.Connected.FromVertexForm + -- HGeometry.Plane.LowerEnvelope.Sample - -- HGeometry.LowerEnvelope.AtMostThree - -- HGeometry.LowerEnvelope.Triangulate + -- HGeometry.Plane.LowerEnvelope.AtMostThree + -- HGeometry.Plane.LowerEnvelope.Triangulate HGeometry.VoronoiDiagram.ViaLowerEnvelope diff --git a/hgeometry/ipe/src/Ipe/IpeOut.hs b/hgeometry/ipe/src/Ipe/IpeOut.hs index 5668c269c..34e729bee 100644 --- a/hgeometry/ipe/src/Ipe/IpeOut.hs +++ b/hgeometry/ipe/src/Ipe/IpeOut.hs @@ -20,6 +20,7 @@ import Control.Lens hiding (Simple) import Data.Foldable (toList) import Data.Kind import Data.List.NonEmpty (NonEmpty(..)) +import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Sequence as Seq import Data.Text (Text) import qualified Data.Text as Text @@ -276,7 +277,10 @@ path = Path . Seq.singleton -- | Construct a PolyLine path segment pathSegment :: (LineSegment_ lineSegment point, Point_ point 2 r) => lineSegment -> PathSegment r -pathSegment = PolyLineSegment . fmap (^.asPoint) . review _PolyLineLineSegment +pathSegment = PolyLineSegment . fmap (^.asPoint) . lineSegmentToPolyLine + where + lineSegmentToPolyLine s = polyLineFromPoints . NonEmpty.fromList $ [s^.start, s^.end] + -- | Draw a polygon ipePolygon :: IpeOut (SimplePolygon (Point 2 r)) Path r diff --git a/hgeometry/kernel/src/HGeometry/Ball/Class.hs b/hgeometry/kernel/src/HGeometry/Ball/Class.hs index 38df44ec2..66cdfe5ad 100644 --- a/hgeometry/kernel/src/HGeometry/Ball/Class.hs +++ b/hgeometry/kernel/src/HGeometry/Ball/Class.hs @@ -49,7 +49,8 @@ class ( HasCenter ball point fromCenterAndSquaredRadius :: point -> NumType ball -> ball -- | A d dimensional unit ball centered at the origin. - unitBall :: Num (NumType ball) => ball + unitBall :: (r ~ NumType ball, d ~ Dimension ball + , Num r, ConstructablePoint_ point d r) => ball unitBall = fromCenterAndSquaredRadius origin 1 -- | A lens to get/set the radius of a Ball diff --git a/hgeometry/kernel/src/HGeometry/HyperPlane/Class.hs b/hgeometry/kernel/src/HGeometry/HyperPlane/Class.hs index bf8179a56..a05662ed0 100644 --- a/hgeometry/kernel/src/HGeometry/HyperPlane/Class.hs +++ b/hgeometry/kernel/src/HGeometry/HyperPlane/Class.hs @@ -346,7 +346,7 @@ class HyperPlaneFromPoints hyperPlane where ) => Vector d point -> hyperPlane -instance (HyperPlane_ hyperPlane d r, Default extra) +instance (HyperPlane_ hyperPlane d r) => HyperPlane_ (hyperPlane :+ extra) d r where evalHyperPlaneEquation h = evalHyperPlaneEquation (h^.core) {-# INLINE evalHyperPlaneEquation #-} @@ -368,7 +368,7 @@ instance (ConstructableHyperPlane_ hyperPlane d r, Default extra) fromPointAndNormal p v = fromPointAndNormal p v :+ def {-# INLINE fromPointAndNormal #-} -instance (NonVerticalHyperPlane_ hyperPlane d r, Default extra) +instance (NonVerticalHyperPlane_ hyperPlane d r) => NonVerticalHyperPlane_ (hyperPlane :+ extra) d r where evalAt p = evalAt p . view core {-# INLINE evalAt #-} diff --git a/hgeometry/kernel/src/HGeometry/Interval/Class.hs b/hgeometry/kernel/src/HGeometry/Interval/Class.hs index c859fcff9..47a293359 100644 --- a/hgeometry/kernel/src/HGeometry/Interval/Class.hs +++ b/hgeometry/kernel/src/HGeometry/Interval/Class.hs @@ -12,11 +12,14 @@ module HGeometry.Interval.Class ( Interval_, pattern Interval_ , IntervalLike_(..) + , ConstructableInterval_(..) , ClosedInterval_(..), pattern ClosedInterval_ + , ConstructableClosedInterval_(..) , clampTo , OpenInterval_(..), pattern OpenInterval_ + , ConstructableOpenInterval_(..) , HasStart(..) , HasEnd(..) @@ -103,6 +106,19 @@ class ( HasStart interval point, HasStartPoint interval (StartPointOf interval) , EndPoint_ (EndPointOf interval), IxValue (EndPointOf interval) ~ point , EndPoint_ (StartPointOf interval), IxValue (StartPointOf interval) ~ point ) => IntervalLike_ interval point | interval -> point where + {-# MINIMAL #-} + +-- | A class for types representing Intervals +type Interval_ :: Type -> Type -> Constraint +class ( IntervalLike_ interval r + , NumType interval ~ r + ) => Interval_ interval r | interval -> r where + +-------------------------------------------------------------------------------- + +-- | A class for constructable intervals +type ConstructableInterval_ :: Type -> Type -> Constraint +class Interval_ interval point => ConstructableInterval_ interval point where {-# MINIMAL mkInterval #-} -- | Construct an interval given its start and end point. @@ -124,15 +140,6 @@ class ( HasStart interval point, HasStartPoint interval (StartPointOf interval) {-# INLINE buildInterval #-} --------------------------------------------------------------------------------- - --- | A class for types representing Intervals -type Interval_ :: Type -> Type -> Constraint -class ( IntervalLike_ interval r - , NumType interval ~ r - ) => Interval_ interval r | interval -> r where - - -------------------------------------------------------------------------------- -- * Closed Intervals @@ -142,6 +149,12 @@ class ( Interval_ interval r , StartPointOf interval ~ EndPoint Closed r , EndPointOf interval ~ EndPoint Closed r ) => ClosedInterval_ interval r where + +-- | A class representing constructable closed intervals +class ( ClosedInterval_ interval r + , ConstructableInterval_ interval r + ) => ConstructableClosedInterval_ interval r where + -- | Construct an interval given its start and end point. mkClosedInterval :: r -> r -> interval mkClosedInterval s e = mkInterval (ClosedE s) (ClosedE e) @@ -157,10 +170,10 @@ class ( Interval_ interval r -- | Pattern matching on an arbitrary closed interval pattern ClosedInterval_ :: ClosedInterval_ interval r => r -> r -> interval pattern ClosedInterval_ l u <- (startAndEnd -> (l,u)) - where - ClosedInterval_ l u = mkClosedInterval l u {-# COMPLETE ClosedInterval_ #-} -{-# INLINE ClosedInterval_ #-} +-- where +-- ClosedInterval_ l u = mkClosedInterval l u +-- {-# INLINE ClosedInterval_ #-} -- | Clamps a value to an interval. I.e. if the value lies outside the range we -- report the closest value "in the range". @@ -182,6 +195,11 @@ class ( Interval_ interval r , StartPointOf interval ~ EndPoint Open r , EndPointOf interval ~ EndPoint Open r ) => OpenInterval_ interval r | interval -> r where + +-- | Constructable Open intervals +class ( OpenInterval_ interval r + , ConstructableInterval_ interval r + ) => ConstructableOpenInterval_ interval r | interval -> r where -- | Construct an interval given its start s and end point t. -- -- pre: s < t @@ -192,19 +210,19 @@ class ( Interval_ interval r -- | Pattern matching on an arbitrary open interval pattern OpenInterval_ :: OpenInterval_ interval r => r -> r -> interval pattern OpenInterval_ l u <- (startAndEnd -> (l,u)) - where - OpenInterval_ l u = mkOpenInterval l u + -- where + -- OpenInterval_ l u = mkOpenInterval l u {-# COMPLETE OpenInterval_ #-} -------------------------------------------------------------------------------- --- | Pattern to match on intervals or construct them. +-- | Pattern to match on intervals pattern Interval_ :: Interval_ interval r => StartPointOf interval -> EndPointOf interval -> interval pattern Interval_ s t <- (startAndEndPoint -> (s,t)) - where - Interval_ s t = mkInterval s t {-# COMPLETE Interval_ #-} + -- where + -- Interval_ s t = mkInterval s t -- | Compute where the given query value is with respect to the interval. @@ -320,20 +338,28 @@ type instance StartPointOf (interval :+ extra) = StartPointOf interval type instance EndPointOf (interval :+ extra) = EndPointOf interval instance ( IntervalLike_ interval point - , Default extra ) => IntervalLike_ (interval :+ extra) point where - mkInterval s t = mkInterval s t :+ def instance ( Interval_ interval r - , Default extra ) => Interval_ (interval :+ extra) r instance ( ClosedInterval_ interval r + ) => ClosedInterval_ (interval :+ extra) r + +instance ( OpenInterval_ interval r + ) => OpenInterval_ (interval :+ extra) r + +instance ( ConstructableInterval_ interval point , Default extra - ) => ClosedInterval_ (interval :+ extra) r where + ) => ConstructableInterval_ (interval :+ extra) point where + mkInterval s t = mkInterval s t :+ def + +instance ( ConstructableClosedInterval_ interval r + , Default extra + ) => ConstructableClosedInterval_ (interval :+ extra) r where mkClosedInterval s t = mkClosedInterval s t :+ def -instance ( OpenInterval_ interval r +instance ( ConstructableOpenInterval_ interval r , Default extra - ) => OpenInterval_ (interval :+ extra) r where + ) => ConstructableOpenInterval_ (interval :+ extra) r where mkOpenInterval s t = mkOpenInterval s t :+ def diff --git a/hgeometry/kernel/src/HGeometry/Interval/HalfOpen.hs b/hgeometry/kernel/src/HGeometry/Interval/HalfOpen.hs index df64fc82e..0407dbd31 100644 --- a/hgeometry/kernel/src/HGeometry/Interval/HalfOpen.hs +++ b/hgeometry/kernel/src/HGeometry/Interval/HalfOpen.hs @@ -52,10 +52,12 @@ instance HasEndPoint (HalfOpenInterval r) (EndPoint Closed r) where endPoint = lens _right (\ai x -> ai { _right = x}) instance IntervalLike_ (HalfOpenInterval r) r where - mkInterval = HalfOpenInterval instance Interval_ (HalfOpenInterval r) r where +instance ConstructableInterval_ (HalfOpenInterval r) r where + mkInterval = HalfOpenInterval + instance (Ord r) => Point 1 r `HasIntersectionWith` HalfOpenInterval r where (Point1 q) `intersects` i = q `stabsInterval` i diff --git a/hgeometry/kernel/src/HGeometry/Interval/Internal.hs b/hgeometry/kernel/src/HGeometry/Interval/Internal.hs index 4dea2b4e1..1b491b3d9 100644 --- a/hgeometry/kernel/src/HGeometry/Interval/Internal.hs +++ b/hgeometry/kernel/src/HGeometry/Interval/Internal.hs @@ -83,15 +83,19 @@ type instance EndPointOf (Interval endPoint r) = endPoint r instance ( EndPoint_ (endPoint r), IxValue (endPoint r) ~ r ) => IntervalLike_ (Interval endPoint r) r where - mkInterval = Interval instance ( EndPoint_ (endPoint r), IxValue (endPoint r) ~ r ) => Interval_ (Interval endPoint r) r where +instance ( EndPoint_ (endPoint r), IxValue (endPoint r) ~ r + ) => ConstructableInterval_ (Interval endPoint r) r where + mkInterval = Interval instance ClosedInterval_ (ClosedInterval r) r +instance ConstructableClosedInterval_ (ClosedInterval r) r instance OpenInterval_ (OpenInterval r) r +instance ConstructableOpenInterval_ (OpenInterval r) r -------------------------------------------------------------------------------- diff --git a/hgeometry/kernel/src/HGeometry/LineSegment/Class.hs b/hgeometry/kernel/src/HGeometry/LineSegment/Class.hs index 04d9070fd..d20f3db3c 100644 --- a/hgeometry/kernel/src/HGeometry/LineSegment/Class.hs +++ b/hgeometry/kernel/src/HGeometry/LineSegment/Class.hs @@ -11,6 +11,7 @@ -------------------------------------------------------------------------------- module HGeometry.LineSegment.Class ( LineSegment_(..), pattern LineSegment_ + , ConstructableLineSegment_(..) , ClosedLineSegment_ , OpenLineSegment_ @@ -57,14 +58,18 @@ class HasOnSegment lineSegment d | lineSegment -> d where class ( IntervalLike_ lineSegment point , Point_ point (Dimension lineSegment) (NumType lineSegment) ) => LineSegment_ lineSegment point | lineSegment -> point where - {-# MINIMAL uncheckedLineSegment #-} + {-# MINIMAL #-} +-- | A class representing line segments +class ( LineSegment_ lineSegment point + ) => ConstructableLineSegment_ lineSegment point where + {-# MINIMAL uncheckedLineSegment #-} -- | Create a segment -- -- pre: the points are disjoint uncheckedLineSegment :: point -> point -> lineSegment - uncheckedLineSegment s t = mkInterval (mkEndPoint s) (mkEndPoint t) + -- uncheckedLineSegment s t = mkInterval (mkEndPoint s) (mkEndPoint t) -- | smart constructor that creates a valid segment, i.e. it -- validates that the endpoints are disjoint. @@ -74,6 +79,9 @@ class ( IntervalLike_ lineSegment point | s^.vector /= t^.vector = Just $ uncheckedLineSegment s t | otherwise = Nothing + + + -- | A class representing Closed Linesegments class ( LineSegment_ lineSegment point , StartPointOf lineSegment ~ EndPoint Closed point @@ -87,12 +95,10 @@ class ( LineSegment_ lineSegment point ) => OpenLineSegment_ lineSegment point where --- | Constructs a line segment from the start and end point +-- | Deconstructs a line segment from the start and end point pattern LineSegment_ :: forall lineSegment point. LineSegment_ lineSegment point => point -> point -> lineSegment pattern LineSegment_ s t <- (startAndEnd -> (s,t)) - where - LineSegment_ s t = uncheckedLineSegment s t {-# COMPLETE LineSegment_ #-} -------------------------------------------------------------------------------- @@ -108,7 +114,9 @@ pattern LineSegment_ s t <- (startAndEnd -> (s,t)) -- >>> interpolate 1 $ ClosedLineSegment origin (Point2 10.0 10.0) -- Point2 10.0 10.0 interpolate :: forall lineSegment d point r - . (Fractional r, LineSegment_ lineSegment point, Point_ point d r) + . ( Fractional r, LineSegment_ lineSegment point + , ConstructablePoint_ point d r + ) => r -> lineSegment -> point interpolate lam (LineSegment_ s t) = fromVector $ (s^.vector ^* (1-lam)) ^+^ (t^.vector ^* lam) @@ -221,16 +229,17 @@ yCoordAt x (LineSegment_ (Point2_ px py) (Point2_ qx qy)) -------------------------------------------------------------------------------- instance ( LineSegment_ segment point - , Default extra ) => LineSegment_ (segment :+ extra) point where + +instance ( ConstructableLineSegment_ segment point + , Default extra + ) => ConstructableLineSegment_ (segment :+ extra) point where uncheckedLineSegment p q = uncheckedLineSegment p q :+ def instance ( ClosedLineSegment_ segment point - , Default extra ) => ClosedLineSegment_ (segment :+ extra) point where instance ( OpenLineSegment_ segment point - , Default extra ) => OpenLineSegment_ (segment :+ extra) point where instance HasOnSegment lineSegment d => HasOnSegment (lineSegment :+ extra) d where diff --git a/hgeometry/kernel/src/HGeometry/LineSegment/Internal.hs b/hgeometry/kernel/src/HGeometry/LineSegment/Internal.hs index c1c98a90f..32458564b 100644 --- a/hgeometry/kernel/src/HGeometry/LineSegment/Internal.hs +++ b/hgeometry/kernel/src/HGeometry/LineSegment/Internal.hs @@ -63,10 +63,10 @@ import Text.Read type LineSegment :: (Type -> Type) -> Type -> Type newtype LineSegment endPoint point = MkLineSegment (Interval endPoint point) --- | Default implementation of Closed LineSegments +-- | A type representing Closed LineSegments type ClosedLineSegment point = LineSegment (EndPoint Closed) point --- | Default implementation of Open LineSegments +-- | A type representing Open LineSegments type OpenLineSegment point = LineSegment (EndPoint Open) point -- | Construct a line Segment @@ -133,12 +133,16 @@ type instance EndPointOf (LineSegment endPoint point) = endPoint point instance ( IxValue (endPoint point) ~ point , EndPoint_ (endPoint point) ) => IntervalLike_ (LineSegment endPoint point) point where - mkInterval = LineSegment instance ( IxValue (endPoint point) ~ point , EndPoint_ (endPoint point) , Point_ point (Dimension point) (NumType point) ) => LineSegment_ (LineSegment endPoint point) point where + +instance ( IxValue (endPoint point) ~ point + , EndPoint_ (endPoint point) + , Point_ point (Dimension point) (NumType point) + ) => ConstructableLineSegment_ (LineSegment endPoint point) point where uncheckedLineSegment s t = LineSegment (mkEndPoint s) (mkEndPoint t) instance ( Point_ point (Dimension point) (NumType point) diff --git a/hgeometry/kernel/src/HGeometry/Viewport.hs b/hgeometry/kernel/src/HGeometry/Viewport.hs index 67a37055e..06e8a5bb8 100644 --- a/hgeometry/kernel/src/HGeometry/Viewport.hs +++ b/hgeometry/kernel/src/HGeometry/Viewport.hs @@ -117,7 +117,7 @@ centeredOrigin :: ( Fractional r , Point_ point 2 r ) => rectangle -> Viewport r centeredOrigin rect' = Viewport rect - (translation $ centerPoint rect' .-. origin) + (translation $ (centerPoint rect')^.vector) where rect = Box (rect'^.minPoint.asPoint) (rect'^.maxPoint.asPoint) diff --git a/hgeometry/point/src/HGeometry/Point.hs b/hgeometry/point/src/HGeometry/Point.hs index 56d717665..4f769facd 100644 --- a/hgeometry/point/src/HGeometry/Point.hs +++ b/hgeometry/point/src/HGeometry/Point.hs @@ -20,6 +20,7 @@ module HGeometry.Point -- , {- | construct a 3-dimensional point -} pattern Point3 -- , {- | construct a 4-dimensional point -} pattern Point4 , Point_(..), pattern Point1_, pattern Point2_, pattern Point3_, pattern Point4_ + , ConstructablePoint_(..) , HasVector(..) , HasCoordinates(..) , asPoint diff --git a/hgeometry/point/src/HGeometry/Point/Class.hs b/hgeometry/point/src/HGeometry/Point/Class.hs index 1d34eaa56..4f482236a 100644 --- a/hgeometry/point/src/HGeometry/Point/Class.hs +++ b/hgeometry/point/src/HGeometry/Point/Class.hs @@ -1,6 +1,7 @@ {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE DefaultSignatures #-} +{-# OPTIONS_GHC -Wno-orphans #-} -------------------------------------------------------------------------------- -- | -- Module : HGeometry.Point.Class @@ -16,6 +17,7 @@ module HGeometry.Point.Class , HasCoordinates(..) , Affine_(..) , Point_(..), pattern Point1_, pattern Point2_, pattern Point3_, pattern Point4_ + , ConstructablePoint_(..) , origin , pointFromList , coord @@ -24,7 +26,6 @@ module HGeometry.Point.Class -- , projectPoint -- , PointFor , HasPoints(..), HasPoints' - , NoDefault(..) ) where import Control.Lens @@ -32,7 +33,6 @@ import Data.Default.Class import Data.Function (on) import qualified Data.List.NonEmpty as NonEmpty import Data.Proxy (Proxy(..)) -import GHC.Generics (Generic) import GHC.TypeNats import HGeometry.Ext import HGeometry.Properties @@ -161,13 +161,7 @@ instance ( d ~ Dimension (v r) class ( Affine_ point d r , HasVector point point ) => Point_ point d r where - {-# MINIMAL fromVector #-} - - -- | Construct a point from a vector - -- - -- >>> fromVector (Vector4 1 2 3 4) :: Point 4 Int - -- Point4 1 2 3 4 - fromVector :: Vector d r -> point + {-# MINIMAL #-} -- | Get the coordinate in a given dimension. This operation is unsafe in the -- sense that no bounds are checked. Consider using `coord` instead. @@ -183,6 +177,16 @@ class ( Affine_ point d r {-# INLINE coord' #-} +-- | Type class for constructable points +class Point_ point d r => ConstructablePoint_ point d r where + {-# MINIMAL fromVector #-} + + -- | Construct a point from a vector + -- + -- >>> fromVector (Vector4 1 2 3 4) :: Point 4 Int + -- Point4 1 2 3 4 + fromVector :: Vector d r -> point + -- | Get the coordinate in a given dimension -- @@ -202,7 +206,13 @@ instance ( d ~ Dimension (v r) , r ~ IxValue (v r) , Vector_ (v r) d r , Additive_ (Vector d r) d r - ) => Point_ (Linear.Point v r) d r where + ) => Point_ (Linear.Point v r) d r + +instance ( d ~ Dimension (v r) + , r ~ IxValue (v r) + , Vector_ (v r) d r + , Additive_ (Vector d r) d r + ) => ConstructablePoint_ (Linear.Point v r) d r where fromVector = Linear.P . review _Vector {-# INLINE fromVector #-} @@ -210,46 +220,44 @@ instance ( d ~ Dimension (v r) -- -- >>> origin :: Point 4 Int -- Point4 0 0 0 0 -origin :: forall point d r. (Num r, Point_ point d r) => point +origin :: forall point d r. (Num r, ConstructablePoint_ point d r) => point origin = fromVector zero {-# INLINE origin #-} --- | A bidirectional pattern synonym for 1 dimensional points. +-- | A pattern synonym for 1 dimensional points. pattern Point1_ :: Point_ point 1 r => r -> point pattern Point1_ x <- (view xCoord -> x) - where - Point1_ x = fromVector $ Vector1 x -{-# INLINE Point1_ #-} +-- where +-- Point1_ x = fromVector $ Vector1 x +-- {-# INLINE Point1_ #-} {-# COMPLETE Point1_ #-} --- | A bidirectional pattern synonym for 2 dimensional points. +-- | A pattern synonym for 2 dimensional points. pattern Point2_ :: ( Point_ point 2 r ) => r -> r -> point pattern Point2_ x y <- (view vector -> Vector2 x y) - where - Point2_ x y = fromVector $ Vector2 x y -{-# INLINE Point2_ #-} +-- where +-- Point2_ x y = fromVector $ Vector2 x y +-- {-# INLINE Point2_ #-} {-# COMPLETE Point2_ #-} --- | A bidirectional pattern synonym for 3 dimensional points. +-- | A pattern synonym for 3 dimensional points. pattern Point3_ :: ( Point_ point 3 r - -- , ConstructableVector_ (Vector.VectorFamily 3 r) 3 r ) => r -> r -> r -> point pattern Point3_ x y z <- (view vector -> Vector3 x y z) - where - Point3_ x y z = fromVector $ Vector3 x y z -{-# INLINE Point3_ #-} +-- where +-- Point3_ x y z = fromVector $ Vector3 x y z +-- {-# INLINE Point3_ #-} {-# COMPLETE Point3_ #-} -- | A bidirectional pattern synonym for 4 dimensional points. pattern Point4_ :: ( Point_ point 4 r - -- , ConstructableVector_ (Vector.VectorFamily 4 r) 4 r ) => r -> r -> r -> r -> point pattern Point4_ x y z w <- (view vector -> Vector4 x y z w) - where - Point4_ x y z w = fromVector $ Vector4 x y z w -{-# INLINE Point4_ #-} +-- where +-- Point4_ x y z w = fromVector $ Vector4 x y z w +-- {-# INLINE Point4_ #-} {-# COMPLETE Point4_ #-} @@ -262,7 +270,7 @@ pattern Point4_ x y z w <- (view vector -> Vector4 x y z w) -- Nothing -- >>> pointFromList [1,2,3,4] :: Maybe (Point 3 Int) -- Nothing -pointFromList :: ( Point_ point d r +pointFromList :: ( ConstructablePoint_ point d r , Vector_ (Vector d r) d r ) => [r] -> Maybe point pointFromList = fmap fromVector . vectorFromList @@ -356,15 +364,11 @@ instance Affine_ point d r => Affine_ (point :+ extra) d r where p .+^ v = p&core %~ (.+^ v) {-# INLINE (.+^) #-} -instance (Point_ point d r, Default extra) => Point_ (point :+ extra) d r where +instance (Point_ point d r) => Point_ (point :+ extra) d r where {-# SPECIALIZE instance Point_ point d r => Point_ (point :+ ()) d r #-} - fromVector v = fromVector v :+ def - --- | A newtype that can discharge the Default constraint in an unsafe way, if you really --- sure that you'll never actually need the default -newtype NoDefault extra = NoDefault extra - deriving newtype (Show,Read,Eq,Ord,Enum,Num,Bounded,Real,Fractional,RealFrac,Generic) - -instance Default (NoDefault extra) where - def = error "NoDefault does not have an actual default. So something went wrong" +instance (ConstructablePoint_ point d r, Default extra) + => ConstructablePoint_ (point :+ extra) d r where + {-# SPECIALIZE instance ConstructablePoint_ point d r + => ConstructablePoint_ (point :+ ()) d r #-} + fromVector v = fromVector v :+ def diff --git a/hgeometry/point/src/HGeometry/Point/PointF.hs b/hgeometry/point/src/HGeometry/Point/PointF.hs index e14ca5a0a..0bdd6921f 100644 --- a/hgeometry/point/src/HGeometry/Point/PointF.hs +++ b/hgeometry/point/src/HGeometry/Point/PointF.hs @@ -108,6 +108,10 @@ instance ( Additive_ vector d r instance ( Additive_ vector d r , Additive_ (Vector d r) d r ) => Point_ (PointF vector) d r where + +instance ( Additive_ vector d r + , Additive_ (Vector d r) d r + ) => ConstructablePoint_ (PointF vector) d r where fromVector = Point . review _Vector {-# INLINE fromVector #-} diff --git a/hgeometry/point/src/HGeometry/Point/Quadrants.hs b/hgeometry/point/src/HGeometry/Point/Quadrants.hs index 6315c1f1f..535d7319b 100644 --- a/hgeometry/point/src/HGeometry/Point/Quadrants.hs +++ b/hgeometry/point/src/HGeometry/Point/Quadrants.hs @@ -35,7 +35,7 @@ quadrantWith c p = case ( (c^.xCoord) `compare` (p^.xCoord) (LT, GT) -> BottomRight -- | Quadrants with respect to the origin -quadrant :: (Ord r, Num r, Point_ point 2 r) => point -> Quadrant +quadrant :: (Ord r, Num r, ConstructablePoint_ point 2 r) => point -> Quadrant quadrant = quadrantWith origin -- | Given a center point c, and a set of points, partition the points into diff --git a/hgeometry/point/test/Point/CmpAround.hs b/hgeometry/point/test/Point/CmpAround.hs index fa076a67c..949d3e336 100644 --- a/hgeometry/point/test/Point/CmpAround.hs +++ b/hgeometry/point/test/Point/CmpAround.hs @@ -1,14 +1,13 @@ module Point.CmpAround where import Control.Lens ((^.)) -import Data.Default.Class import HGeometry.Ext import HGeometry.Point -- | Counter clockwise ordering of the points around c. Points are ordered with -- respect to the positive x-axis. -ccwCmpAroundByQuadrant :: (Num r, Ord r, Default p) +ccwCmpAroundByQuadrant :: (Num r, Ord r) => Point 2 r :+ p -> Point 2 r :+ p -> Point 2 r :+ p -> Ordering ccwCmpAroundByQuadrant c q r = case (quadrantWith c q `compare` quadrantWith c r) of EQ -> case ccw (c^.core) (q^.core) (r^.core) of @@ -20,7 +19,7 @@ ccwCmpAroundByQuadrant c q r = case (quadrantWith c q `compare` quadrantWith c r -cwCmpAroundByQuadrant :: (Num r, Ord r, Default p) +cwCmpAroundByQuadrant :: (Num r, Ord r) => Point 2 r :+ p -> Point 2 r :+ p -> Point 2 r :+ p -> Ordering cwCmpAroundByQuadrant c q r = case (quadrantWith c q `compare` quadrantWith c r) of EQ -> case ccw (c^.core) (q^.core) (r^.core) of @@ -32,7 +31,7 @@ cwCmpAroundByQuadrant c q r = case (quadrantWith c q `compare` quadrantWith c r) -- specified by the quadrant. -- | Original implementation of cw with distance check -cwCmpAroundByQuadrantWithDist :: (Num r, Ord r, Default p) +cwCmpAroundByQuadrantWithDist :: (Num r, Ord r) => Point 2 r :+ p -> Point 2 r :+ p -> Point 2 r :+ p -> Ordering cwCmpAroundByQuadrantWithDist c q r = case (quadrantWith c q `compare` quadrantWith c r) of diff --git a/hgeometry/src/HGeometry/HalfPlane/CommonIntersection.hs b/hgeometry/src/HGeometry/HalfPlane/CommonIntersection.hs index 54af40d60..1f0c6a813 100644 --- a/hgeometry/src/HGeometry/HalfPlane/CommonIntersection.hs +++ b/hgeometry/src/HGeometry/HalfPlane/CommonIntersection.hs @@ -8,11 +8,13 @@ module HGeometry.HalfPlane.CommonIntersection -- , LowerBoundary(..) ) where + +import Control.Lens import Control.Lens hiding (Empty) import Data.Bifunctor (first) -import Data.Default.Class import Data.Foldable1 import Data.List.NonEmpty (NonEmpty(..)) +import qualified Data.List.NonEmpty as NonEmpty import Data.Ord (comparing) import Data.Sequence (Seq(..)) import qualified Data.Sequence as Seq @@ -67,7 +69,6 @@ commonIntersection :: forall f halfPlane r. , HalfPlane_ halfPlane r , Fractional r, Ord r - , Default (LineEQ r :+ halfPlane), Default halfPlane -- FIXME , Show halfPlane, Show r ) => f halfPlane -> CommonIntersection halfPlane r @@ -273,7 +274,6 @@ boundaries :: ( HalfPlane_ halfPlane r , Ord r, Fractional r - , Default (LineEQ r :+ halfPlane), Default halfPlane -- FIXME , Show r, Show halfPlane ) => NonVerticals halfPlane r -> These2 (Chain Seq (LineEQ r :+ halfPlane) r) boundaries = bimap upperBoundary lowerBoundary @@ -431,7 +431,6 @@ upperEnvelope :: forall g f line r. , IsIntersectableWith line line , Intersection line line ~ Maybe (LineLineIntersection line) , HasFromFoldable g, Functor g - , Default line -- TODO hack ) => f line -> UpperEnvelopeF g (Point 2 r) line upperEnvelope = bimap (over yCoord negate) flipY . lowerEnvelope . fmap flipY diff --git a/hgeometry/src/HGeometry/Line/LowerEnvelope.hs b/hgeometry/src/HGeometry/Line/LowerEnvelope.hs index b6ae4ab3b..74d1cba07 100644 --- a/hgeometry/src/HGeometry/Line/LowerEnvelope.hs +++ b/hgeometry/src/HGeometry/Line/LowerEnvelope.hs @@ -21,7 +21,6 @@ module HGeometry.Line.LowerEnvelope ) where import Control.Lens -import Data.Default.Class import Data.Foldable1 import qualified Data.List as List import Data.List.NonEmpty (NonEmpty(..)) @@ -91,7 +90,6 @@ lowerEnvelope :: forall g f line r. , IsIntersectableWith line line , Intersection line line ~ Maybe (LineLineIntersection line) , HasFromFoldable g - , Default line -- TODO hack ) => f line -> LowerEnvelopeF g (Point 2 r) line lowerEnvelope = construct . fmap (view extra) . NonEmpty.reverse diff --git a/hgeometry/src/HGeometry/LineSegment/Intersection/BentleyOttmann.hs b/hgeometry/src/HGeometry/LineSegment/Intersection/BentleyOttmann.hs index d4af6f33c..27871b374 100644 --- a/hgeometry/src/HGeometry/LineSegment/Intersection/BentleyOttmann.hs +++ b/hgeometry/src/HGeometry/LineSegment/Intersection/BentleyOttmann.hs @@ -468,11 +468,12 @@ instance ( HasEndPoint lineSegment endPoint type instance StartPointOf (Flipped lineSegment) = StartPointOf lineSegment type instance EndPointOf (Flipped lineSegment) = EndPointOf lineSegment -instance IntervalLike_ lineSegment point => IntervalLike_ (Flipped lineSegment) point where - mkInterval s t = NotFlipped $ mkInterval s t -instance LineSegment_ lineSegment point => LineSegment_ (Flipped lineSegment) point where - uncheckedLineSegment s t = NotFlipped $ uncheckedLineSegment s t +instance IntervalLike_ lineSegment point => IntervalLike_ (Flipped lineSegment) point +instance LineSegment_ lineSegment point => LineSegment_ (Flipped lineSegment) point +instance ConstructableLineSegment_ lineSegment point + => ConstructableLineSegment_ (Flipped lineSegment) point where + uncheckedLineSegment s t = NotFlipped $ uncheckedLineSegment s t instance segment `HasIntersectionWith` segment => (Flipped segment) `HasIntersectionWith` (Flipped segment) where diff --git a/hgeometry/src/HGeometry/LowerEnvelope.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope.hs similarity index 57% rename from hgeometry/src/HGeometry/LowerEnvelope.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope.hs index 6907f8f75..a155c14ef 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope.hs @@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- -- | --- Module : HGeometry.LowerEnvelope +-- Module : HGeometry.Plane.LowerEnvelope -- Copyright : (C) Frank Staals -- License : see the LICENSE file -- Maintainer : Frank Staals @@ -8,14 +8,14 @@ -- Computing the lower envelope of a set of planes -- -------------------------------------------------------------------------------- -module HGeometry.LowerEnvelope - ( module HGeometry.LowerEnvelope.Naive - , module HGeometry.LowerEnvelope.Type - -- , module HGeometry.LowerEnvelope.Naive +module HGeometry.Plane.LowerEnvelope + ( module HGeometry.Plane.LowerEnvelope.Naive + , module HGeometry.Plane.LowerEnvelope.Type + -- , module HGeometry.Plane.LowerEnvelope.Naive ) where -import HGeometry.LowerEnvelope.Naive -import HGeometry.LowerEnvelope.Type +import HGeometry.Plane.LowerEnvelope.Naive +import HGeometry.Plane.LowerEnvelope.Type -------------------------------------------------------------------------------- diff --git a/hgeometry/src/HGeometry/LowerEnvelope/AdjListForm.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/AdjListForm.hs similarity index 95% rename from hgeometry/src/HGeometry/LowerEnvelope/AdjListForm.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/AdjListForm.hs index 6d2d1f61e..d1e66ea7c 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope/AdjListForm.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/AdjListForm.hs @@ -1,7 +1,7 @@ {-# LANGUAGE UndecidableInstances #-} -------------------------------------------------------------------------------- -- | --- Module : HGeometry.LowerEnvelope.AdjListForm +-- Module : HGeometry.Plane.LowerEnvelope.AdjListForm -- Copyright : (C) Frank Staals -- License : see the LICENSE file -- Maintainer : Frank Staals @@ -10,7 +10,7 @@ -- form. -- -------------------------------------------------------------------------------- -module HGeometry.LowerEnvelope.AdjListForm +module HGeometry.Plane.LowerEnvelope.AdjListForm ( LowerEnvelope(..) , LowerEnvelope'(LowerEnvelope) , ParallelPlane @@ -45,9 +45,9 @@ import HGeometry.Algorithms.DivideAndConquer import HGeometry.HyperPlane.Class import HGeometry.HyperPlane.NonVertical import HGeometry.Line.LineEQ -import HGeometry.LowerEnvelope.Connected -import HGeometry.LowerEnvelope.VertexForm (IntersectionLine(..), intersectionLine) -import qualified HGeometry.LowerEnvelope.VertexForm as VertexForm +import HGeometry.Plane.LowerEnvelope.Connected +import HGeometry.Plane.LowerEnvelope.VertexForm (IntersectionLine(..), intersectionLine) +import qualified HGeometry.Plane.LowerEnvelope.VertexForm as VertexForm import HGeometry.Point import HGeometry.Properties import HGeometry.Vector.NonEmpty.Util () diff --git a/hgeometry/src/HGeometry/LowerEnvelope/AtMostThree.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/AtMostThree.hs similarity index 100% rename from hgeometry/src/HGeometry/LowerEnvelope/AtMostThree.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/AtMostThree.hs diff --git a/hgeometry/src/HGeometry/LowerEnvelope/BatchedPointLoc.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/BatchedPointLoc.hs similarity index 100% rename from hgeometry/src/HGeometry/LowerEnvelope/BatchedPointLoc.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/BatchedPointLoc.hs diff --git a/hgeometry/src/HGeometry/LowerEnvelope/ConflictLists.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/ConflictLists.hs similarity index 100% rename from hgeometry/src/HGeometry/LowerEnvelope/ConflictLists.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/ConflictLists.hs diff --git a/hgeometry/src/HGeometry/LowerEnvelope/Connected.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected.hs similarity index 79% rename from hgeometry/src/HGeometry/LowerEnvelope/Connected.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected.hs index 9455fdba0..2214cb9ff 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope/Connected.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected.hs @@ -10,7 +10,7 @@ -- form. -- -------------------------------------------------------------------------------- -module HGeometry.LowerEnvelope.Connected +module HGeometry.Plane.LowerEnvelope.Connected ( LowerEnvelope'(LowerEnvelope) , theUnboundedVertex, boundedVertices @@ -28,9 +28,9 @@ module HGeometry.LowerEnvelope.Connected , projectedEdgeGeometries, projectedEdgeGeometry ) where -import HGeometry.LowerEnvelope.Type -import HGeometry.LowerEnvelope.Connected.Type -import HGeometry.LowerEnvelope.Connected.FromVertexForm +import HGeometry.Plane.LowerEnvelope.Type +import HGeometry.Plane.LowerEnvelope.Connected.Type +import HGeometry.Plane.LowerEnvelope.Connected.FromVertexForm import HGeometry.Vector.NonEmpty.Util () diff --git a/hgeometry/src/HGeometry/LowerEnvelope/Connected/FromVertexForm.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected/FromVertexForm.hs similarity index 98% rename from hgeometry/src/HGeometry/LowerEnvelope/Connected/FromVertexForm.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected/FromVertexForm.hs index 0d8df9938..e3ee52041 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope/Connected/FromVertexForm.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected/FromVertexForm.hs @@ -1,7 +1,7 @@ {-# LANGUAGE UndecidableInstances #-} -------------------------------------------------------------------------------- -- | --- Module : HGeometry.LowerEnvelope.FromVertexForm +-- Module : HGeometry.Plane.LowerEnvelope.FromVertexForm -- Copyright : (C) Frank Staals -- License : see the LICENSE file -- Maintainer : Frank Staals @@ -10,7 +10,7 @@ -- form. -- -------------------------------------------------------------------------------- -module HGeometry.LowerEnvelope.Connected.FromVertexForm +module HGeometry.Plane.LowerEnvelope.Connected.FromVertexForm ( fromVertexForm' ) where @@ -33,9 +33,9 @@ import HGeometry.Foldable.Sort import HGeometry.Foldable.Util import HGeometry.HyperPlane.NonVertical import HGeometry.Line -import HGeometry.LowerEnvelope.Connected.Type -import HGeometry.LowerEnvelope.Type -import qualified HGeometry.LowerEnvelope.VertexForm as VertexForm +import HGeometry.Plane.LowerEnvelope.Connected.Type +import HGeometry.Plane.LowerEnvelope.Type +import qualified HGeometry.Plane.LowerEnvelope.VertexForm as VertexForm import HGeometry.Point import HGeometry.Properties import HGeometry.Vector diff --git a/hgeometry/src/HGeometry/LowerEnvelope/Connected/Type.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected/Type.hs similarity index 98% rename from hgeometry/src/HGeometry/LowerEnvelope/Connected/Type.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected/Type.hs index 1693b42de..47312b5db 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope/Connected/Type.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Connected/Type.hs @@ -1,7 +1,7 @@ {-# LANGUAGE UndecidableInstances #-} -------------------------------------------------------------------------------- -- | --- Module : HGeometry.LowerEnvelope.Connected.Type +-- Module : HGeometry.Plane.LowerEnvelope.Connected.Type -- Copyright : (C) Frank Staals -- License : see the LICENSE file -- Maintainer : Frank Staals @@ -10,7 +10,7 @@ -- form. -- -------------------------------------------------------------------------------- -module HGeometry.LowerEnvelope.Connected.Type +module HGeometry.Plane.LowerEnvelope.Connected.Type ( LowerEnvelope'(LowerEnvelope) , theUnboundedVertex, boundedVertices , traverseLowerEnvelope @@ -57,9 +57,9 @@ import HGeometry.HyperPlane.Class import HGeometry.HyperPlane.NonVertical import HGeometry.Line import HGeometry.LineSegment -import HGeometry.LowerEnvelope.Type -import HGeometry.LowerEnvelope.VertexForm (IntersectionLine(..),intersectionLine) -import qualified HGeometry.LowerEnvelope.VertexForm as VertexForm +import HGeometry.Plane.LowerEnvelope.Type +import HGeometry.Plane.LowerEnvelope.VertexForm (IntersectionLine(..),intersectionLine) +import qualified HGeometry.Plane.LowerEnvelope.VertexForm as VertexForm import HGeometry.Point import HGeometry.Properties import HGeometry.Vector diff --git a/hgeometry/src/HGeometry/LowerEnvelope/DivideAndConquer.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/DivideAndConquer.hs similarity index 100% rename from hgeometry/src/HGeometry/LowerEnvelope/DivideAndConquer.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/DivideAndConquer.hs diff --git a/hgeometry/src/HGeometry/Plane/LowerEnvelope/EpsApproximation.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/EpsApproximation.hs new file mode 100644 index 000000000..666b5d9df --- /dev/null +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/EpsApproximation.hs @@ -0,0 +1,32 @@ +module HGeometry.LowerEnvelope.EpsApproximation + ( + + ) where + +import Control.Monad.State.Class +import HGeometry.HyperPlane.Class +import HGeometry.HyperPlane.NonVertical +import System.Random.Stateful +import Witherable + +-------------------------------------------------------------------------------- + +-- | Given a value r, and a set of planes H, we construct a C/r-approximation A of H w.r.t +-- the shallow downward ranges. +epsApproximation :: ( Plane_ plane r + , Ord r, Fractional r, Foldable f, Functor f, Ord plane + ) + => Int -- ^ the parameter r + -> f plane -> f plane +epsApproximation = undefined + +-- | Given a value r, and a set of planes H, we construct a C/r-approximation A of H w.r.t +-- the shallow downward ranges. +epsApproximation' :: ( Plane_ plane r + , Ord r, Fractional r, Foldable f, Functor f, Ord plane + , RandomGen gen, MonadState gen m + , Show plane, Show r + ) + => Int -- ^ the parameter r + -> f plane -> m (f plane) +epsApproximation' r hs = undefined diff --git a/hgeometry/src/HGeometry/LowerEnvelope/Naive.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Naive.hs similarity index 95% rename from hgeometry/src/HGeometry/LowerEnvelope/Naive.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/Naive.hs index 96e9fe874..5ebd50ced 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope/Naive.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Naive.hs @@ -1,5 +1,5 @@ {-# LANGUAGE UndecidableInstances #-} -module HGeometry.LowerEnvelope.Naive +module HGeometry.Plane.LowerEnvelope.Naive ( lowerEnvelope , lowerEnvelopeVertexForm -- , triangulatedLowerEnvelope @@ -16,8 +16,8 @@ import qualified Data.Set as Set import HGeometry.Combinatorial.Util import HGeometry.HyperPlane.Class import HGeometry.HyperPlane.NonVertical -import HGeometry.LowerEnvelope.AdjListForm (LowerEnvelope, fromVertexForm) -import HGeometry.LowerEnvelope.VertexForm +import HGeometry.Plane.LowerEnvelope.AdjListForm (LowerEnvelope, fromVertexForm) +import HGeometry.Plane.LowerEnvelope.VertexForm import HGeometry.Point -------------------------------------------------------------------------------- diff --git a/hgeometry/src/HGeometry/LowerEnvelope/Sample.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Sample.hs similarity index 100% rename from hgeometry/src/HGeometry/LowerEnvelope/Sample.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/Sample.hs diff --git a/hgeometry/src/HGeometry/LowerEnvelope/Triangulate.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Triangulate.hs similarity index 100% rename from hgeometry/src/HGeometry/LowerEnvelope/Triangulate.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/Triangulate.hs diff --git a/hgeometry/src/HGeometry/LowerEnvelope/Type.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Type.hs similarity index 99% rename from hgeometry/src/HGeometry/LowerEnvelope/Type.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/Type.hs index 8368bde61..f3a7c8194 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope/Type.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/Type.hs @@ -1,5 +1,5 @@ {-# LANGUAGE UndecidableInstances #-} -module HGeometry.LowerEnvelope.Type +module HGeometry.Plane.LowerEnvelope.Type ( VertexID , BoundedVertexF(Vertex) , location, definers, location2, incidentEdgesB diff --git a/hgeometry/src/HGeometry/LowerEnvelope/VertexForm.hs b/hgeometry/src/HGeometry/Plane/LowerEnvelope/VertexForm.hs similarity index 97% rename from hgeometry/src/HGeometry/LowerEnvelope/VertexForm.hs rename to hgeometry/src/HGeometry/Plane/LowerEnvelope/VertexForm.hs index 6de37fcdb..e6be0926c 100644 --- a/hgeometry/src/HGeometry/LowerEnvelope/VertexForm.hs +++ b/hgeometry/src/HGeometry/Plane/LowerEnvelope/VertexForm.hs @@ -1,7 +1,7 @@ {-# LANGUAGE UndecidableInstances #-} -------------------------------------------------------------------------------- -- | --- Module : HGeometry.LowerEnvelope.VertexForm +-- Module : HGeometry.Plane.LowerEnvelope.VertexForm -- Copyright : (C) Frank Staals -- License : see the LICENSE file -- Maintainer : Frank Staals @@ -10,7 +10,7 @@ -- i.e. storing only the vertices. -- -------------------------------------------------------------------------------- -module HGeometry.LowerEnvelope.VertexForm +module HGeometry.Plane.LowerEnvelope.VertexForm ( VertexForm(VertexForm) , hasVertices, vertices' , singleton @@ -31,7 +31,7 @@ import HGeometry.Combinatorial.Util import HGeometry.HyperPlane.NonVertical import HGeometry.Intersection import HGeometry.Line -import HGeometry.LowerEnvelope.Type +import HGeometry.Plane.LowerEnvelope.Type import HGeometry.Point import HGeometry.Properties import Hiraffe.Graph diff --git a/hgeometry/src/HGeometry/PlaneGraph/Class.hs b/hgeometry/src/HGeometry/PlaneGraph/Class.hs index 313008613..6ca4b61e1 100644 --- a/hgeometry/src/HGeometry/PlaneGraph/Class.hs +++ b/hgeometry/src/HGeometry/PlaneGraph/Class.hs @@ -28,7 +28,6 @@ module HGeometry.PlaneGraph.Class import Control.Lens import Data.Coerce -import Data.Default.Class import Data.Foldable1 import Data.Functor.Apply import Data.Maybe (fromMaybe) @@ -234,9 +233,9 @@ polygonFromFace :: forall planeGraph vertex r.( PlaneGraph_ planeGraph vert -> SimplePolygon (vertex :+ VertexIx planeGraph) polygonFromFace gr fi = poly'&vertices.extra %~ coerce where - poly' :: SimplePolygon (vertex :+ NoDefault (VertexIx planeGraph)) + poly' :: SimplePolygon (vertex :+ VertexIx planeGraph) poly' = uncheckedFromCCWPoints - . fmap (\vi -> gr^?!vertexAt vi :+ NoDefault vi) + . fmap (\vi -> gr^?!vertexAt vi :+ vi) $ boundaryVertices fi gr -- note that this is safe, since boundaryVerticesOf guarantees that for -- interior faces, the vertices are returned in CCW order. @@ -264,13 +263,6 @@ interiorFacePolygonAt fi = theFold draw _ = let poly = polygonFromFace gr fi in poly >$ indexed pPolyFPoly fi poly - -newtype NoDefault e = NoDefault e - -instance Default (NoDefault e) where - def = undefined - - -------------------------------------------------------------------------------- -- | get the minimum of the elements the lens points to using the given comparison function diff --git a/hgeometry/src/HGeometry/PolyLine.hs b/hgeometry/src/HGeometry/PolyLine.hs index eff6e9f93..0cb11e2db 100644 --- a/hgeometry/src/HGeometry/PolyLine.hs +++ b/hgeometry/src/HGeometry/PolyLine.hs @@ -18,25 +18,21 @@ module HGeometry.PolyLine ) where -import Control.DeepSeq (NFData) -import Control.Lens --- import qualified Data.Foldable as F -import Data.Functor.Classes --- import qualified Data.List.NonEmpty as NonEmpty -import Data.Semigroup.Foldable -import Data.Vector.NonEmpty.Internal (NonEmptyVector(..)) --- import qualified Data.Vector.NonEmpty as NV -import GHC.Generics -import HGeometry.Box -import HGeometry.Point -import HGeometry.Foldable.Util -import HGeometry.PolyLine.Class -import HGeometry.Interval.Class -import HGeometry.Properties -import HGeometry.Transformation --- import HGeometry.Vector -import HGeometry.Vector.NonEmpty.Util () -import Hiraffe.Graph +import Control.DeepSeq (NFData) +import Control.Lens +import Data.Functor.Classes +import Data.Semigroup.Foldable +import Data.Vector.NonEmpty.Internal (NonEmptyVector(..)) +import GHC.Generics +import HGeometry.Box +import HGeometry.Foldable.Util +import HGeometry.Interval.Class +import HGeometry.Point +import HGeometry.PolyLine.Class +import HGeometry.Properties +import HGeometry.Transformation +import HGeometry.Vector.NonEmpty.Util () +import Hiraffe.Graph -------------------------------------------------------------------------------- @@ -124,4 +120,12 @@ instance ( Traversable1 f , Point_ point d r , TraversableWithIndex Int f ) => PolyLine_ (PolyLineF f point) point where + +instance ( Traversable1 f + , IxValue (f point) ~ point, Index (f point) ~ Int + , Ixed (f point) + , HasFromFoldable1 f + , Point_ point d r + , TraversableWithIndex Int f + ) => ConstructablePolyLine_ (PolyLineF f point) point where polyLineFromPoints = PolyLine . fromFoldable1 diff --git a/hgeometry/src/HGeometry/PolyLine/Class.hs b/hgeometry/src/HGeometry/PolyLine/Class.hs index d53731c9e..dcb7c6013 100644 --- a/hgeometry/src/HGeometry/PolyLine/Class.hs +++ b/hgeometry/src/HGeometry/PolyLine/Class.hs @@ -10,23 +10,17 @@ -------------------------------------------------------------------------------- module HGeometry.PolyLine.Class ( PolyLine_(..) + , ConstructablePolyLine_(..) , _PolyLineLineSegment ) where import Control.Lens --- import Control.Lens.Internal.Fold (NonEmptyDList(..)) --- import Data.Functor.Apply (Apply) --- import Data.Functor.Contravariant (phantom) import qualified Data.List.NonEmpty as NonEmpty --- import Data.Maybe (fromMaybe) import Data.Semigroup.Foldable import HGeometry.LineSegment.Class import HGeometry.Point.Class import HGeometry.Properties --- import HGeometry.Vector.Class import Hiraffe.Graph --- import Data.Function (on) --- import Data.Semigroup (First(..)) -------------------------------------------------------------------------------- @@ -41,6 +35,9 @@ class ( HasVertices polyLine polyLine , Dimension polyLine ~ Dimension point ) => PolyLine_ polyLine point | polyLine -> point where +-- | Class for constructable polylglines +class PolyLine_ polyLine point => ConstructablePolyLine_ polyLine point where + -- | Constructs a polyline from a given sequence of points. -- -- pre: there should be at least two distinct points @@ -50,12 +47,13 @@ class ( HasVertices polyLine polyLine -- maybe make these two functions into a prism instead -- | Prism between a polyline and a line segment -_PolyLineLineSegment :: ( LineSegment_ lineSegment point - , PolyLine_ polyLine point +_PolyLineLineSegment :: ( ConstructableLineSegment_ lineSegment point + , ConstructablePolyLine_ polyLine point ) => Prism' polyLine lineSegment _PolyLineLineSegment = prism' lineSegmentToPolyLine polyLineToLineSegment where lineSegmentToPolyLine s = polyLineFromPoints . NonEmpty.fromList $ [s^.start, s^.end] polyLineToLineSegment pl - | lengthOf vertices pl == 2 = Just $ uncheckedLineSegment (pl^.start) (pl^.end) | otherwise = Nothing + | lengthOf vertices pl == 2 = Just $ uncheckedLineSegment (pl^.start) (pl^.end) + | otherwise = Nothing diff --git a/hgeometry/src/HGeometry/Polygon/Convex/MinkowskiSum.hs b/hgeometry/src/HGeometry/Polygon/Convex/MinkowskiSum.hs index 00d3789bd..884ea3d2e 100644 --- a/hgeometry/src/HGeometry/Polygon/Convex/MinkowskiSum.hs +++ b/hgeometry/src/HGeometry/Polygon/Convex/MinkowskiSum.hs @@ -15,7 +15,6 @@ module HGeometry.Polygon.Convex.MinkowskiSum ) where import Control.Lens -import Data.Default.Class import Data.List.NonEmpty (NonEmpty(..)) import Data.Ord (comparing) import HGeometry.Ext @@ -38,7 +37,6 @@ import HGeometry.Polygon.Simple.Class minkowskiSum :: ( Ord r, Num r , ConvexPolygon_ convexPolygon point r , ConvexPolygon_ convexPolygon' point' r - , Default point' ) => convexPolygon -> convexPolygon' -> ConvexPolygon (point :+ point') diff --git a/hgeometry/src/HGeometry/Polygon/Simple/Class.hs b/hgeometry/src/HGeometry/Polygon/Simple/Class.hs index fa2695d0a..7fafe3ae2 100644 --- a/hgeometry/src/HGeometry/Polygon/Simple/Class.hs +++ b/hgeometry/src/HGeometry/Polygon/Simple/Class.hs @@ -55,7 +55,7 @@ class ( Polygon_ simplePolygon point r -- | Compute the centroid of a simple polygon. -- -- running time: \(O(n)\) - centroid :: Fractional r => simplePolygon -> point + centroid :: (Fractional r, ConstructablePoint_ point' 2 r) => simplePolygon -> point' centroid poly = fromVector $ sum' xs ^/ (6 * signedArea poly) where xs = [ (p^.vector ^+^ q^.vector) ^* (p^.xCoord * q^.yCoord - q^.xCoord * p^.yCoord) diff --git a/hgeometry/src/HGeometry/Polygon/Triangulation/MakeMonotone.hs b/hgeometry/src/HGeometry/Polygon/Triangulation/MakeMonotone.hs index ed0133bc9..58c0e8ba9 100644 --- a/hgeometry/src/HGeometry/Polygon/Triangulation/MakeMonotone.hs +++ b/hgeometry/src/HGeometry/Polygon/Triangulation/MakeMonotone.hs @@ -15,7 +15,6 @@ module HGeometry.Polygon.Triangulation.MakeMonotone ) where import Control.Lens -import Data.Default.Class import qualified Data.Map as Map import Data.Ord (Down (..), comparing) import qualified Data.Set as Set @@ -51,7 +50,7 @@ makeMonotone pg = constructGraph pg (computeDiagonals pg) -- -- running time: \(O(n\log n)\) computeDiagonals :: ( Polygon_ polygon point r, Point_ point 2 r - , Ord r, Num r, Ord (VertexIx polygon), Default (VertexIx polygon) + , Ord r, Num r, Ord (VertexIx polygon) ) => polygon -> [Diagonal polygon] computeDiagonals pg = @@ -91,7 +90,6 @@ p `cmpSweep` q = comparing (^.yCoord) p q <> comparing (Down . (^.xCoord)) p q -- | Handle an event handle :: forall polygon point r. ( Polygon_ polygon point r , Point_ point 2 r, Num r, Ord r - , Default (VertexIx polygon) , Ord (VertexIx polygon) ) => polygon diff --git a/hgeometry/src/HGeometry/Polygon/Triangulation/Types.hs b/hgeometry/src/HGeometry/Polygon/Triangulation/Types.hs index 47f5ecffa..1a6ba0cb3 100644 --- a/hgeometry/src/HGeometry/Polygon/Triangulation/Types.hs +++ b/hgeometry/src/HGeometry/Polygon/Triangulation/Types.hs @@ -18,7 +18,6 @@ import HGeometry.Point import HGeometry.Polygon.Class import HGeometry.Polygon.Simple.Class import HGeometry.Vector -import Hiraffe.Graph.Class import Hiraffe.PlanarGraph as PlanarGraph -- import qualified Data.Foldable as F diff --git a/hgeometry/src/HGeometry/VoronoiDiagram/ViaLowerEnvelope.hs b/hgeometry/src/HGeometry/VoronoiDiagram/ViaLowerEnvelope.hs index db9129099..2744c1003 100644 --- a/hgeometry/src/HGeometry/VoronoiDiagram/ViaLowerEnvelope.hs +++ b/hgeometry/src/HGeometry/VoronoiDiagram/ViaLowerEnvelope.hs @@ -20,7 +20,6 @@ module HGeometry.VoronoiDiagram.ViaLowerEnvelope ) where import Control.Lens -import Data.Default.Class import Data.Foldable1 import qualified Data.Set as Set import HGeometry.Box @@ -28,9 +27,9 @@ import HGeometry.Duality import HGeometry.Ext import HGeometry.HyperPlane.Class import HGeometry.HyperPlane.NonVertical -import HGeometry.LowerEnvelope.AdjListForm -import HGeometry.LowerEnvelope.Naive (lowerEnvelopeVertexForm) -import HGeometry.LowerEnvelope.VertexForm (VertexForm, vertices') +import HGeometry.Plane.LowerEnvelope.AdjListForm +import HGeometry.Plane.LowerEnvelope.Naive (lowerEnvelopeVertexForm) +import HGeometry.Plane.LowerEnvelope.VertexForm (VertexForm, vertices') import HGeometry.Point import HGeometry.Properties @@ -86,7 +85,7 @@ instance (Ord (NumType point), Num (NumType point)) => IsBoxable (VoronoiDiagram -- the lower envelope of these planes. -- -- \(O(n\log n)\) -voronoiDiagram :: ( Point_ point 2 r, Functor f, Default point, Ord point +voronoiDiagram :: ( Point_ point 2 r, Functor f, Ord point , Ord r, Fractional r, Foldable1 f , Show point, Show r ) => f point -> VoronoiDiagram point @@ -98,14 +97,13 @@ voronoiDiagram pts = case lowerEnvelope' . fmap (\p -> liftPointToPlane p :+ p) getPoint = view (_Wrapped'.extra.to ColinearPoint) -- | Computes all voronoi vertices -voronoiVertices :: ( Point_ point 2 r, Functor f, Default point, Ord point +voronoiVertices :: ( Point_ point 2 r, Functor f, Ord point , Ord r, Fractional r, Foldable f ) => f point -> [Point 2 r] voronoiVertices = map (projectPoint . fst) . itoListOf vertices' . upperEnvelopeVertexForm . fmap (\p -> liftPointToPlane p :+ p) --- FIXME: get rid of the default point constraint -- FIXME: get rid of the ord point constraint -- | Computes the vertex form of the upper envelope. The z-coordinates are still flipped. @@ -120,7 +118,7 @@ upperEnvelopeVertexForm = lowerEnvelopeVertexForm . fmap flipZ -------------------------------------------------------------------------------- -- | Get the halflines and line segments representing the VoronoiDiagram -edgeGeometries :: (Point_ point 2 r, Ord r, Fractional r, Default point +edgeGeometries :: (Point_ point 2 r, Ord r, Fractional r , Show point, Show r ) diff --git a/hgeometry/test-with-ipe/test/HalfPlane/CommonIntersectionSpec.hs b/hgeometry/test-with-ipe/test/HalfPlane/CommonIntersectionSpec.hs index a67133e28..d85bc3a04 100644 --- a/hgeometry/test-with-ipe/test/HalfPlane/CommonIntersectionSpec.hs +++ b/hgeometry/test-with-ipe/test/HalfPlane/CommonIntersectionSpec.hs @@ -3,7 +3,6 @@ module HalfPlane.CommonIntersectionSpec(spec) where import Control.Lens hiding (below) import Control.Monad ((>=>)) -import Data.Default.Class import qualified Data.Foldable as F import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NonEmpty @@ -132,11 +131,6 @@ rightOf = HalfSpace Positive . VerticalLineThrough -------------------------------------------------------------------------------- --- FIXME: this instance does not really make sene I think, but whatever -instance Num r => Default (HalfPlane r) where - def = HalfSpace Negative (VerticalLineThrough 0) -instance Num r => Default (LineEQ r) where - def = LineEQ 1 0 -------------------------------------------------------------------------------- diff --git a/hgeometry/test-with-ipe/test/Line/LowerEnvelopeSpec.hs b/hgeometry/test-with-ipe/test/Line/LowerEnvelopeSpec.hs index 3a5aad88b..0c2120ea3 100644 --- a/hgeometry/test-with-ipe/test/Line/LowerEnvelopeSpec.hs +++ b/hgeometry/test-with-ipe/test/Line/LowerEnvelopeSpec.hs @@ -3,7 +3,6 @@ module Line.LowerEnvelopeSpec(spec) where import Control.Lens hiding (below) import Control.Monad ((>=>)) -import Data.Default.Class import Data.Foldable (minimumBy) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NonEmpty @@ -88,7 +87,3 @@ theAnswer2 = LowerEnvelope ) -------------------------------------------------------------------------------- - --- FIXME: hack -instance Num r => Default (LineEQ r) where - def = LineEQ 1 0 diff --git a/hgeometry/test-with-ipe/test/PlaneGraph/RenderSpec.hs b/hgeometry/test-with-ipe/test/PlaneGraph/RenderSpec.hs index caa710ff2..af3f67767 100644 --- a/hgeometry/test-with-ipe/test/PlaneGraph/RenderSpec.hs +++ b/hgeometry/test-with-ipe/test/PlaneGraph/RenderSpec.hs @@ -98,7 +98,7 @@ spec = describe "render planegraph tests" $ do drawGraph :: ( PlaneGraph_ planeGraph vertex , IsTransformable vertex - , Point_ vertex 2 r, Ord r, Real r + , ConstructablePoint_ vertex 2 r, Ord r, Real r , Fractional r, Show r, Eq (FaceIx planeGraph) , Show (Vertex planeGraph), Show (Dart planeGraph), Show (Face planeGraph) , Show (EdgeIx planeGraph) @@ -117,7 +117,7 @@ drawVertex _ v = [ iO $ ipeDiskMark (v^.asPoint) ! attr SLayer "vertex" -- ! attr SStroke Ipe.red ] -drawEdge :: ( PlaneGraph_ planeGraph vertex, Point_ vertex 2 r, IsTransformable vertex +drawEdge :: ( PlaneGraph_ planeGraph vertex, ConstructablePoint_ vertex 2 r, IsTransformable vertex , Show (EdgeIx planeGraph), Fractional r, Real r) => planeGraph -> EdgeIx planeGraph -> ClosedLineSegment vertex -> [IpeObject r] drawEdge gr d s = [ iO $ ipeLineSegment s ! attr SLayer "edges" @@ -127,7 +127,7 @@ drawEdge gr d s = [ iO $ ipeLineSegment s ! attr SLayer "edges" c = interpolate 0.5 s ^. asPoint -drawDart :: ( PlaneGraph_ planeGraph vertex, Point_ vertex 2 r, IsTransformable vertex +drawDart :: ( PlaneGraph_ planeGraph vertex, ConstructablePoint_ vertex 2 r, IsTransformable vertex , Show (Dart planeGraph), Fractional r, Real r) => planeGraph -> DartIx planeGraph -> ClosedLineSegment vertex -> [IpeObject r] drawDart gr d s = [ iO $ ipeLineSegment (offset s) diff --git a/hgeometry/test-with-ipe/test/Polygon/Convex/ConvexSpec.hs b/hgeometry/test-with-ipe/test/Polygon/Convex/ConvexSpec.hs index 54fa6cc18..dc2b316cf 100644 --- a/hgeometry/test-with-ipe/test/Polygon/Convex/ConvexSpec.hs +++ b/hgeometry/test-with-ipe/test/Polygon/Convex/ConvexSpec.hs @@ -6,7 +6,6 @@ module Polygon.Convex.ConvexSpec import Control.Arrow ((&&&)) import Control.Lens -import Data.Default.Class import qualified Data.List.NonEmpty as NonEmpty import Golden import HGeometry.ConvexHull.GrahamScan (convexHull) @@ -29,12 +28,6 @@ import Test.Hspec.WithTempFile type R = RealNumber 10 -instance Default (Point 2 R) where - def = origin - -instance Default (Point 2 Rational) where - def = origin - -------------------------------------------------------------------------------- spec :: Spec @@ -104,15 +97,16 @@ toSpec (TestCase poly) = do -------------------------------------------------------------------------------- -- | Center the given polygon at the origin. I.e. places the centroid at the origin. -centerAtOrigin :: ( SimplePolygon_ polygon point r +centerAtOrigin :: forall polygon point r. + ( SimplePolygon_ polygon point r , Fractional r , IsTransformable polygon ) => polygon -> polygon -centerAtOrigin pg = translateBy (origin .-. centroid pg) pg +centerAtOrigin pg = translateBy (origin .-. (centroid pg :: Point 2 r)) pg -------------------------------------------------------------------------------- -minkowskiTests :: (Fractional r, Ord r, Show r, Default (Point 2 r) +minkowskiTests :: (Fractional r, Ord r, Show r , IpeWriteText r ) => String -> [ConvexPolygon (Point 2 r)] -> Spec @@ -121,7 +115,7 @@ minkowskiTests s pgs = describe ("Minkowskisums on " ++ s) $ zip [0..] [ (p,centerAtOrigin q) | p <- pgs, q <- pgs ] -minkowskiTest :: ( Fractional r, Ord r, Show r, Default (Point 2 r) +minkowskiTest :: ( Fractional r, Ord r, Show r , IpeWriteText r ) => Int -> ConvexPolygon (Point 2 r) -> ConvexPolygon (Point 2 r) -> Spec @@ -160,7 +154,6 @@ instance (ShiftedEq b, Eq (ElemCyclic b)) => Eq (F a b) where naiveMinkowski :: ( Ord r, Num r , ConvexPolygon_ convexPolygon point r , ConvexPolygon_ convexPolygon' point' r - , Default point' ) => convexPolygon -> convexPolygon' -> ConvexPolygon (point :+ point') diff --git a/hgeometry/test-with-ipe/test/Polygon/Triangulation/TriangulateSpec.hs b/hgeometry/test-with-ipe/test/Polygon/Triangulation/TriangulateSpec.hs index b6b803d96..568db5728 100644 --- a/hgeometry/test-with-ipe/test/Polygon/Triangulation/TriangulateSpec.hs +++ b/hgeometry/test-with-ipe/test/Polygon/Triangulation/TriangulateSpec.hs @@ -58,7 +58,7 @@ spec = describe "triangulateSpec" $ do _drawGraph :: ( PlaneGraph_ planeGraph vertex , IsTransformable vertex - , Point_ vertex 2 r, Ord r, Real r, Fractional r, Show r, Eq (FaceIx planeGraph) + , ConstructablePoint_ vertex 2 r, Ord r, Real r, Fractional r, Show r, Eq (FaceIx planeGraph) , Show (Vertex planeGraph), Show (Dart planeGraph), Show (Face planeGraph) , Show (EdgeIx planeGraph) ) => planeGraph -> [IpeObject r] diff --git a/hgeometry/test-with-ipe/test/VoronoiDiagram/VoronoiSpec.hs b/hgeometry/test-with-ipe/test/VoronoiDiagram/VoronoiSpec.hs index a2b85109d..95d46591b 100644 --- a/hgeometry/test-with-ipe/test/VoronoiDiagram/VoronoiSpec.hs +++ b/hgeometry/test-with-ipe/test/VoronoiDiagram/VoronoiSpec.hs @@ -6,15 +6,14 @@ module VoronoiDiagram.VoronoiSpec ) where import Control.Lens -import Data.Default.Class import Golden -- import HGeometry.Combinatorial.Util import HGeometry.Duality import HGeometry.Ext import HGeometry.HyperPlane.Class import HGeometry.HyperPlane.NonVertical -import HGeometry.LowerEnvelope -import HGeometry.LowerEnvelope.AdjListForm +import HGeometry.Plane.LowerEnvelope +import HGeometry.Plane.LowerEnvelope.AdjListForm import qualified Data.Set as Set import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Sequence as Seq @@ -104,7 +103,7 @@ grow d (Box p q) = Box (p&coordinates %~ subtract d) (q&coordinates %~ (+d)) -instance (HasDefaultIpeOut point, Point_ point 2 r, Fractional r, Ord r, Default point +instance (HasDefaultIpeOut point, Point_ point 2 r, Fractional r, Ord r , Show r, Show point ) => HasDefaultIpeOut (VoronoiDiagram point) where @@ -114,7 +113,7 @@ instance (HasDefaultIpeOut point, Point_ point 2 r, Fractional r, Ord r, Default ConnectedVD vd -> defIO vd -instance (HasDefaultIpeOut point, Point_ point 2 r, Fractional r, Ord r, Default point +instance (HasDefaultIpeOut point, Point_ point 2 r, Fractional r, Ord r , Show r, Show point ) => HasDefaultIpeOut (VoronoiDiagram' point) where @@ -126,10 +125,6 @@ instance (HasDefaultIpeOut point, Point_ point 2 r, Fractional r, Ord r, Default Left hl -> iO $ ipeHalfLineIn bRect hl Right seg -> iO' seg - -instance Default (Point 2 R) where - def = error "not def" - inputs :: [Point 2 R] inputs = [origin, Point2 10 10, Point2 10 0] diff --git a/hgeometry/test/LowerEnvelope/NaiveSpec.hs b/hgeometry/test/LowerEnvelope/NaiveSpec.hs index 535e25bc9..647e408e5 100644 --- a/hgeometry/test/LowerEnvelope/NaiveSpec.hs +++ b/hgeometry/test/LowerEnvelope/NaiveSpec.hs @@ -8,8 +8,8 @@ import HGeometry.Combinatorial.Util import HGeometry.HyperPlane.Class import HGeometry.HyperPlane.NonVertical import HGeometry.Instances () -import HGeometry.LowerEnvelope -import HGeometry.LowerEnvelope.VertexForm +import HGeometry.Plane.LowerEnvelope +import HGeometry.Plane.LowerEnvelope.VertexForm import HGeometry.Number.Real.Rational import HGeometry.Point import HGeometry.Vector diff --git a/hgeometry/test/Polygon/Convex/ConvexSpec.hs b/hgeometry/test/Polygon/Convex/ConvexSpec.hs index ca9b8fddc..33582febf 100644 --- a/hgeometry/test/Polygon/Convex/ConvexSpec.hs +++ b/hgeometry/test/Polygon/Convex/ConvexSpec.hs @@ -4,7 +4,6 @@ module Polygon.Convex.ConvexSpec import Control.Lens hiding (elements) import Control.Monad.State -import Data.Default.Class import qualified Data.List.NonEmpty as NonEmpty import HGeometry.Boundary import HGeometry.Box @@ -34,8 +33,6 @@ import Test.QuickCheck.Instances () -- type R = RealNumber 10 -instance Default (Point 2 Rational) where - def = origin instance Arbitrary (ConvexPolygon (Point 2 Rational)) where arbitrary = let granularity = 1000000 in sized $ \n -> do @@ -148,17 +145,17 @@ spec = describe "Convex Polygon tests" $ do -------------------------------------------------------------------------------- -- | Center the given polygon at the origin. I.e. places the centroid at the origin. -centerAtOrigin :: ( SimplePolygon_ polygon point r +centerAtOrigin :: forall polygon point r. + ( SimplePolygon_ polygon point r , Fractional r , IsTransformable polygon ) => polygon -> polygon -centerAtOrigin pg = translateBy (origin .-. centroid pg) pg +centerAtOrigin pg = translateBy (origin .-. (centroid pg :: Point 2 r)) pg naiveMinkowski :: ( Ord r, Num r , ConvexPolygon_ convexPolygon point r , ConvexPolygon_ convexPolygon' point' r - , Default point' ) => convexPolygon -> convexPolygon' -> ConvexPolygon (point :+ point') diff --git a/hgeometry/test/Polygon/Triangulation/MakeMonotoneSpec.hs b/hgeometry/test/Polygon/Triangulation/MakeMonotoneSpec.hs index e53555dc3..a022c5685 100644 --- a/hgeometry/test/Polygon/Triangulation/MakeMonotoneSpec.hs +++ b/hgeometry/test/Polygon/Triangulation/MakeMonotoneSpec.hs @@ -1,7 +1,6 @@ module Polygon.Triangulation.MakeMonotoneSpec where import Control.Lens -import Data.Default.Class import Data.Maybe (fromJust) import qualified Data.Set as Set import HGeometry.Ext @@ -40,10 +39,6 @@ spec = describe "GeomBook Example" $ do seg2 = ClosedLineSegment (Point2 16 25) (Point2 13 23) cmpX q seg2 `shouldBe` EQ - -instance Default VertexType where - def = Regular - sort' :: Ord a => Vector 2 a-> Vector 2 a sort' (Vector2 x y) = Vector2 (min x y) (max x y)