author | ehelin |
Mon, 20 Jan 2014 17:15:55 +0100 | |
changeset 22548 | d54e4339811f |
parent 9965 | 21ec27af2037 |
permissions | -rw-r--r-- |
9965
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
1 |
/* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
4 |
* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
8 |
* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
13 |
* accompanied this code). |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
14 |
* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
18 |
* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
21 |
* questions. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
22 |
* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
23 |
*/ |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
24 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
25 |
/** |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
26 |
* @test |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
27 |
* @bug 7047069 |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
28 |
* @summary Array can dynamically change size when assigned to an object field |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
29 |
* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
30 |
* @run main/othervm -Xbatch Test7047069 |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
31 |
*/ |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
32 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
33 |
import java.util.*; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
34 |
import java.awt.geom.*; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
35 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
36 |
public class Test7047069 { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
37 |
static boolean verbose; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
38 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
39 |
static final int GROW_SIZE = 24; // Multiple of cubic & quad curve size |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
40 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
41 |
float squareflat; // Square of the flatness parameter |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
42 |
// for testing against squared lengths |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
43 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
44 |
int limit; // Maximum number of recursion levels |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
45 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
46 |
float hold[] = new float[14]; // The cache of interpolated coords |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
47 |
// Note that this must be long enough |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
48 |
// to store a full cubic segment and |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
49 |
// a relative cubic segment to avoid |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
50 |
// aliasing when copying the coords |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
51 |
// of a curve to the end of the array. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
52 |
// This is also serendipitously equal |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
53 |
// to the size of a full quad segment |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
54 |
// and 2 relative quad segments. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
55 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
56 |
int holdEnd; // The index of the last curve segment |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
57 |
// being held for interpolation |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
58 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
59 |
int holdIndex; // The index of the curve segment |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
60 |
// that was last interpolated. This |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
61 |
// is the curve segment ready to be |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
62 |
// returned in the next call to |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
63 |
// currentSegment(). |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
64 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
65 |
int levels[]; // The recursion level at which |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
66 |
// each curve being held in storage |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
67 |
// was generated. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
68 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
69 |
int levelIndex; // The index of the entry in the |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
70 |
// levels array of the curve segment |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
71 |
// at the holdIndex |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
72 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
73 |
public static void subdivide(float src[], int srcoff, |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
74 |
float left[], int leftoff, |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
75 |
float right[], int rightoff) |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
76 |
{ |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
77 |
float x1 = src[srcoff + 0]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
78 |
float y1 = src[srcoff + 1]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
79 |
float ctrlx = src[srcoff + 2]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
80 |
float ctrly = src[srcoff + 3]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
81 |
float x2 = src[srcoff + 4]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
82 |
float y2 = src[srcoff + 5]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
83 |
if (left != null) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
84 |
left[leftoff + 0] = x1; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
85 |
left[leftoff + 1] = y1; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
86 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
87 |
if (right != null) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
88 |
right[rightoff + 4] = x2; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
89 |
right[rightoff + 5] = y2; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
90 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
91 |
x1 = (x1 + ctrlx) / 2f; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
92 |
y1 = (y1 + ctrly) / 2f; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
93 |
x2 = (x2 + ctrlx) / 2f; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
94 |
y2 = (y2 + ctrly) / 2f; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
95 |
ctrlx = (x1 + x2) / 2f; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
96 |
ctrly = (y1 + y2) / 2f; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
97 |
if (left != null) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
98 |
left[leftoff + 2] = x1; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
99 |
left[leftoff + 3] = y1; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
100 |
left[leftoff + 4] = ctrlx; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
101 |
left[leftoff + 5] = ctrly; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
102 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
103 |
if (right != null) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
104 |
right[rightoff + 0] = ctrlx; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
105 |
right[rightoff + 1] = ctrly; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
106 |
right[rightoff + 2] = x2; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
107 |
right[rightoff + 3] = y2; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
108 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
109 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
110 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
111 |
public static double getFlatnessSq(float coords[], int offset) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
112 |
return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1], |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
113 |
coords[offset + 4], coords[offset + 5], |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
114 |
coords[offset + 2], coords[offset + 3]); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
115 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
116 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
117 |
public Test7047069() { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
118 |
this.squareflat = .0001f * .0001f; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
119 |
holdIndex = hold.length - 6; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
120 |
holdEnd = hold.length - 2; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
121 |
hold[holdIndex + 0] = (float) (Math.random() * 100); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
122 |
hold[holdIndex + 1] = (float) (Math.random() * 100); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
123 |
hold[holdIndex + 2] = (float) (Math.random() * 100); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
124 |
hold[holdIndex + 3] = (float) (Math.random() * 100); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
125 |
hold[holdIndex + 4] = (float) (Math.random() * 100); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
126 |
hold[holdIndex + 5] = (float) (Math.random() * 100); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
127 |
levelIndex = 0; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
128 |
this.limit = 10; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
129 |
this.levels = new int[limit + 1]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
130 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
131 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
132 |
/* |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
133 |
* Ensures that the hold array can hold up to (want) more values. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
134 |
* It is currently holding (hold.length - holdIndex) values. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
135 |
*/ |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
136 |
void ensureHoldCapacity(int want) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
137 |
if (holdIndex - want < 0) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
138 |
int have = hold.length - holdIndex; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
139 |
int newsize = hold.length + GROW_SIZE; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
140 |
float newhold[] = new float[newsize]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
141 |
System.arraycopy(hold, holdIndex, |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
142 |
newhold, holdIndex + GROW_SIZE, |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
143 |
have); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
144 |
if (verbose) System.err.println("old hold = "+hold+"["+hold.length+"]"); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
145 |
if (verbose) System.err.println("replacement hold = "+newhold+"["+newhold.length+"]"); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
146 |
hold = newhold; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
147 |
if (verbose) System.err.println("new hold = "+hold+"["+hold.length+"]"); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
148 |
if (verbose) System.err.println("replacement hold still = "+newhold+"["+newhold.length+"]"); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
149 |
holdIndex += GROW_SIZE; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
150 |
holdEnd += GROW_SIZE; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
151 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
152 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
153 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
154 |
private boolean next() { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
155 |
if (holdIndex >= holdEnd) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
156 |
return false; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
157 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
158 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
159 |
int level = levels[levelIndex]; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
160 |
while (level < limit) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
161 |
if (getFlatnessSq(hold, holdIndex) < squareflat) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
162 |
break; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
163 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
164 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
165 |
ensureHoldCapacity(4); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
166 |
subdivide(hold, holdIndex, |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
167 |
hold, holdIndex - 4, |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
168 |
hold, holdIndex); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
169 |
holdIndex -= 4; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
170 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
171 |
// Now that we have subdivided, we have constructed |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
172 |
// two curves of one depth lower than the original |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
173 |
// curve. One of those curves is in the place of |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
174 |
// the former curve and one of them is in the next |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
175 |
// set of held coordinate slots. We now set both |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
176 |
// curves level values to the next higher level. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
177 |
level++; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
178 |
levels[levelIndex] = level; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
179 |
levelIndex++; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
180 |
levels[levelIndex] = level; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
181 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
182 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
183 |
// This curve segment is flat enough, or it is too deep |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
184 |
// in recursion levels to try to flatten any more. The |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
185 |
// two coordinates at holdIndex+4 and holdIndex+5 now |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
186 |
// contain the endpoint of the curve which can be the |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
187 |
// endpoint of an approximating line segment. |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
188 |
holdIndex += 4; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
189 |
levelIndex--; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
190 |
return true; |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
191 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
192 |
|
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
193 |
public static void main(String argv[]) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
194 |
verbose = (argv.length > 0); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
195 |
for (int i = 0; i < 100000; i++) { |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
196 |
Test7047069 st = new Test7047069(); |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
197 |
while (st.next()) {} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
198 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
199 |
} |
21ec27af2037
7047069: Array can dynamically change size when assigned to an object field
kvn
parents:
diff
changeset
|
200 |
} |