-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8176501: Method Shape.getBounds2D() incorrectly includes Bezier control points in bounding box #6227
Closed
Closed
8176501: Method Shape.getBounds2D() incorrectly includes Bezier control points in bounding box #6227
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0da9594
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 5a0e2bd
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 410cd6c
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness e617c72
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness b7ca69c
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 4b9d87d
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 8db26a2
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness af4c5f0
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 40bda06
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 8c5e772
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 0e2b529
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness b3e84a5
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 7680533
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 2b7a132
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness e346df0
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness 637c769
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness fcf9d35
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness d79f067
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness faeb241
8176501: Method Shape.getBounds2D() incorrectly includes Bezier contr…
mickleness File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -800,23 +800,7 @@ public final void transform(AffineTransform at) { | |
* @since 1.6 | ||
*/ | ||
public final synchronized Rectangle2D getBounds2D() { | ||
float x1, y1, x2, y2; | ||
int i = numCoords; | ||
if (i > 0) { | ||
y1 = y2 = floatCoords[--i]; | ||
x1 = x2 = floatCoords[--i]; | ||
while (i > 0) { | ||
float y = floatCoords[--i]; | ||
float x = floatCoords[--i]; | ||
if (x < x1) x1 = x; | ||
if (y < y1) y1 = y; | ||
if (x > x2) x2 = x; | ||
if (y > y2) y2 = y; | ||
} | ||
} else { | ||
x1 = y1 = x2 = y2 = 0.0f; | ||
} | ||
return new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1); | ||
return getBounds2D(getPathIterator(null)); | ||
} | ||
|
||
/** | ||
|
@@ -1592,23 +1576,7 @@ public final void transform(AffineTransform at) { | |
* @since 1.6 | ||
*/ | ||
public final synchronized Rectangle2D getBounds2D() { | ||
double x1, y1, x2, y2; | ||
int i = numCoords; | ||
if (i > 0) { | ||
y1 = y2 = doubleCoords[--i]; | ||
x1 = x2 = doubleCoords[--i]; | ||
while (i > 0) { | ||
double y = doubleCoords[--i]; | ||
double x = doubleCoords[--i]; | ||
if (x < x1) x1 = x; | ||
if (y < y1) y1 = y; | ||
if (x > x2) x2 = x; | ||
if (y > y2) y2 = y; | ||
} | ||
} else { | ||
x1 = y1 = x2 = y2 = 0.0; | ||
} | ||
return new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1); | ||
return getBounds2D(getPathIterator(null)); | ||
} | ||
|
||
/** | ||
|
@@ -2129,6 +2097,88 @@ public final Rectangle getBounds() { | |
return getBounds2D().getBounds(); | ||
} | ||
|
||
/** | ||
* Returns a high precision bounding box of the specified PathIterator. | ||
* <p> | ||
* This method provides a basic facility for implementors of the {@link Shape} interface to | ||
* implement support for the {@link Shape#getBounds2D()} method. | ||
* </p> | ||
* | ||
* @param pi the specified {@code PathIterator} | ||
* @return an instance of {@code Rectangle2D} that is a high-precision bounding box of the | ||
* {@code PathIterator}. | ||
* @see Shape#getBounds2D() | ||
*/ | ||
static Rectangle2D getBounds2D(final PathIterator pi) { | ||
final double[] coeff = new double[4]; | ||
final double[] deriv_coeff = new double[3]; | ||
|
||
final double[] coords = new double[6]; | ||
|
||
// bounds are stored as {leftX, rightX, topY, bottomY} | ||
double[] bounds = null; | ||
double lastX = 0.0; | ||
double lastY = 0.0; | ||
double endX = 0.0; | ||
double endY = 0.0; | ||
|
||
for (; !pi.isDone(); pi.next()) { | ||
final int type = pi.currentSegment(coords); | ||
switch (type) { | ||
case PathIterator.SEG_MOVETO: | ||
if (bounds == null) { | ||
bounds = new double[] { coords[0], coords[0], coords[1], coords[1] }; | ||
} | ||
endX = coords[0]; | ||
endY = coords[1]; | ||
break; | ||
case PathIterator.SEG_LINETO: | ||
endX = coords[0]; | ||
endY = coords[1]; | ||
break; | ||
case PathIterator.SEG_QUADTO: | ||
endX = coords[2]; | ||
endY = coords[3]; | ||
break; | ||
case PathIterator.SEG_CUBICTO: | ||
endX = coords[4]; | ||
endY = coords[5]; | ||
break; | ||
case PathIterator.SEG_CLOSE: | ||
default: | ||
continue; | ||
} | ||
|
||
if (endX < bounds[0]) bounds[0] = endX; | ||
if (endX > bounds[1]) bounds[1] = endX; | ||
if (endY < bounds[2]) bounds[2] = endY; | ||
if (endY > bounds[3]) bounds[3] = endY; | ||
|
||
switch (type) { | ||
case PathIterator.SEG_QUADTO: | ||
Curve.accumulateExtremaBoundsForQuad(bounds, 0, lastX, coords[0], coords[2], coeff, deriv_coeff); | ||
Curve.accumulateExtremaBoundsForQuad(bounds, 2, lastY, coords[1], coords[3], coeff, deriv_coeff); | ||
break; | ||
case PathIterator.SEG_CUBICTO: | ||
Curve.accumulateExtremaBoundsForCubic(bounds, 0, lastX, coords[0], coords[2], coords[4], coeff, deriv_coeff); | ||
Curve.accumulateExtremaBoundsForCubic(bounds, 2, lastY, coords[1], coords[3], coords[5], coeff, deriv_coeff); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. close the shortcut test |
||
lastX = endX; | ||
lastY = endY; | ||
} | ||
if (bounds != null) { | ||
return new Rectangle2D.Double(bounds[0], bounds[2], bounds[1] - bounds[0], bounds[3] - bounds[2]); | ||
} | ||
|
||
// there's room to debate what should happen here, but historically we return a zeroed | ||
// out rectangle here. So for backwards compatibility let's keep doing that: | ||
return new Rectangle2D.Double(); | ||
} | ||
|
||
/** | ||
* Tests if the specified coordinates are inside the closed | ||
* boundary of the specified {@link PathIterator}. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add explicitely the SEG_CLOSE case (skip = continue) before the default case (impossible case)