From 7a6b79a766d4e32b3007ae33b83442b018303943 Mon Sep 17 00:00:00 2001 From: nimec01 <24428341+nimec01@users.noreply.github.com> Date: Wed, 27 May 2026 15:17:31 +0200 Subject: [PATCH 1/7] reject more negative parameters --- codeworld-api/src/CodeWorld/Picture.hs | 45 ++++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/codeworld-api/src/CodeWorld/Picture.hs b/codeworld-api/src/CodeWorld/Picture.hs index 5aeb44d7..d7c9afa1 100644 --- a/codeworld-api/src/CodeWorld/Picture.hs +++ b/codeworld-api/src/CodeWorld/Picture.hs @@ -266,59 +266,84 @@ rectangleVertices :: Double -> Double -> [Point] rectangleVertices w h = [(w / 2, h / 2), (w / 2, - h / 2), (- w / 2, - h / 2), (- w / 2, h / 2)] -- | A thin rectangle, with this width and height +-- +-- The width and height must be non-negative. rectangle :: HasCallStack => Double -> Double -> Picture -rectangle w h = Rectangle (getDebugSrcLoc callStack) w h +rectangle w h + | w < 0 || h < 0 = error "The width and height must be non-negative." + | otherwise = Rectangle (getDebugSrcLoc callStack) w h -- | A solid rectangle, with this width and height +-- +-- The width and height must be non-negative. solidRectangle :: HasCallStack => Double -> Double -> Picture -solidRectangle w h = SolidRectangle (getDebugSrcLoc callStack) w h +solidRectangle w h + | w < 0 || h < 0 = error "The width and height must be non-negative." + | otherwise = SolidRectangle (getDebugSrcLoc callStack) w h -- | A thick rectangle, with this line width, and width and height -- +-- The width and height must be non-negative. -- The line width must be non-negative. thickRectangle :: HasCallStack => Double -> Double -> Double -> Picture thickRectangle lw w h + | w < 0 || h < 0 = error "The width and height must be non-negative." | lw < 0 = error "The line width must be non-negative." | otherwise = ThickRectangle (getDebugSrcLoc callStack) lw w h -- | A thin circle, with this radius +-- +-- The radius must be non-negative. circle :: HasCallStack => Double -> Picture -circle = Circle (getDebugSrcLoc callStack) +circle r + | r < 0 = error "The radius must be non-negative." + | otherwise = Circle (getDebugSrcLoc callStack) r -- | A thick circle, with this line width and radius -- --- The line width must be non-negative and not greater than its diameter. +-- The line width and radius must be non-negative, and the line width must not +-- be greater than its diameter. thickCircle :: HasCallStack => Double -> Double -> Picture thickCircle a r + | r < 0 = error "The radius must be non-negative." | a < 0 = error "The line width must be non-negative." | a <= 2 * r = ThickCircle (getDebugSrcLoc callStack) a r | otherwise = error "The line width of a thickCircle must not be greater than its diameter." -- | A thin arc, starting and ending at these angles, with this radius -- --- Angles are in radians. +-- Angles are in radians. The radius must be non-negative. arc :: HasCallStack => Double -> Double -> Double -> Picture -arc b e r = Arc (getDebugSrcLoc callStack) b e r +arc b e r + | r < 0 = error "The radius must be non-negative." + | otherwise = Arc (getDebugSrcLoc callStack) b e r -- | A thick arc with this line width, starting and ending at these angles, -- with this radius. -- --- Angles are in radians. The line width must be non-negative. +-- Angles are in radians. The line width and radius must be non-negative. thickArc :: HasCallStack => Double -> Double -> Double -> Double -> Picture thickArc w b e r + | r < 0 = error "The radius must be non-negative." | w < 0 = error "The line width must be non-negative." | otherwise = ThickArc (getDebugSrcLoc callStack) b e r w -- | A solid circle, with this radius +-- +-- The radius must be non-negative. solidCircle :: HasCallStack => Double -> Picture -solidCircle = SolidCircle (getDebugSrcLoc callStack) +solidCircle r + | r < 0 = error "The radius must be non-negative." + | otherwise = SolidCircle (getDebugSrcLoc callStack) r -- | A solid sector of a circle (i.e., a pie slice) starting and ending at these -- angles, with this radius -- --- Angles are in radians. +-- Angles are in radians. The radius must be non-negative. sector :: HasCallStack => Double -> Double -> Double -> Picture -sector = Sector (getDebugSrcLoc callStack) +sector b e r + | r < 0 = error "The radius must be non-negative." + | otherwise = Sector (getDebugSrcLoc callStack) b e r -- | A rendering of text characters. lettering :: HasCallStack => Text -> Picture From 02e47cdfa53136e3394e4f0ccfc506799baa369c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janis=20Voigtl=C3=A4nder?= Date: Wed, 27 May 2026 15:55:05 +0200 Subject: [PATCH 2/7] Fix comments for clarity in Picture.hs --- codeworld-api/src/CodeWorld/Picture.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codeworld-api/src/CodeWorld/Picture.hs b/codeworld-api/src/CodeWorld/Picture.hs index d7c9afa1..33081328 100644 --- a/codeworld-api/src/CodeWorld/Picture.hs +++ b/codeworld-api/src/CodeWorld/Picture.hs @@ -302,7 +302,7 @@ circle r -- | A thick circle, with this line width and radius -- -- The line width and radius must be non-negative, and the line width must not --- be greater than its diameter. +-- be greater than the diameter. thickCircle :: HasCallStack => Double -> Double -> Picture thickCircle a r | r < 0 = error "The radius must be non-negative." @@ -367,7 +367,7 @@ translated :: HasCallStack => Double -> Double -> Picture -> Picture translated = Translate (getDebugSrcLoc callStack) -- | A picture scaled by these factors in the x and y directions. Scaling --- by a negative factoralso reflects across that axis. +-- by a negative factor also reflects across that axis. scaled :: HasCallStack => Double -> Double -> Picture -> Picture scaled = Scale (getDebugSrcLoc callStack) From cd42c10d5546f91d76f33dddce31eb0a60dd55d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janis=20Voigtl=C3=A4nder?= Date: Wed, 27 May 2026 15:58:49 +0200 Subject: [PATCH 3/7] tweak --- codeworld-api/src/CodeWorld/Picture.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/codeworld-api/src/CodeWorld/Picture.hs b/codeworld-api/src/CodeWorld/Picture.hs index 33081328..715ece74 100644 --- a/codeworld-api/src/CodeWorld/Picture.hs +++ b/codeworld-api/src/CodeWorld/Picture.hs @@ -283,12 +283,11 @@ solidRectangle w h -- | A thick rectangle, with this line width, and width and height -- --- The width and height must be non-negative. --- The line width must be non-negative. +-- The line width, as well as width and heigth, must be non-negative. thickRectangle :: HasCallStack => Double -> Double -> Double -> Picture thickRectangle lw w h - | w < 0 || h < 0 = error "The width and height must be non-negative." | lw < 0 = error "The line width must be non-negative." + | w < 0 || h < 0 = error "The width and height must be non-negative." | otherwise = ThickRectangle (getDebugSrcLoc callStack) lw w h -- | A thin circle, with this radius From e78e333005bc75956debe81170762ba2e0ed1b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janis=20Voigtl=C3=A4nder?= Date: Wed, 27 May 2026 16:02:49 +0200 Subject: [PATCH 4/7] code consistency --- codeworld-api/src/CodeWorld/Picture.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codeworld-api/src/CodeWorld/Picture.hs b/codeworld-api/src/CodeWorld/Picture.hs index 715ece74..7a3a1acf 100644 --- a/codeworld-api/src/CodeWorld/Picture.hs +++ b/codeworld-api/src/CodeWorld/Picture.hs @@ -304,10 +304,10 @@ circle r -- be greater than the diameter. thickCircle :: HasCallStack => Double -> Double -> Picture thickCircle a r - | r < 0 = error "The radius must be non-negative." | a < 0 = error "The line width must be non-negative." - | a <= 2 * r = ThickCircle (getDebugSrcLoc callStack) a r - | otherwise = error "The line width of a thickCircle must not be greater than its diameter." + | r < 0 = error "The radius must be non-negative." + | a > 2 * r = error "The line width must not be greater than the diameter." + | otherwise = ThickCircle (getDebugSrcLoc callStack) a r -- | A thin arc, starting and ending at these angles, with this radius -- @@ -323,8 +323,8 @@ arc b e r -- Angles are in radians. The line width and radius must be non-negative. thickArc :: HasCallStack => Double -> Double -> Double -> Double -> Picture thickArc w b e r - | r < 0 = error "The radius must be non-negative." | w < 0 = error "The line width must be non-negative." + | r < 0 = error "The radius must be non-negative." | otherwise = ThickArc (getDebugSrcLoc callStack) b e r w -- | A solid circle, with this radius From 1a9b4ad7024a8315f5e49630ee9caba3368cdca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janis=20Voigtl=C3=A4nder?= Date: Wed, 27 May 2026 16:05:47 +0200 Subject: [PATCH 5/7] Fix typo in thickRectangle documentation --- codeworld-api/src/CodeWorld/Picture.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeworld-api/src/CodeWorld/Picture.hs b/codeworld-api/src/CodeWorld/Picture.hs index 7a3a1acf..36a0608d 100644 --- a/codeworld-api/src/CodeWorld/Picture.hs +++ b/codeworld-api/src/CodeWorld/Picture.hs @@ -283,7 +283,7 @@ solidRectangle w h -- | A thick rectangle, with this line width, and width and height -- --- The line width, as well as width and heigth, must be non-negative. +-- The line width, as well as width and height, must be non-negative. thickRectangle :: HasCallStack => Double -> Double -> Double -> Picture thickRectangle lw w h | lw < 0 = error "The line width must be non-negative." From 02e638e3f8bed4f3ba4154181c9f6bdec8acb941 Mon Sep 17 00:00:00 2001 From: nimec01 <24428341+nimec01@users.noreply.github.com> Date: Wed, 27 May 2026 16:25:31 +0200 Subject: [PATCH 6/7] apply restrictions to clipped and image --- codeworld-api/src/CodeWorld/Picture.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/codeworld-api/src/CodeWorld/Picture.hs b/codeworld-api/src/CodeWorld/Picture.hs index 36a0608d..501f52f4 100644 --- a/codeworld-api/src/CodeWorld/Picture.hs +++ b/codeworld-api/src/CodeWorld/Picture.hs @@ -390,7 +390,9 @@ reflected = Reflect (getDebugSrcLoc callStack) -- | A picture clipped to a rectangle around the origin with this width and height. clipped :: HasCallStack => Double -> Double -> Picture -> Picture -clipped = Clip (getDebugSrcLoc callStack) +clipped w h + | w < 0 || h < 0 = error "The width and height must be non-negative." + | otherwise = Clip (getDebugSrcLoc callStack) w h -- A picture made by drawing these pictures, ordered from top to bottom. pictures :: HasCallStack => [Picture] -> Picture @@ -442,7 +444,9 @@ image :: -- | Height, in CodeWorld screen units Double -> Picture -image = Sketch (getDebugSrcLoc callStack) +image name uri w h + | w < 0 || h < 0 = error "The width and height must be non-negative." + | otherwise = Sketch (getDebugSrcLoc callStack) name uri w h getDebugSrcLoc :: CallStack -> Maybe SrcLoc getDebugSrcLoc cs = Data.List.find ((== "main") . srcLocPackage) locs From 698f3c31b0c519f93ab2fd215e8cea9e57b98764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janis=20Voigtl=C3=A4nder?= Date: Wed, 27 May 2026 16:39:44 +0200 Subject: [PATCH 7/7] Add width and height requirements to comments --- codeworld-api/src/CodeWorld/Picture.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/codeworld-api/src/CodeWorld/Picture.hs b/codeworld-api/src/CodeWorld/Picture.hs index 501f52f4..b4feb442 100644 --- a/codeworld-api/src/CodeWorld/Picture.hs +++ b/codeworld-api/src/CodeWorld/Picture.hs @@ -389,6 +389,8 @@ reflected :: HasCallStack => Double -> Picture -> Picture reflected = Reflect (getDebugSrcLoc callStack) -- | A picture clipped to a rectangle around the origin with this width and height. +-- +-- The width and height must be non-negative. clipped :: HasCallStack => Double -> Double -> Picture -> Picture clipped w h | w < 0 || h < 0 = error "The width and height must be non-negative." @@ -439,9 +441,9 @@ image :: Text -> -- | Data-scheme URI for the image data Text -> - -- | Width, in CodeWorld screen units + -- | Width (non-negative), in CodeWorld screen units Double -> - -- | Height, in CodeWorld screen units + -- | Height (non-negative), in CodeWorld screen units Double -> Picture image name uri w h