forked from diagrams/diagrams-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use trailPoints instead of trailVertices to match number of ends with…
… trailSegments. Fixes diagrams#263.
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 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,48 @@ | ||
module Diagrams.TwoD.OffsetTest | ||
( | ||
tests | ||
) where | ||
|
||
import Test.Tasty (TestTree) | ||
import Test.Tasty.HUnit | ||
|
||
import Diagrams.Prelude | ||
import Diagrams.TwoD.Offset | ||
|
||
tests :: [TestTree] | ||
tests = | ||
[ testCase "line" | ||
(offsetTrailVertices | ||
[p2 (0, 0), p2 (1, 0)] | ||
[p2 (0, -1), p2 (1, -1)]) | ||
, testCase "square" | ||
(offsetTrailVertices | ||
[p2 (0, 0), p2 (1, 0), p2 (1, 1), p2 (0, 1), p2 (0, 0)] | ||
[p2 (0, -1), p2 (2, -1), p2 (2, 2), p2 (-1, 2), p2 (-1, 0)]) | ||
, testCase "square loop" | ||
(offsetTrailLoopVertices | ||
[p2 (0, 0), p2 (1, 0), p2 (1, 1), p2 (0, 1), p2 (0, 0)] | ||
[p2 (2, -1), p2 (2, 2), p2 (-1, 2), p2 (-1, -1)]) | ||
, testCase "redundant line" | ||
(offsetTrailVertices | ||
[p2 (0, 0), p2 (0.5, 0), p2 (1, 0)] | ||
[p2 (0, -1), p2 (1, -1)]) | ||
, testCase "redundant square" | ||
(offsetTrailVertices | ||
[p2 (0, 0), p2 (1, 0), p2 (1, 0.5), p2 (1, 1), p2 (0, 1), p2 (0, 0)] | ||
[p2 (0, -1), p2 (2, -1), p2 (2, 2), p2 (-1, 2), p2 (-1, 0)]) | ||
, testCase "redundant square loop" | ||
(offsetTrailLoopVertices | ||
[p2 (0, 0), p2 (1, 0), p2 (1, 0.5), p2 (1, 1), p2 (0, 1), p2 (0, 0)] | ||
[p2 (2, -1), p2 (2, 2), p2 (-1, 2), p2 (-1, -1)]) | ||
] | ||
|
||
offsetTrailVertices :: [Point V2 Double] -> [Point V2 Double] -> Assertion | ||
offsetTrailVertices orig off = | ||
(trailVertices . offsetTrail 1 . fromVertices $ orig) @?= off | ||
|
||
offsetTrailLoopVertices :: [Point V2 Double] -> [Point V2 Double] -> Assertion | ||
offsetTrailLoopVertices orig off = | ||
(trailVertices . offsetTrail 1 . loopTrailFromVertices $ orig) @?= off | ||
where | ||
loopTrailFromVertices = (`at` origin) . wrapTrail . glueLine . lineFromVertices |
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,10 @@ | ||
import Test.Tasty (defaultMain, testGroup, TestTree) | ||
|
||
import qualified Diagrams.TwoD.OffsetTest as TwoD.OffsetTest | ||
|
||
tests :: TestTree | ||
tests = testGroup "unit tests" | ||
[ testGroup "TwoD.Offset" TwoD.OffsetTest.tests ] | ||
|
||
main :: IO () | ||
main = defaultMain tests |