Skip to content
Commit 4b9d87d6 authored by jeremy's avatar jeremy
Browse files

8176501: Method Shape.getBounds2D() incorrectly includes Bezier control points in bounding box

This adds an exploratory algorithm that tries to identify how to expand the double-based bounding box. It is currently problematic, but I'm committing it for review/feedback. Maybe this will look like a familiar problem to someone more familiar with this subject? Once we settle on how to address machine error: I'll either adapt this file into a more proper unit test or delete it.

This is an attempt to explore Laurent's comments here:
https://github.com/openjdk/jdk/pull/6227#discussion_r746450132

The problem is our double-based approach can be a little bit too small because of machine error. We need it to only ever err on the side of being too large.

Currently in this class we're applying a `margin` as follows:
```
       double x = coeff[0] + t * (coeff[1] + t * coeff[2]);
       double margin = marginMultiplier * Math.ulp(x);
       if (x - margin < leftX) leftX = x - margin;
       if (x + margin> rightX) rightX = x + margin;
```

This class tests a million shapes and tries to identify the smallest constant `marginMultiplier` that always returns an appropriate bounding box.

The current problem is this constant is multiplied by the ulp of a value. So as the value (for ex: the left x-value) approaches zero the ulp becomes increasingly small, so the multiplier has to become extremely large. Currently this algorithm settles on a multiplier of: 7.864956084850002E10

If we treat the constant as a multiplier of the x-value itself (for ex: `margin = multiplier * Math.abs(x)``), then this algorithm settles on 0.000013173867835580114.

What is a good way to evaluate `margin` in the code snippet above?

Or at some point we could switch back to using the bezier control point: what fuzzy sliding scale logic do we use to determine when to use "the old way" and when to use "the new way"?
parent b7ca69c8
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment