Skip to content

Commit fed7525

Browse files
committed
remove unnecessary thickness validator and simplify picture conversion in Abstract
1 parent 599f20c commit fed7525

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

src/CodeWorld/Test/Abstract.hs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import CodeWorld.Tasks.VectorSpace (
5151
import CodeWorld.Test.AbsTypes
5252

5353
import qualified CodeWorld.Tasks.Picture as P
54+
import qualified CodeWorld.Tasks.Types as PT
5455

5556

5657
{- |
@@ -121,7 +122,7 @@ instance Drawable AbstractPicture where
121122
solidPolygon = Polyline Solid . map toAbsPoint . toOpenShape
122123

123124
polygon = polyline . toOpenShape
124-
thickPolygon (validThickness -> t) = thickPolyline t . toOpenShape
125+
thickPolygon t = thickPolyline t . toOpenShape
125126

126127
lettering = Lettering
127128

@@ -339,14 +340,8 @@ This only makes sense if there's exactly one way to solve the given task.
339340
-}
340341
toConcretePicture :: AbstractPicture -> P.Picture
341342
toConcretePicture p = case p of
342-
Rectangle sk sx sy -> (case sk of
343-
Hollow Normal -> P.Rectangle
344-
Hollow Thick -> P.ThickRectangle 1
345-
_ -> P.SolidRectangle) (fromSize sx) (fromSize sy)
346-
Circle sk s -> (case sk of
347-
Hollow Normal -> P.Circle
348-
Hollow Thick -> P.ThickCircle 1
349-
_ -> P.SolidCircle) (fromSize s)
343+
Rectangle sk sx sy -> P.AnyRectangle (toStyle sk) (fromSize sx) (fromSize sy)
344+
Circle sk s -> P.AnyCircle (toStyle sk) (fromSize s)
350345
Lettering t -> P.Lettering t
351346
Color c q -> P.Color (fromAbsColor c) $ toConcretePicture q
352347
Translate x y q -> P.Translate (fromPosition x) (fromPosition y) $ toConcretePicture q
@@ -356,25 +351,16 @@ toConcretePicture p = case p of
356351
CoordinatePlane -> P.CoordinatePlane
357352
Logo -> P.Logo
358353
Blank -> P.Blank
359-
Polyline sk ps -> case sk of
360-
Hollow Normal -> P.Polyline $ map fromAbsPoint ps
361-
Hollow Thick -> P.ThickPolyline 1 $ map fromAbsPoint ps
362-
_ -> P.SolidPolygon $ init $ map fromAbsPoint ps
363-
Curve sk ps -> case sk of
364-
Hollow Normal -> P.Curve $ map fromAbsPoint ps
365-
Hollow Thick -> P.ThickCurve 1 $ map fromAbsPoint ps
366-
_ -> P.SolidClosedCurve $ init $ map fromAbsPoint ps
367-
Arc sk a1 a2 s -> (case sk of
368-
Hollow Normal -> P.Arc
369-
Hollow Thick -> P.ThickArc 1
370-
_ -> P.Sector) (fromAngle a1) (fromAngle a2) (fromSize s)
354+
Polyline sk ps -> uncurry P.AnyPolyline $ toShape sk $ map fromAbsPoint ps
355+
Curve sk ps -> uncurry P.AnyCurve $ toShape sk $ map fromAbsPoint ps
356+
Arc sk a1 a2 s -> P.AnyArc (toStyle sk) (fromAngle a1) (fromAngle a2) (fromSize s)
371357
Reflect a q -> P.Reflect (fromAngle a) $ toConcretePicture q
372358
Clip sx sy q -> P.Clip (fromSize sx) (fromSize sy) $ toConcretePicture q
359+
where
360+
toStyle (Hollow Normal) = PT.Outline Nothing
361+
toStyle (Hollow Thick) = PT.Outline $ Just 1
362+
toStyle Solid = PT.Solid
373363

374-
375-
validThickness :: Double -> Double
376-
validThickness t
377-
| t < 0 = error $
378-
"The line width must be non-negative. " ++
379-
"(This error was thrown inside the test suite)"
380-
| otherwise = t
364+
toShape (Hollow Normal) ps = (PT.Open Nothing, ps)
365+
toShape (Hollow Thick) ps = (PT.Open $ Just 1, ps)
366+
toShape Solid ps = (PT.Closed PT.Solid, init ps)

0 commit comments

Comments
 (0)