Commit before attempting to allow for non-convex chasm shapes
This commit is contained in:
@@ -83,14 +83,17 @@ intersectSegSeg (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
|
||||
{- | Intended to intersect a segment with a half-line-segment, ie a segment
|
||||
extending infinitely in one direction.
|
||||
Will intersect with the first endpoint of the segment, but NOT the second.
|
||||
This is to allow sensible intersections with polygons described as lists of points.
|
||||
It will also intersect with the point of the ray.
|
||||
-}
|
||||
intersectSegLineFrom :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectSegLineFrom #-}
|
||||
intersectSegLineFrom (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
intersectSegRay :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectSegRay #-}
|
||||
intersectSegRay (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
| den == 0 = Nothing
|
||||
| den > 0 && (t' < 0 || u' < 0 || t' > den) =
|
||||
| den > 0 && (t' < 0 || u' < 0 || t' >= den) =
|
||||
Nothing
|
||||
| den < 0 && (t' > 0 || u' > 0 || t' < den) =
|
||||
| den < 0 && (t' > 0 || u' > 0 || t' <= den) =
|
||||
Nothing
|
||||
| otherwise = Just $ V2 (x1 + (x2 - x1) * t' / den) (y1 + (y2 - y1) * t' / den)
|
||||
where
|
||||
@@ -114,18 +117,20 @@ intersectSegLineext (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
u' = (y1 - y2) * (x1 - x3) - (x1 - x2) * (y1 - y3)
|
||||
|
||||
-- | Intersect a segment with a line.
|
||||
-- the line intersects with the first endpoint of the segment
|
||||
-- but NOT the second
|
||||
intersectSegLine :: Point2 -> Point2 -> Point2 -> Point2 -> Maybe Point2
|
||||
{-# INLINE intersectSegLine #-}
|
||||
intersectSegLine (V2 x1 y1) (V2 x2 y2) (V2 x3 y3) (V2 x4 y4)
|
||||
| den == 0 = Nothing
|
||||
| den > 0 && (t' < 0 || t' > den) =
|
||||
| den > 0 && (t < 0 || t >= den) =
|
||||
Nothing
|
||||
| den < 0 && (t' > 0 || t' < den) =
|
||||
| den < 0 && (t > 0 || t <= den) =
|
||||
Nothing
|
||||
| otherwise = Just $ V2 (x1 + (x2 - x1) * t' / den) (y1 + (y2 - y1) * t' / den)
|
||||
| otherwise = Just $ V2 (x1 + (x2 - x1) * t / den) (y1 + (y2 - y1) * t / den)
|
||||
where
|
||||
den = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
|
||||
t' = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
|
||||
t = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)
|
||||
|
||||
--u' = (y1-y2)*(x1-x3) - (x1-x2)*(y1-y3)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user