Define room link datatypes

This commit is contained in:
2021-11-23 13:00:34 +00:00
parent f51a6a7216
commit 67b0d694af
6 changed files with 25 additions and 14 deletions
+5 -5
View File
@@ -168,14 +168,14 @@ gameRoomFromRoom rm = GameRoom
[p +.+ 10 *.* unitVectorAtAngle a [p +.+ 10 *.* unitVectorAtAngle a
,p -.- 10 *.* unitVectorAtAngle a ,p -.- 10 *.* unitVectorAtAngle a
] ]
unpos (OutLink _ p a) = doubleShift p a unpos (UsedOutLink _ p a) = doubleShift p a
unpos (InLink p a) = doubleShift p a unpos (UsedInLink p a) = doubleShift p a
unpos _ = [] unpos _ = []
undir (OutLink _ _ a) = Just $ 0.5*pi + a + snd (_rmShift rm) undir (UsedOutLink _ _ a) = Just $ 0.5*pi + a + snd (_rmShift rm)
undir (InLink _ a) = Just $ 0.5*pi + a + snd (_rmShift rm) undir (UsedInLink _ a) = Just $ 0.5*pi + a + snd (_rmShift rm)
undir _ = Nothing undir _ = Nothing
closePoints x y = roundPoint2 x == roundPoint2 y closePoints x y = roundPoint2 x == roundPoint2 y
getDir (InLink _ a:_) = a + snd (_rmShift rm) getDir (UsedInLink _ a:_) = a + snd (_rmShift rm)
getDir (_:xs) = getDir xs getDir (_:xs) = getDir xs
getDir _ = 0 -- fallback getDir _ = 0 -- fallback
+13 -2
View File
@@ -82,12 +82,23 @@ data Room = Room
, _rmStartWires :: IM.IntMap RoomWire , _rmStartWires :: IM.IntMap RoomWire
, _rmEndWires :: IM.IntMap RoomWire , _rmEndWires :: IM.IntMap RoomWire
} }
data RoomLink = RoomLink
{ _rlType :: RoomLinkType
, _rlPos :: Point2
, _rlDir :: Float
} deriving (Eq,Ord)
data RoomLinkType
= OutLink
| InLink
| AnyLink
| LabLink Int
deriving (Eq,Ord)
data RoomWire data RoomWire
= --RoomWire Point2 Float = --RoomWire Point2 Float
WallWire Point2 Float Float WallWire Point2 Float Float
data RoomPos data RoomPos
= OutLink Int Point2 Float = UsedOutLink Int Point2 Float
| InLink Point2 Float | UsedInLink Point2 Float
| UnusedLink Point2 Float | UnusedLink Point2 Float
| PosPl Point2 Float | PosPl Point2 Float
| LabPos Int RoomPos | LabPos Int RoomPos
+3 -3
View File
@@ -15,13 +15,13 @@ anyLnkOutPS = PSPos f (const id) Nothing
atFstLnkOut :: PlacementSpot atFstLnkOut :: PlacementSpot
atFstLnkOut = PSPos f (const id) Nothing atFstLnkOut = PSPos f (const id) Nothing
where where
f (OutLink 0 p a) = Just (PS p a, OutLink 0 p a) f (UsedOutLink 0 p a) = Just (PS p a, UsedOutLink 0 p a)
f _ = Nothing f _ = Nothing
atNthLnkOutShiftBy :: Int -> ((Point2,Float) -> (Point2,Float)) -> PlacementSpot atNthLnkOutShiftBy :: Int -> ((Point2,Float) -> (Point2,Float)) -> PlacementSpot
atNthLnkOutShiftBy n theshift = PSPos f (const id) Nothing atNthLnkOutShiftBy n theshift = PSPos f (const id) Nothing
where where
f (OutLink i p a) | n == i = Just (PS p' a', OutLink n p a) f (UsedOutLink i p a) | n == i = Just (PS p' a', UsedOutLink n p a)
where where
(p',a') = theshift (p,a) (p',a') = theshift (p,a)
f _ = Nothing f _ = Nothing
@@ -40,7 +40,7 @@ atNthLnkOutShiftInward n x = atNthLnkOutShiftBy n f
overFstLnkOut :: PlacementSpot overFstLnkOut :: PlacementSpot
overFstLnkOut = PSPos f (const id) Nothing overFstLnkOut = PSPos f (const id) Nothing
where where
f (OutLink 0 p a) = Just (PS p a, PosPl p a) f (UsedOutLink 0 p a) = Just (PS p a, PosPl p a)
f _ = Nothing f _ = Nothing
anyLnkInPS :: Float -- ^ amount to shift inward anyLnkInPS :: Float -- ^ amount to shift inward
+1 -1
View File
@@ -140,7 +140,7 @@ finalLinksUpdate :: Room -> Room
finalLinksUpdate rm = case _rmLinks rm of finalLinksUpdate rm = case _rmLinks rm of
(_:_) -> rm (_:_) -> rm
& rmLinks %~ init & rmLinks %~ init
& rmPos %~ ( (uncurry InLink (last thelnks) :) . (map (uncurry UnusedLink) (init thelnks) ++) ) & rmPos %~ ( (uncurry UsedInLink (last thelnks) :) . (map (uncurry UnusedLink) (init thelnks) ++) )
_ -> rm _ -> rm
where where
thelnks = _rmLinks rm thelnks = _rmLinks rm
+2 -2
View File
@@ -4,8 +4,8 @@ import Geometry
extractRoomPos :: RoomPos -> (Point2,Float) extractRoomPos :: RoomPos -> (Point2,Float)
extractRoomPos rp = case rp of extractRoomPos rp = case rp of
OutLink _ p a -> (p,a) UsedOutLink _ p a -> (p,a)
InLink p a -> (p,a) UsedInLink p a -> (p,a)
UnusedLink p a -> (p,a) UnusedLink p a -> (p,a)
PosPl p a -> (p,a) PosPl p a -> (p,a)
LabPos _ rp' -> extractRoomPos rp' LabPos _ rp' -> extractRoomPos rp'
+1 -1
View File
@@ -53,7 +53,7 @@ posRms bounds parenti numChild (t@(Node childi _):ts) tseq = do
where where
convexBounds = map pointsToPoly $ _rmBound r' convexBounds = map pointsToPoly $ _rmBound r'
clipping = or (convexPolysOverlap <$> convexBounds <*> bounds) clipping = or (convexPolysOverlap <$> convexBounds <*> bounds)
upr rm = doLnkEff l $ rm & rmLinks %~ delete l & rmPos %~ (uncurry (OutLink numChild) l :) upr rm = doLnkEff l $ rm & rmLinks %~ delete l & rmPos %~ (uncurry (UsedOutLink numChild) l :)
l' = shiftLinkBy (_rmShift parent) l l' = shiftLinkBy (_rmShift parent) l
r' = doRoomShift . fst $ rootLabel shiftedt r' = doRoomShift . fst $ rootLabel shiftedt
shiftedt = applyToRoot (first $ shiftRoomShiftToLink l') t shiftedt = applyToRoot (first $ shiftRoomShiftToLink l') t