src/share/classes/java/awt/geom/Area.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 95,107 ****
* </ul>
*
* @since 1.2
*/
public class Area implements Shape, Cloneable {
! private static Vector EmptyCurves = new Vector();
! private Vector curves;
/**
* Default constructor which creates an empty area.
* @since 1.2
*/
--- 95,107 ----
* </ul>
*
* @since 1.2
*/
public class Area implements Shape, Cloneable {
! private static Vector<Curve> EmptyCurves = new Vector<>();
! private Vector<Curve> curves;
/**
* Default constructor which creates an empty area.
* @since 1.2
*/
*** 125,136 ****
} else {
curves = pathToCurves(s.getPathIterator(null));
}
}
! private static Vector pathToCurves(PathIterator pi) {
! Vector curves = new Vector();
int windingRule = pi.getWindingRule();
// coords array is big enough for holding:
// coordinates returned from currentSegment (6)
// OR
// two subdivided quadratic curves (2+4+4=10)
--- 125,136 ----
} else {
curves = pathToCurves(s.getPathIterator(null));
}
}
! private static Vector<Curve> pathToCurves(PathIterator pi) {
! Vector<Curve> curves = new Vector<>();
int windingRule = pi.getWindingRule();
// coords array is big enough for holding:
// coordinates returned from currentSegment (6)
// OR
// two subdivided quadratic curves (2+4+4=10)
*** 332,342 ****
* Removes all of the geometry from this <code>Area</code> and
* restores it to an empty area.
* @since 1.2
*/
public void reset() {
! curves = new Vector();
invalidateBounds();
}
/**
* Tests whether this <code>Area</code> object encloses any area.
--- 332,342 ----
* Removes all of the geometry from this <code>Area</code> and
* restores it to an empty area.
* @since 1.2
*/
public void reset() {
! curves = new Vector<>();
invalidateBounds();
}
/**
* Tests whether this <code>Area</code> object encloses any area.
*** 355,367 ****
* <code>Area</code> consists entirely of line segments;
* <code>false</code> otherwise.
* @since 1.2
*/
public boolean isPolygonal() {
! Enumeration enum_ = curves.elements();
while (enum_.hasMoreElements()) {
! if (((Curve) enum_.nextElement()).getOrder() > 1) {
return false;
}
}
return true;
}
--- 355,367 ----
* <code>Area</code> consists entirely of line segments;
* <code>false</code> otherwise.
* @since 1.2
*/
public boolean isPolygonal() {
! Enumeration<Curve> enum_ = curves.elements();
while (enum_.hasMoreElements()) {
! if (enum_.nextElement().getOrder() > 1) {
return false;
}
}
return true;
}
*** 379,390 ****
return true;
}
if (size > 3) {
return false;
}
! Curve c1 = (Curve) curves.get(1);
! Curve c2 = (Curve) curves.get(2);
if (c1.getOrder() != 1 || c2.getOrder() != 1) {
return false;
}
if (c1.getXTop() != c1.getXBot() || c2.getXTop() != c2.getXBot()) {
return false;
--- 379,390 ----
return true;
}
if (size > 3) {
return false;
}
! Curve c1 = curves.get(1);
! Curve c2 = curves.get(2);
if (c1.getOrder() != 1 || c2.getOrder() != 1) {
return false;
}
if (c1.getXTop() != c1.getXBot() || c2.getXTop() != c2.getXBot()) {
return false;
*** 409,422 ****
*/
public boolean isSingular() {
if (curves.size() < 3) {
return true;
}
! Enumeration enum_ = curves.elements();
enum_.nextElement(); // First Order0 "moveto"
while (enum_.hasMoreElements()) {
! if (((Curve) enum_.nextElement()).getOrder() == 0) {
return false;
}
}
return true;
}
--- 409,422 ----
*/
public boolean isSingular() {
if (curves.size() < 3) {
return true;
}
! Enumeration<Curve> enum_ = curves.elements();
enum_.nextElement(); // First Order0 "moveto"
while (enum_.hasMoreElements()) {
! if (enum_.nextElement().getOrder() == 0) {
return false;
}
}
return true;
}
*** 429,443 ****
if (cachedBounds != null) {
return cachedBounds;
}
Rectangle2D r = new Rectangle2D.Double();
if (curves.size() > 0) {
! Curve c = (Curve) curves.get(0);
// First point is always an order 0 curve (moveto)
r.setRect(c.getX0(), c.getY0(), 0, 0);
for (int i = 1; i < curves.size(); i++) {
! ((Curve) curves.get(i)).enlarge(r);
}
}
return (cachedBounds = r);
}
--- 429,443 ----
if (cachedBounds != null) {
return cachedBounds;
}
Rectangle2D r = new Rectangle2D.Double();
if (curves.size() > 0) {
! Curve c = curves.get(0);
// First point is always an order 0 curve (moveto)
r.setRect(c.getX0(), c.getY0(), 0, 0);
for (int i = 1; i < curves.size(); i++) {
! curves.get(i).enlarge(r);
}
}
return (cachedBounds = r);
}
*** 505,515 ****
return true;
}
if (other == null) {
return false;
}
! Vector c = new AreaOp.XorOp().calculate(this.curves, other.curves);
return c.isEmpty();
}
/**
* Transforms the geometry of this <code>Area</code> using the specified
--- 505,515 ----
return true;
}
if (other == null) {
return false;
}
! Vector<Curve> c = new AreaOp.XorOp().calculate(this.curves, other.curves);
return c.isEmpty();
}
/**
* Transforms the geometry of this <code>Area</code> using the specified
*** 553,566 ****
*/
public boolean contains(double x, double y) {
if (!getCachedBounds().contains(x, y)) {
return false;
}
! Enumeration enum_ = curves.elements();
int crossings = 0;
while (enum_.hasMoreElements()) {
! Curve c = (Curve) enum_.nextElement();
crossings += c.crossingsFor(x, y);
}
return ((crossings & 1) == 1);
}
--- 553,566 ----
*/
public boolean contains(double x, double y) {
if (!getCachedBounds().contains(x, y)) {
return false;
}
! Enumeration<Curve> enum_ = curves.elements();
int crossings = 0;
while (enum_.hasMoreElements()) {
! Curve c = enum_.nextElement();
crossings += c.crossingsFor(x, y);
}
return ((crossings & 1) == 1);
}
*** 656,675 ****
}
}
class AreaIterator implements PathIterator {
private AffineTransform transform;
! private Vector curves;
private int index;
private Curve prevcurve;
private Curve thiscurve;
! public AreaIterator(Vector curves, AffineTransform at) {
this.curves = curves;
this.transform = at;
if (curves.size() >= 1) {
! thiscurve = (Curve) curves.get(0);
}
}
public int getWindingRule() {
// REMIND: Which is better, EVEN_ODD or NON_ZERO?
--- 656,675 ----
}
}
class AreaIterator implements PathIterator {
private AffineTransform transform;
! private Vector<Curve> curves;
private int index;
private Curve prevcurve;
private Curve thiscurve;
! public AreaIterator(Vector<Curve> curves, AffineTransform at) {
this.curves = curves;
this.transform = at;
if (curves.size() >= 1) {
! thiscurve = curves.get(0);
}
}
public int getWindingRule() {
// REMIND: Which is better, EVEN_ODD or NON_ZERO?
*** 687,697 ****
prevcurve = null;
} else {
prevcurve = thiscurve;
index++;
if (index < curves.size()) {
! thiscurve = (Curve) curves.get(index);
if (thiscurve.getOrder() != 0 &&
prevcurve.getX1() == thiscurve.getX0() &&
prevcurve.getY1() == thiscurve.getY0())
{
prevcurve = null;
--- 687,697 ----
prevcurve = null;
} else {
prevcurve = thiscurve;
index++;
if (index < curves.size()) {
! thiscurve = curves.get(index);
if (thiscurve.getOrder() != 0 &&
prevcurve.getX1() == thiscurve.getX0() &&
prevcurve.getY1() == thiscurve.getY0())
{
prevcurve = null;