Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / geom / FlatteningPathIterator.js
1 Clazz.declarePackage ("java.awt.geom");
2 Clazz.load (["java.awt.geom.PathIterator"], "java.awt.geom.FlatteningPathIterator", ["java.lang.IllegalArgumentException", "java.util.NoSuchElementException", "java.awt.geom.CubicCurve2D", "$.QuadCurve2D"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.src = null;
5 this.squareflat = 0;
6 this.limit = 0;
7 this.hold = null;
8 this.curx = 0;
9 this.cury = 0;
10 this.movx = 0;
11 this.movy = 0;
12 this.holdType = 0;
13 this.holdEnd = 0;
14 this.holdIndex = 0;
15 this.levels = null;
16 this.levelIndex = 0;
17 this.done = false;
18 Clazz.instantialize (this, arguments);
19 }, java.awt.geom, "FlatteningPathIterator", null, java.awt.geom.PathIterator);
20 Clazz.prepareFields (c$, function () {
21 this.hold =  Clazz.newDoubleArray (14, 0);
22 });
23 Clazz.makeConstructor (c$, 
24 function (src, flatness) {
25 this.construct (src, flatness, 10);
26 }, "java.awt.geom.PathIterator,~N");
27 Clazz.makeConstructor (c$, 
28 function (src, flatness, limit) {
29 if (flatness < 0.0) {
30 throw  new IllegalArgumentException ("flatness must be >= 0");
31 }if (limit < 0) {
32 throw  new IllegalArgumentException ("limit must be >= 0");
33 }this.src = src;
34 this.squareflat = flatness * flatness;
35 this.limit = limit;
36 this.levels =  Clazz.newIntArray (limit + 1, 0);
37 this.next (false);
38 }, "java.awt.geom.PathIterator,~N,~N");
39 Clazz.defineMethod (c$, "getFlatness", 
40 function () {
41 return Math.sqrt (this.squareflat);
42 });
43 Clazz.defineMethod (c$, "getRecursionLimit", 
44 function () {
45 return this.limit;
46 });
47 Clazz.defineMethod (c$, "getWindingRule", 
48 function () {
49 return this.src.getWindingRule ();
50 });
51 Clazz.defineMethod (c$, "isDone", 
52 function () {
53 return this.done;
54 });
55 Clazz.defineMethod (c$, "ensureHoldCapacity", 
56 function (want) {
57 if (this.holdIndex - want < 0) {
58 var have = this.hold.length - this.holdIndex;
59 var newsize = this.hold.length + 24;
60 var newhold =  Clazz.newDoubleArray (newsize, 0);
61 System.arraycopy (this.hold, this.holdIndex, newhold, this.holdIndex + 24, have);
62 this.hold = newhold;
63 this.holdIndex += 24;
64 this.holdEnd += 24;
65 }}, "~N");
66 Clazz.defineMethod (c$, "next", 
67 function () {
68 this.next (true);
69 });
70 Clazz.defineMethod (c$, "next", 
71  function (doNext) {
72 var level;
73 if (this.holdIndex >= this.holdEnd) {
74 if (doNext) {
75 this.src.next ();
76 }if (this.src.isDone ()) {
77 this.done = true;
78 return;
79 }this.holdType = this.src.currentSegment (this.hold);
80 this.levelIndex = 0;
81 this.levels[0] = 0;
82 }switch (this.holdType) {
83 case 0:
84 case 1:
85 this.curx = this.hold[0];
86 this.cury = this.hold[1];
87 if (this.holdType == 0) {
88 this.movx = this.curx;
89 this.movy = this.cury;
90 }this.holdIndex = 0;
91 this.holdEnd = 0;
92 break;
93 case 4:
94 this.curx = this.movx;
95 this.cury = this.movy;
96 this.holdIndex = 0;
97 this.holdEnd = 0;
98 break;
99 case 2:
100 if (this.holdIndex >= this.holdEnd) {
101 this.holdIndex = this.hold.length - 6;
102 this.holdEnd = this.hold.length - 2;
103 this.hold[this.holdIndex + 0] = this.curx;
104 this.hold[this.holdIndex + 1] = this.cury;
105 this.hold[this.holdIndex + 2] = this.hold[0];
106 this.hold[this.holdIndex + 3] = this.hold[1];
107 this.hold[this.holdIndex + 4] = this.curx = this.hold[2];
108 this.hold[this.holdIndex + 5] = this.cury = this.hold[3];
109 }level = this.levels[this.levelIndex];
110 while (level < this.limit) {
111 if (java.awt.geom.QuadCurve2D.getFlatnessSq (this.hold, this.holdIndex) < this.squareflat) {
112 break;
113 }this.ensureHoldCapacity (4);
114 java.awt.geom.QuadCurve2D.subdivide (this.hold, this.holdIndex, this.hold, this.holdIndex - 4, this.hold, this.holdIndex);
115 this.holdIndex -= 4;
116 level++;
117 this.levels[this.levelIndex] = level;
118 this.levelIndex++;
119 this.levels[this.levelIndex] = level;
120 }
121 this.holdIndex += 4;
122 this.levelIndex--;
123 break;
124 case 3:
125 if (this.holdIndex >= this.holdEnd) {
126 this.holdIndex = this.hold.length - 8;
127 this.holdEnd = this.hold.length - 2;
128 this.hold[this.holdIndex + 0] = this.curx;
129 this.hold[this.holdIndex + 1] = this.cury;
130 this.hold[this.holdIndex + 2] = this.hold[0];
131 this.hold[this.holdIndex + 3] = this.hold[1];
132 this.hold[this.holdIndex + 4] = this.hold[2];
133 this.hold[this.holdIndex + 5] = this.hold[3];
134 this.hold[this.holdIndex + 6] = this.curx = this.hold[4];
135 this.hold[this.holdIndex + 7] = this.cury = this.hold[5];
136 }level = this.levels[this.levelIndex];
137 while (level < this.limit) {
138 if (java.awt.geom.CubicCurve2D.getFlatnessSq (this.hold, this.holdIndex) < this.squareflat) {
139 break;
140 }this.ensureHoldCapacity (6);
141 java.awt.geom.CubicCurve2D.subdivide (this.hold, this.holdIndex, this.hold, this.holdIndex - 6, this.hold, this.holdIndex);
142 this.holdIndex -= 6;
143 level++;
144 this.levels[this.levelIndex] = level;
145 this.levelIndex++;
146 this.levels[this.levelIndex] = level;
147 }
148 this.holdIndex += 6;
149 this.levelIndex--;
150 break;
151 }
152 }, "~B");
153 Clazz.defineMethod (c$, "currentSegment", 
154 function (coords) {
155 if (this.isDone ()) {
156 throw  new java.util.NoSuchElementException ("flattening iterator out of bounds");
157 }var type = this.holdType;
158 if (type != 4) {
159 coords[0] = this.hold[this.holdIndex + 0];
160 coords[1] = this.hold[this.holdIndex + 1];
161 if (type != 0) {
162 type = 1;
163 }}return type;
164 }, "~A");
165 Clazz.defineMethod (c$, "currentSegment", 
166 function (coords) {
167 if (this.isDone ()) {
168 throw  new java.util.NoSuchElementException ("flattening iterator out of bounds");
169 }var type = this.holdType;
170 if (type != 4) {
171 coords[0] = this.hold[this.holdIndex + 0];
172 coords[1] = this.hold[this.holdIndex + 1];
173 if (type != 0) {
174 type = 1;
175 }}return type;
176 }, "~A");
177 Clazz.defineStatics (c$,
178 "GROW_SIZE", 24);
179 });