Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007498OCamlstandard librarypublic2017-03-02 15:172017-04-24 16:16
Assigned Todim 
PlatformOSOS Version
Product Version4.04.0 
Target VersionFixed in Version 
Summary0007498: Rectangle madness
DescriptionGraphics.draw_rect and Graphics.fill_rect have strange behaviors.

I will suppose that they use the same meaning for their arguments.
I see two behaviors

1) how I understand the documentation
fill_rect x y z h
means { px, py : x <= px < x + w and y <= py < y + h }

2) what is currently implemented on Linux
fill_rect x y z h
means { px, py : x <= px <= x + w and y <= py <= y + h }

In any cases the behavior of windows must be the same. I use the C compiler of VS 2010 to compile ocaml.

For the case 1, Linux must be changed and Windows too
I have the fix fix1.patch

For the case 2, Windows does not do the same thing as Linux
I have the fix fix2.patch

I also add a test file (
> ocamlopt -o test graphics.cmxa && ./test 1
will test the case 1
> ocamlopt -o test graphics.cmxa && ./test 2
will test the case 2

The documentation of get_image states that the arguments have the same meaning than fill_rect. That's why case 1 is probably the expected behavior.

By the way, there is the commit
which looks like the opposite of fix1 (for the Linux part). That's strange.

I don't have Mac OS X to test, sorry.

TagsNo tags attached.
Attached Files? file icon rectanglemadness.tar.xz [^] (2,304 bytes) 2017-03-02 15:17

- Relationships

-  Notes
dim (developer)
2017-04-21 14:48

I agree that case 1 should be the expected behavior; if you ask for a rectangle of width 10, you should get a rectangle of width 10, not 11.

I tried fix1.patch and it seems to fix the issue, however there are some problems with edge cases on Windows:

- [draw_rect 10 10 0 0] draws a 2x2 square
- [draw_rect 10 10 1 1] draws nothing

On Linux, [draw_rect 10 10 0 0] ends up passing negative values to XDrawRectangle. This doesn't cause a failure or bad behavior but should probably be avoided.
iesvs (reporter)
2017-04-24 14:38

I forgot to test edge cases. So I just dit it with fix1.

On Windows when drawing a rect of size 0, the windows API invert the coordinates to always use nondecreasing coordinates. So a rect of size 2 is drawn.
I didn't observe such behavior with fill rect.

With Linux I noticed no problems with fill_rect, but draw rect draw a very big rect when trying to draw a rect of size 0.

Maybe disable draw_rect and fill_rect when width or height is 0 will prevent strange behaviors.
dim (developer)
2017-04-24 16:16

Yh I suppose we could have special cases when width is zero and/or height is zero. We could do this in the OCaml code, to avoid having to rely on the behavior of the underlying API for edge cases.

BTW, any chance you could submit a PR on github? This would make the review easier.

- Issue History
Date Modified Username Field Change
2017-03-02 15:17 iesvs New Issue
2017-03-02 15:17 iesvs File Added: rectanglemadness.tar.xz
2017-04-14 16:59 doligez Status new => acknowledged
2017-04-21 14:43 dim Assigned To => dim
2017-04-21 14:43 dim Status acknowledged => assigned
2017-04-21 14:48 dim Note Added: 0017750
2017-04-24 14:38 iesvs Note Added: 0017753
2017-04-24 16:16 dim Note Added: 0017754

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker