Sudha247 / ocaml-joy

MIT License
21 stars 14 forks source link

bug: Drawing circle on a rectangular canvas draws an ellipse #86

Closed nikochiko closed 4 months ago

nikochiko commented 6 months ago

Code:

open Joy

let () =
  init ~size:(500., 300.) ();
  background (1., 1., 1., 1.);
  let c = circle 50. in
  set_color (0., 0., 0.);
  render c;
  write ~filename:"circle.png" ()
image

The initial cairo scaling must be done by Cairo.scale (max w h) (max w h) instead of Cairo.scale w h.

FayCarsons commented 6 months ago

I tried max w h as the args and it caused distortions in the placement of shapes (i.e. a circle at 0,0 was not centered on the Y axis). I think the euclidean norm may work, I'll also test out a few of the aspect ratio correction equations I know.

Its very odd that it is doing this though, we aren't drawing on a pixel level and this shouldn't really be happening. Or at least, this doesn't happen with frameworks like p5.js or the others I've used. There may be something else at play, some config missing.

nikochiko commented 6 months ago

The denormalisation logic also needed to be corrected. I have a fix for this locally.