Skip to content

Commit

Permalink
compile with latest version of non-empty vector
Browse files Browse the repository at this point in the history
  • Loading branch information
noinia committed Nov 17, 2023
1 parent a915176 commit 139f1fd
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 14 deletions.
8 changes: 8 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ allow-newer:
miso:servant,
servant-lucid:servant,
lucid-svg:transformers,
-- servant:all,
-- lucid-svg:text,
-- hexpat:all,
-- pretty:all,
-- dlist:all,
-- aeson:all,
-- primitive:all,
-- vector-circular:primitive,

source-repository-package
type: git
Expand Down
2 changes: 1 addition & 1 deletion hgeometry-combinatorial/hgeometry-combinatorial.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ common setup
, vector >= 0.13 && < 1
, vector-builder >= 0.3.7 && < 1
, vector-algorithms >= 0.8 && < 1
, nonempty-vector >= 0.2.0.0 && < 1
, nonempty-vector >= 0.2.3 && < 1
, vector-circular >= 0.1.4 && < 1
, linear >= 1.20 && < 2
, HsYAML >= 0.2 && < 1
Expand Down
8 changes: 4 additions & 4 deletions hgeometry-combinatorial/src/HGeometry/Vector/NonEmpty/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ instance Ixed (NonEmptyVector a) where
ix i f (NonEmptyVector v) = NonEmptyVector <$> ix i f v
{-# INLINE ix #-}

instance Foldable1 NonEmptyVector where
foldMap1 f v = let (v',x) = NV.unsnoc v
in Vector.foldr (\x' a -> f x' <> a) (f x) v'
{-# INLINE foldMap1 #-}
-- instance Foldable1 NonEmptyVector where
-- foldMap1 f v = let (v',x) = NV.unsnoc v
-- in Vector.foldr (\x' a -> f x' <> a) (f x) v'
-- {-# INLINE foldMap1 #-}

instance Traversable1 NonEmptyVector where
traverse1 f (NonEmptyVector v) =
Expand Down
4 changes: 1 addition & 3 deletions hgeometry-examples/convexHull/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ data Action = Id
updateModel :: Model -> Action -> Effect Action Model
updateModel m = \case
Id -> noEff m
CanvasAction ca -> do
c' <- Canvas.handleInternalCanvasAction (m^.canvas) ca
pure $ m&canvas .~ c'
CanvasAction ca -> m&canvas %%~ flip Canvas.handleInternalCanvasAction ca
AddPoint -> addPoint
Select p -> noEff $ m&selected ?~ p
where
Expand Down
43 changes: 41 additions & 2 deletions hgeometry/kernel/src/HGeometry/Box.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module HGeometry.Box
) where

import Control.Lens
import Data.Maybe (isJust)
import HGeometry.Box.Boxable
import HGeometry.Box.Class
import HGeometry.Box.Corners
Expand All @@ -28,12 +29,14 @@ import HGeometry.Box.Sides
import HGeometry.HyperPlane.Class
import HGeometry.Intersection
import HGeometry.Interval
import HGeometry.Line.LineEQ
import HGeometry.Line.Class
import HGeometry.Line.LineEQ
import HGeometry.Line.PointAndVector
import HGeometry.LineSegment
import HGeometry.Point
import HGeometry.Properties
import HGeometry.Transformation
import HGeometry.Vector.Class

--------------------------------------------------------------------------------
-- $setup
Expand Down Expand Up @@ -132,5 +135,41 @@ instance ( Num r, Ord r
instance ( Fractional r, Ord r
, Point_ point 2 r
) => IsIntersectableWith (LinePV 2 r) (Rectangle point) where
(LinePV p v) `intersect` r = (fromPointAndVec @(LineEQ r) p v) `intersect` r
(LinePV p v) `intersect` r = fromPointAndVec @(LineEQ r) p v `intersect` r
{-# INLINE intersect #-}

--------------------------------------------------------------------------------
-- Box x Box intersection



type instance Intersection (Box point) (Box point) =
Maybe (Box (Point (Dimension point) (NumType point)))

-- TODO, maybe make this more precise:

-- data instance IntersectionOf (Box point) (Box point) =
-- Box_x_Box_Point point
-- | Box_x_Box_Segment (ClosedLineSegment point)
-- | Box_x_Box_Box (Box point)

-- instance (Ord r, Num r, Point_ point d r) => Box point `HasIntersectionWith` Box point where
-- a `intersects` b = isJust $ a `intersect` b

-- instance (Ord r, Num r, Point_ point d r) => Box point `IsIntersectableWith` Box point where
-- bx `intersect` bx' = fmap fromExtent' . sequence
-- $ liftI2 intersect (extent bx) (extent bx')
-- where
-- fromExtent' = fromExtent . \case
-- ClosedInterval_x_ClosedInterval_Point x -> ClosedInterval x x
-- ClosedInterval_x_ClosedInterval_Contained i -> i
-- ClosedInterval_x_ClosedInterval_Partial i -> i

-- fromExtent :: ( Vector_ vector d interval
-- , Point_ point d r
-- , ClosedInterval_ interval r
-- ) => vector -> Box point
-- fromExtent v = Box minP maxP
-- where
-- minP = undefined
-- maxP = undefined -- v^._Vector.components
4 changes: 4 additions & 0 deletions hgeometry/kernel/src/HGeometry/Box/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import Prelude hiding (zipWith)
import Text.Read

--------------------------------------------------------------------------------

-- | D-dimensional boxes.
--
-- A box is represented by two points; a point with lexicographically minimal coordinates,
-- and a point with lexicographically maximal coordinates.
newtype Box point = MkBox (Vector 2 point)
deriving stock (Generic)
deriving newtype (Eq,Ord)
Expand Down
4 changes: 1 addition & 3 deletions hgeometry/test-with-ipe/test/LineSegmentSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ getDataFileName' = decodeFS >=> getDataFileName >=> encodeFS


spec :: Spec
spec = testI
spec = pure ()
{-
describe "linesegment x box intersection tests" $ do
fp <- runIO $ getDataFileName' [osp|LineSegment/linesegmentBoxIntersections.ipe|]
ipeIntersectionTests fp
Expand All @@ -55,7 +54,6 @@ ipeIntersectionTests fp = do (segs,boxes) <- runIO $ (,) <$> readAllFrom fp <*>
(seg `intersects` (Boundary rect)) `shouldBe` (sameColor segAts rectAts && notOrange segAts )
-}

sameColor :: IpeAttributes Path R -> IpeAttributes Path R -> Bool
sameColor atsA atsB = atsA^?_Attr SStroke == atsB^?_Attr SStroke

Expand Down
8 changes: 7 additions & 1 deletion todo.org
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ consistent results
** TODO hgeometry
*** DONE convex polygon spec

* TODO box x box intersection
** TODO fromExtent to build a Box

* TODO renderer
* TODO ipe-renderer
* DONE test import
Expand All @@ -71,13 +74,16 @@ consistent results

* TODO Line segment intersection ; i.e Benthey Otham
** TODO the naive algorithm
*** TODO represent the various types of intersections
*** DONE represent the various types of intersections
*** TODO debug the onSideTest hyperplane function again

* TODO polygon triangulation
** DONE triangulate monotone
** TODO triangiulate non-monotone
*** TODO split into non-monotone parts
* TODO polyline simplification
** TODO imai iri
** TODO DP

* TODO arrangement
** TODO line-segment-intersection sweep
Expand Down

0 comments on commit 139f1fd

Please sign in to comment.