Improve intersection test--fails sometimes
This commit is contained in:
@@ -14,23 +14,21 @@ import Geometry.Vector
|
||||
import Geometry.LHS
|
||||
import Geometry.Intersect
|
||||
|
||||
import Data.Maybe
|
||||
import Control.Lens
|
||||
import qualified Control.Foldl as L
|
||||
data ConvexPoly = ConvexPoly
|
||||
{ _cpPoints :: [Point2]
|
||||
, _cpCen :: Point2
|
||||
, _cpCen :: Point2
|
||||
, _cpRad :: Float
|
||||
}
|
||||
pointsToPoly :: [Point2] -> ConvexPoly
|
||||
pointsToPoly xs = ConvexPoly
|
||||
{ _cpPoints = xs
|
||||
, _cpCen = cen
|
||||
, _cpCen = cen
|
||||
, _cpRad = minimum $ map (dist cen) xs
|
||||
}
|
||||
where
|
||||
cen = centroid xs
|
||||
|
||||
-- | Test whether two polygons intersect or if one is contained in the other.
|
||||
convexPolysOverlap :: ConvexPoly -> ConvexPoly -> Bool
|
||||
convexPolysOverlap cp1 cp2 = dist (_cpCen cp1) (_cpCen cp2) < _cpRad cp1 + _cpRad cp2
|
||||
@@ -64,10 +62,8 @@ polyPointsIntersect _ _ = False
|
||||
pairPolyPointsIntersect :: Point2 -> Point2 -> [Point2] -> Bool
|
||||
pairPolyPointsIntersect a' b' (c':d':xs') = go c' a' b' (c':d':xs')
|
||||
where
|
||||
go x a b (c:d:xs)
|
||||
| isJust $ myIntersectSegSeg a b c d = True
|
||||
| otherwise = go x a b (d:xs)
|
||||
go d a b [c] = isJust $ myIntersectSegSeg a b c d
|
||||
go x a b (c:d:xs) = intersectSegSegTest a b c d || go x a b (d:xs)
|
||||
go d a b [c] = intersectSegSegTest a b c d
|
||||
go _ _ _ _ = False
|
||||
pairPolyPointsIntersect _ _ _ = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user