Opened 7 years ago

Closed 4 years ago

#16758 closed defect (patchwelcome)

GFX bounding boxes incorrect if paths contain arcs

Reported by: Tom Shinnick Owned by: Eugene Lazutkin
Priority: undecided Milestone: 1.13
Component: DojoX GFX Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

The initially observed failure was that the height of a large circle (using getBoundingBox) was determined to be zero while the width was a (large) nonzero. This was so astonishing it was unrecognized for quite awhile. A circle by definition has width same as height...

The problem is that gfx/path.js routine _updateWithSegment() tries to update the bbox x- and y-extents by adding only the end point of the arc. Since arcs are not lines, this misses the actual maximum x-/y-extents along the arc path.

In the original case, two arcs were drawn with start and end points parallel to the x-axis. Thus the y values were the same at both start and end. The difference between them was computed as zero and returned as the 'height'.

I am searching for mathematical solutions, but I hate math. The 'solution' I have, you will hate (and quite rightly):

  diff -w path.js.original path.js.workaround
  45a46,56
  >
  >             if ( this.rawNode  &&  this.rawNode.ownerSVGElement ) {
  >                     try {
  >                             var bb = this.rawNode.getBBox();
  >                             console.log("    path::getBoundingBox(): bb ", bb );
  >                             this.bbox = { l: bb.x, t: bb.y, r: bb.x+bb.width, b: bb.y+bb.height };
  >                             return {x: bb.x, y: bb.y, width: bb.width, height: bb.height};
  >                     } catch(e) {
  >                     }
  >             }
  >

Attached is a test HTML file showing the problem. It compares the bounding box return value from using a simple Circle, with two examples using Path's with arcs.

In the first arc example the start and end point y-values are the same (parallel with x-axis) and so the height is returned as zero.

In the second arc example the start and end points are aligned along a 45 degree angle. The result is then that the bounding box is entirely *inside* the drawn circle, demonstrating nicely the problem of using only an arc's end point to

Attachments (1)

test01.html (5.3 KB) - added by Tom Shinnick 7 years ago.
Test HTML showing 2 tests of paths with arc and bad bbox values

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by Tom Shinnick

Attachment: test01.html added

Test HTML showing 2 tests of paths with arc and bad bbox values

comment:1 Changed 7 years ago by Tom Shinnick

(oh dear, here's the rest of the submission - something cut it off)

In the second arc example the start and end points are aligned along a 45 degree angle. The result is then that the bounding box is entirely *inside* the drawn circle, demonstrating nicely the problem of using only an arc's end point to estimate the arcs actual maximum x- and y-extents.

The dojoConfig value for gfxRender may be varied in order to compare test results with "svg", "canvas" and "vml" on the various browsers.

Note that the failures on SVG are all the same between browsers, as are the failures when using canvas. Chrome, FF, Opera all fail the same way.

      Chrome    (25)
        SVG    fails 2nd & 3rd
        canvas fails 2nd & 3rd

      Firefox   (19.0)
        SVG    fails 2nd & 3rd
        canvas fails 2nd & 3rd

      Opera     (12.14)
        SVG    fails 2nd & 3rd
        canvas fails 2nd & 3rd

      IE 8
        VML    works on 2nd
               fails almost correctly on 3rd
                  (1 pixel off on right and bottom)
      IE 9
        VML    doesn't run anymore?   and SVG does?  (jokers!)
        SVG    fails 2nd & 3rd
        canvas fails 2nd & 3rd

This somewhat relates to this SO question:
"How to calculate center of an ellipse by two points and radius sizes"
http://stackoverflow.com/questions/197649/how-to-calculate-center-of-an-ellipse-by-two-points-and-radius-sizes

comment:2 Changed 4 years ago by dylan

Milestone: tbd1.12
Resolution: patchwelcome
Status: newclosed

Given that no one has shown interest in creating a patch in the past 2+ years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.