-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from fryguybob/wip/322
Attempt to fix some issues with Bezier intersections.
- Loading branch information
Showing
5 changed files
with
133 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
module Diagrams.Test.TwoD.Segment | ||
( | ||
tests | ||
) where | ||
|
||
import Test.Tasty (TestTree) | ||
import Test.Tasty.HUnit | ||
import Test.Tasty.QuickCheck | ||
import qualified Test.QuickCheck.Property as Q | ||
|
||
import Diagrams.Prelude | ||
import Diagrams.TwoD.Segment | ||
|
||
newtype InBox = InBox { unInBox :: Double } | ||
|
||
instance Arbitrary InBox where | ||
arbitrary = InBox <$> choose (-1, 1) | ||
|
||
instance Arbitrary (Point V2 Double) where | ||
arbitrary = curry p2 <$> (unInBox <$> arbitrary) | ||
<*> (unInBox <$> arbitrary) | ||
|
||
instance Arbitrary (FixedSegment V2 Double) where | ||
arbitrary = oneof [FLinear <$> arbitrary <*> arbitrary, FCubic <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary] | ||
|
||
epsT = 1.0e-9 -- parameter space epsilon | ||
epsE = 1.0e-8 -- Euclidean space epsilon | ||
|
||
x .=~. y = norm (x .-. y) < epsE | ||
|
||
tests :: [TestTree] | ||
tests = | ||
[ testProperty "segmentSegment" $ | ||
\a b -> validateIntersections a b (segmentSegment epsT a b) | ||
] | ||
|
||
validateIntersections :: FixedSegment V2 Double -> FixedSegment V2 Double -> [(Double, Double, P2 Double)] -> Q.Result | ||
validateIntersections a b [] = Q.rejected -- TODO: check for false negatives (rasterize both and look for overlap?) | ||
validateIntersections a b is = go is | ||
where | ||
go [] = Q.succeeded | ||
go ((ta,tb,p):is) | ||
| and [ 0 <= ta && ta <= 1 | ||
, 0 <= tb && tb <= 1 | ||
, a `atParam` ta .=~. p | ||
, b `atParam` tb .=~. p | ||
] = go is | ||
| otherwise = Q.failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{- From bug report by Mike Zuser (Issue #323): | ||
segmentSegment can fail to terminate on very specific and seemingly innocuous inputs | ||
-} | ||
|
||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
import Diagrams.Prelude | ||
import Diagrams.TwoD.Segment | ||
|
||
d = 72 -- ~ 71.9 to 72.1 | ||
r = d/64 -- ~ 64 to 64.0000001 | ||
e = 6.969e-8 -- ~ <= 6.969e-8 | ||
|
||
path :: Path V2 Double | ||
path = circle r # translateY d | ||
|
||
trails :: [Located (Trail V2 Double)] | ||
trails = head $ explodePath path | ||
|
||
(s0:s1:_) = map (head . fixTrail) trails | ||
|
||
bad = segmentSegment e s0 s1 | ||
|
||
-- Does not terminate or produce output. | ||
main = print bad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters