brownplt / pyret-lang

The Pyret language.
Other
1.06k stars 106 forks source link

`overlay()` buggy #1748

Closed user706 closed 1 month ago

user706 commented 1 month ago

pyret's overlay is messed up:

# pyret

overlay(
  rectangle(500, 300, "outline", "grey"),

  above(
    above(
      rectangle(500, 100, "solid", "black"),
      rectangle(500, 100, "solid", "red")
      ),
    rectangle(500, 100, "solid", "gold")
    )

  )

results in this ridiculous thing:

pyret

Racket, is good:

; racket

(require 2htdp/image)
(overlay
 (rectangle 500  300 "outline" "grey")

 (above
  (above
   (rectangle 500 100 "solid" "black")
   (rectangle 500 100 "solid" "red")
   )
  (rectangle 500 100 "solid" "gold")
  )
 )

results in:

racket

blerner commented 1 month ago

Closing as dupe of #1576. This is by design at the moment, neither "messed up" nor "ridiculous". But I agree it's unexpected! The reason has to do with how Pyret currently treats pinholes, and there are good reasons for what it currently does, and we don't yet know of a clean, consistent way to accommodate all the desired outcomes.

user706 commented 1 month ago

Ok; but then please show me some example code variants of how I can get a German flag with a grey outline around it.

Thanks

blerner commented 1 month ago

Look at the center-pinhole function, and wrap your above(...) sub-image in it.

user706 commented 1 month ago

Seems like a design flaw.

If you mix "bounding box-center" and "centroid"... sometime using the one, and then the other... obviously things will not always work out nicely.

Perhaps a function centroid-pinhole that works on some basic shapes such as triangles, would have been better (i.e. more consistent) (I could imagine a 2nd [slightly-modified] image library, that works exactly like racket's image lib; and has an extra function centroid-pinhole.)

[Since this issue is closed as duplicate; I'll repost this comment, in the open issue]