0N/A/*
2362N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A *
2362N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 7047069
0N/A * @summary Array can dynamically change size when assigned to an object field
0N/A *
0N/A * @run main/othervm -Xbatch Test7047069
0N/A */
0N/A
0N/Aimport java.util.*;
0N/Aimport java.awt.geom.*;
0N/A
0N/Apublic class Test7047069 {
0N/A static boolean verbose;
0N/A
0N/A static final int GROW_SIZE = 24; // Multiple of cubic & quad curve size
0N/A
0N/A float squareflat; // Square of the flatness parameter
0N/A // for testing against squared lengths
0N/A
0N/A int limit; // Maximum number of recursion levels
0N/A
0N/A float hold[] = new float[14]; // The cache of interpolated coords
0N/A // Note that this must be long enough
0N/A // to store a full cubic segment and
0N/A // a relative cubic segment to avoid
0N/A // aliasing when copying the coords
0N/A // of a curve to the end of the array.
0N/A // This is also serendipitously equal
0N/A // to the size of a full quad segment
0N/A // and 2 relative quad segments.
0N/A
0N/A int holdEnd; // The index of the last curve segment
0N/A // being held for interpolation
0N/A
0N/A int holdIndex; // The index of the curve segment
0N/A // that was last interpolated. This
0N/A // is the curve segment ready to be
0N/A // returned in the next call to
0N/A // currentSegment().
0N/A
0N/A int levels[]; // The recursion level at which
0N/A // each curve being held in storage
0N/A // was generated.
0N/A
0N/A int levelIndex; // The index of the entry in the
0N/A // levels array of the curve segment
0N/A // at the holdIndex
0N/A
0N/A public static void subdivide(float src[], int srcoff,
0N/A float left[], int leftoff,
0N/A float right[], int rightoff)
0N/A {
0N/A float x1 = src[srcoff + 0];
0N/A float y1 = src[srcoff + 1];
0N/A float ctrlx = src[srcoff + 2];
0N/A float ctrly = src[srcoff + 3];
0N/A float x2 = src[srcoff + 4];
0N/A float y2 = src[srcoff + 5];
0N/A if (left != null) {
0N/A left[leftoff + 0] = x1;
left[leftoff + 1] = y1;
}
if (right != null) {
right[rightoff + 4] = x2;
right[rightoff + 5] = y2;
}
x1 = (x1 + ctrlx) / 2f;
y1 = (y1 + ctrly) / 2f;
x2 = (x2 + ctrlx) / 2f;
y2 = (y2 + ctrly) / 2f;
ctrlx = (x1 + x2) / 2f;
ctrly = (y1 + y2) / 2f;
if (left != null) {
left[leftoff + 2] = x1;
left[leftoff + 3] = y1;
left[leftoff + 4] = ctrlx;
left[leftoff + 5] = ctrly;
}
if (right != null) {
right[rightoff + 0] = ctrlx;
right[rightoff + 1] = ctrly;
right[rightoff + 2] = x2;
right[rightoff + 3] = y2;
}
}
public static double getFlatnessSq(float coords[], int offset) {
return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1],
coords[offset + 4], coords[offset + 5],
coords[offset + 2], coords[offset + 3]);
}
public Test7047069() {
this.squareflat = .0001f * .0001f;
holdIndex = hold.length - 6;
holdEnd = hold.length - 2;
hold[holdIndex + 0] = (float) (Math.random() * 100);
hold[holdIndex + 1] = (float) (Math.random() * 100);
hold[holdIndex + 2] = (float) (Math.random() * 100);
hold[holdIndex + 3] = (float) (Math.random() * 100);
hold[holdIndex + 4] = (float) (Math.random() * 100);
hold[holdIndex + 5] = (float) (Math.random() * 100);
levelIndex = 0;
this.limit = 10;
this.levels = new int[limit + 1];
}
/*
* Ensures that the hold array can hold up to (want) more values.
* It is currently holding (hold.length - holdIndex) values.
*/
void ensureHoldCapacity(int want) {
if (holdIndex - want < 0) {
int have = hold.length - holdIndex;
int newsize = hold.length + GROW_SIZE;
float newhold[] = new float[newsize];
System.arraycopy(hold, holdIndex,
newhold, holdIndex + GROW_SIZE,
have);
if (verbose) System.err.println("old hold = "+hold+"["+hold.length+"]");
if (verbose) System.err.println("replacement hold = "+newhold+"["+newhold.length+"]");
hold = newhold;
if (verbose) System.err.println("new hold = "+hold+"["+hold.length+"]");
if (verbose) System.err.println("replacement hold still = "+newhold+"["+newhold.length+"]");
holdIndex += GROW_SIZE;
holdEnd += GROW_SIZE;
}
}
private boolean next() {
if (holdIndex >= holdEnd) {
return false;
}
int level = levels[levelIndex];
while (level < limit) {
if (getFlatnessSq(hold, holdIndex) < squareflat) {
break;
}
ensureHoldCapacity(4);
subdivide(hold, holdIndex,
hold, holdIndex - 4,
hold, holdIndex);
holdIndex -= 4;
// Now that we have subdivided, we have constructed
// two curves of one depth lower than the original
// curve. One of those curves is in the place of
// the former curve and one of them is in the next
// set of held coordinate slots. We now set both
// curves level values to the next higher level.
level++;
levels[levelIndex] = level;
levelIndex++;
levels[levelIndex] = level;
}
// This curve segment is flat enough, or it is too deep
// in recursion levels to try to flatten any more. The
// two coordinates at holdIndex+4 and holdIndex+5 now
// contain the endpoint of the curve which can be the
// endpoint of an approximating line segment.
holdIndex += 4;
levelIndex--;
return true;
}
public static void main(String argv[]) {
verbose = (argv.length > 0);
for (int i = 0; i < 100000; i++) {
Test7047069 st = new Test7047069();
while (st.next()) {}
}
}
}