/* */ package com.sun.j3d.utils.geometry;
/* */
/* */ import javax.vecmath.Point2f;
/* */
/* */ class Desperate
/* */ {
/* */ static boolean desperate(Triangulator triRef, int ind, int i, boolean[] splitted)
/* */ {
/* 34 */ int[] i1 = new int[1];
/* 35 */ int[] i2 = new int[1];
/* 36 */ int[] i3 = new int[1];
/* 37 */ int[] i4 = new int[1];
/* 38 */ int[] ind1 = new int[1];
/* 39 */ int[] ind2 = new int[1];
/* 40 */ int[] ind3 = new int[1];
/* 41 */ int[] ind4 = new int[1];
/* */
/* 43 */ splitted[0] = false;
/* */
/* 49 */ if (existsCrossOver(triRef, ind, ind1, i1, ind2, i2, ind3, i3, ind4, i4))
/* */ {
/* 54 */ handleCrossOver(triRef, ind1[0], i1[0], ind2[0], i2[0], ind3[0], i3[0], ind4[0], i4[0]);
/* */
/* 56 */ return false;
/* */ }
/* */
/* 59 */ NoHash.prepareNoHashEdges(triRef, i, i + 1);
/* */
/* 65 */ if (existsSplit(triRef, ind, ind1, i1, ind2, i2))
/* */ {
/* 73 */ handleSplit(triRef, ind1[0], i1[0], ind2[0], i2[0]);
/* 74 */ splitted[0] = true;
/* 75 */ return false;
/* */ }
/* */
/* 78 */ return true;
/* */ }
/* */
/* */ static boolean existsCrossOver(Triangulator triRef, int ind, int[] ind1, int[] i1, int[] ind2, int[] i2, int[] ind3, int[] i3, int[] ind4, int[] i4)
/* */ {
/* 88 */ ind1[0] = ind;
/* 89 */ i1[0] = triRef.fetchData(ind1[0]);
/* 90 */ ind2[0] = triRef.fetchNextData(ind1[0]);
/* 91 */ i2[0] = triRef.fetchData(ind2[0]);
/* 92 */ ind3[0] = triRef.fetchNextData(ind2[0]);
/* 93 */ i3[0] = triRef.fetchData(ind3[0]);
/* 94 */ ind4[0] = triRef.fetchNextData(ind3[0]);
/* 95 */ i4[0] = triRef.fetchData(ind4[0]);
/* */ do
/* */ {
/* 98 */ BBox bb1 = new BBox(triRef, i1[0], i2[0]);
/* 99 */ BBox bb2 = new BBox(triRef, i3[0], i4[0]);
/* 100 */ if ((bb1.BBoxOverlap(bb2)) &&
/* 101 */ (Numerics.segIntersect(triRef, bb1.imin, bb1.imax, bb2.imin, bb2.imax, -1))) {
/* 102 */ return true;
/* */ }
/* 104 */ ind1[0] = ind2[0];
/* 105 */ i1[0] = i2[0];
/* 106 */ ind2[0] = ind3[0];
/* 107 */ i2[0] = i3[0];
/* 108 */ ind3[0] = ind4[0];
/* 109 */ i3[0] = i4[0];
/* 110 */ ind4[0] = triRef.fetchNextData(ind3[0]);
/* 111 */ i4[0] = triRef.fetchData(ind4[0]);
/* */ }
/* 113 */ while (ind1[0] != ind);
/* */
/* 115 */ return false;
/* */ }
/* */
/* */ static void handleCrossOver(Triangulator triRef, int ind1, int i1, int ind2, int i2, int ind3, int i3, int ind4, int i4)
/* */ {
/* 130 */ int angle1 = triRef.getAngle(ind1);
/* 131 */ int angle4 = triRef.getAngle(ind4);
/* */ boolean first;
/* */ boolean first;
/* 132 */ if (angle1 < angle4) { first = true; }
/* */ else
/* */ {
/* 133 */ boolean first;
/* 133 */ if (angle1 > angle4) { first = false; }
/* */ else
/* */ {
/* */ boolean first;
/* 134 */ if (triRef.earsSorted) {
/* 135 */ double ratio1 = Numerics.getRatio(triRef, i3, i4, i1);
/* 136 */ double ratio4 = Numerics.getRatio(triRef, i1, i2, i4);
/* */ boolean first;
/* 137 */ if (ratio4 < ratio1) first = false; else
/* 138 */ first = true;
/* */ }
/* */ else {
/* 141 */ first = true;
/* */ }
/* */ }
/* */ }
/* 144 */ if (first)
/* */ {
/* 148 */ triRef.deleteLinks(ind2);
/* */
/* 150 */ triRef.storeTriangle(ind1, ind2, ind3);
/* 151 */ triRef.setAngle(ind3, 1);
/* 152 */ Heap.insertIntoHeap(triRef, 0.0D, ind3, ind1, ind4);
/* */ }
/* */ else
/* */ {
/* 158 */ triRef.deleteLinks(ind3);
/* */
/* 160 */ triRef.storeTriangle(ind2, ind3, ind4);
/* 161 */ triRef.setAngle(ind2, 1);
/* 162 */ Heap.insertIntoHeap(triRef, 0.0D, ind2, ind1, ind4);
/* */ }
/* */ }
/* */
/* */ static boolean letsHope(Triangulator triRef, int ind)
/* */ {
/* 177 */ int ind1 = ind;
/* 178 */ int i1 = triRef.fetchData(ind1);
/* */ do
/* */ {
/* 181 */ if (triRef.getAngle(ind1) > 0) {
/* 182 */ int ind0 = triRef.fetchPrevData(ind1);
/* 183 */ int i0 = triRef.fetchData(ind0);
/* 184 */ int ind2 = triRef.fetchNextData(ind1);
/* 185 */ int i2 = triRef.fetchData(ind2);
/* 186 */ Heap.insertIntoHeap(triRef, 0.0D, ind1, ind0, ind2);
/* 187 */ return true;
/* */ }
/* 189 */ ind1 = triRef.fetchNextData(ind1);
/* 190 */ i1 = triRef.fetchData(ind1);
/* 191 */ }while (ind1 != ind);
/* */
/* 198 */ triRef.setAngle(ind, 1);
/* 199 */ int ind0 = triRef.fetchPrevData(ind);
/* 200 */ int i0 = triRef.fetchData(ind0);
/* 201 */ int ind2 = triRef.fetchNextData(ind);
/* 202 */ int i2 = triRef.fetchData(ind2);
/* 203 */ Heap.insertIntoHeap(triRef, 0.0D, ind, ind0, ind2);
/* 204 */ i1 = triRef.fetchData(ind);
/* */
/* 206 */ return true;
/* */ }
/* */
/* */ static boolean existsSplit(Triangulator triRef, int ind, int[] ind1, int[] i1, int[] ind2, int[] i2)
/* */ {
/* 223 */ if (triRef.numPoints > triRef.maxNumDist)
/* */ {
/* 225 */ triRef.maxNumDist = triRef.numPoints;
/* 226 */ triRef.distances = new Distance[triRef.maxNumDist];
/* 227 */ for (int k = 0; k < triRef.maxNumDist; k++)
/* 228 */ triRef.distances[k] = new Distance();
/* */ }
/* 230 */ ind1[0] = ind;
/* 231 */ i1[0] = triRef.fetchData(ind1[0]);
/* 232 */ int ind4 = triRef.fetchNextData(ind1[0]);
/* 233 */ int i4 = triRef.fetchData(ind4);
/* */
/* 235 */ int ind5 = triRef.fetchNextData(ind4);
/* 236 */ int i5 = triRef.fetchData(ind5);
/* */
/* 238 */ int ind3 = triRef.fetchPrevData(ind1[0]);
/* 239 */ int i3 = triRef.fetchData(ind3);
/* */
/* 241 */ if (foundSplit(triRef, ind5, i5, ind3, ind1[0], i1[0], i3, i4, ind2, i2))
/* 242 */ return true;
/* 243 */ i3 = i1[0];
/* 244 */ ind1[0] = ind4;
/* 245 */ i1[0] = i4;
/* 246 */ ind4 = ind5;
/* 247 */ i4 = i5;
/* 248 */ ind5 = triRef.fetchNextData(ind4);
/* 249 */ i5 = triRef.fetchData(ind5);
/* */
/* 251 */ while (ind5 != ind) {
/* 252 */ if (foundSplit(triRef, ind5, i5, ind, ind1[0], i1[0], i3, i4, ind2, i2))
/* 253 */ return true;
/* 254 */ i3 = i1[0];
/* 255 */ ind1[0] = ind4;
/* 256 */ i1[0] = i4;
/* 257 */ ind4 = ind5;
/* 258 */ i4 = i5;
/* 259 */ ind5 = triRef.fetchNextData(ind4);
/* 260 */ i5 = triRef.fetchData(ind5);
/* */ }
/* */
/* 263 */ return false;
/* */ }
/* */
/* */ static int windingNumber(Triangulator triRef, int ind, Point2f p)
/* */ {
/* 281 */ int i1 = triRef.fetchData(ind);
/* 282 */ int ind2 = triRef.fetchNextData(ind);
/* 283 */ int i2 = triRef.fetchData(ind2);
/* 284 */ double angle = Numerics.angle(triRef, p, triRef.points[i1], triRef.points[i2]);
/* 285 */ while (ind2 != ind) {
/* 286 */ i1 = i2;
/* 287 */ ind2 = triRef.fetchNextData(ind2);
/* 288 */ i2 = triRef.fetchData(ind2);
/* 289 */ angle += Numerics.angle(triRef, p, triRef.points[i1], triRef.points[i2]);
/* */ }
/* */
/* 292 */ angle += 3.141592653589793D;
/* 293 */ int number = (int)(angle / 6.283185307179586D);
/* */
/* 295 */ return number;
/* */ }
/* */
/* */ static boolean foundSplit(Triangulator triRef, int ind5, int i5, int ind, int ind1, int i1, int i3, int i4, int[] ind2, int[] i2)
/* */ {
/* 305 */ int numDist = 0;
/* */ do
/* */ {
/* 316 */ triRef.distances[numDist].dist = Numerics.baseLength(triRef.points[i1], triRef.points[i5]);
/* */
/* 318 */ triRef.distances[numDist].ind = ind5;
/* 319 */ numDist++;
/* 320 */ ind5 = triRef.fetchNextData(ind5);
/* 321 */ i5 = triRef.fetchData(ind5);
/* 322 */ }while (ind5 != ind);
/* */
/* 324 */ Bridge.sortDistance(triRef.distances, numDist);
/* */
/* 329 */ for (int j = 0; j < numDist; j++) {
/* 330 */ ind2[0] = triRef.distances[j].ind;
/* 331 */ i2[0] = triRef.fetchData(ind2[0]);
/* 332 */ if (i1 != i2[0]) {
/* 333 */ int ind6 = triRef.fetchPrevData(ind2[0]);
/* 334 */ int i6 = triRef.fetchData(ind6);
/* 335 */ int ind7 = triRef.fetchNextData(ind2[0]);
/* 336 */ int i7 = triRef.fetchData(ind7);
/* */
/* 338 */ boolean convex = triRef.getAngle(ind2[0]) > 0;
/* 339 */ boolean coneOk = Numerics.isInCone(triRef, i6, i2[0], i7, i1, convex);
/* 340 */ if (coneOk) {
/* 341 */ convex = triRef.getAngle(ind1) > 0;
/* 342 */ coneOk = Numerics.isInCone(triRef, i3, i1, i4, i2[0], convex);
/* 343 */ if (coneOk) {
/* 344 */ BBox bb = new BBox(triRef, i1, i2[0]);
/* 345 */ if (!NoHash.noHashEdgeIntersectionExists(triRef, bb, -1, -1, ind1, -1))
/* */ {
/* 350 */ Point2f center = new Point2f();
/* 351 */ Basic.vectorAdd2D(triRef.points[i1], triRef.points[i2[0]], center);
/* 352 */ Basic.multScalar2D(0.5D, center);
/* 353 */ if (windingNumber(triRef, ind, center) == 1) return true;
/* */ }
/* */ }
/* */ }
/* */ }
/* */ }
/* */
/* 360 */ return false;
/* */ }
/* */
/* */ static void handleSplit(Triangulator triRef, int ind1, int i1, int ind3, int i3)
/* */ {
/* 368 */ int comIndex = -1;
/* */
/* 373 */ int ind2 = triRef.makeNode(i1);
/* 374 */ triRef.insertAfter(ind1, ind2);
/* */
/* 378 */ comIndex = triRef.list[ind1].getCommonIndex();
/* */
/* 380 */ triRef.list[ind2].setCommonIndex(comIndex);
/* */
/* 382 */ int ind4 = triRef.makeNode(i3);
/* 383 */ triRef.insertAfter(ind3, ind4);
/* */
/* 385 */ comIndex = triRef.list[ind3].getCommonIndex();
/* 386 */ triRef.list[ind4].setCommonIndex(comIndex);
/* */
/* 392 */ triRef.splitSplice(ind1, ind2, ind3, ind4);
/* */
/* 397 */ triRef.storeChain(ind1);
/* 398 */ triRef.storeChain(ind3);
/* */
/* 403 */ int next = triRef.fetchNextData(ind1);
/* 404 */ int nxt = triRef.fetchData(next);
/* 405 */ int prev = triRef.fetchPrevData(ind1);
/* 406 */ int prv = triRef.fetchData(prev);
/* 407 */ int angle = Numerics.isConvexAngle(triRef, prv, i1, nxt, ind1);
/* 408 */ triRef.setAngle(ind1, angle);
/* */
/* 410 */ next = triRef.fetchNextData(ind2);
/* 411 */ nxt = triRef.fetchData(next);
/* 412 */ prev = triRef.fetchPrevData(ind2);
/* 413 */ prv = triRef.fetchData(prev);
/* 414 */ angle = Numerics.isConvexAngle(triRef, prv, i1, nxt, ind2);
/* 415 */ triRef.setAngle(ind2, angle);
/* */
/* 417 */ next = triRef.fetchNextData(ind3);
/* 418 */ nxt = triRef.fetchData(next);
/* 419 */ prev = triRef.fetchPrevData(ind3);
/* 420 */ prv = triRef.fetchData(prev);
/* 421 */ angle = Numerics.isConvexAngle(triRef, prv, i3, nxt, ind3);
/* 422 */ triRef.setAngle(ind3, angle);
/* */
/* 424 */ next = triRef.fetchNextData(ind4);
/* 425 */ nxt = triRef.fetchData(next);
/* 426 */ prev = triRef.fetchPrevData(ind4);
/* 427 */ prv = triRef.fetchData(prev);
/* 428 */ angle = Numerics.isConvexAngle(triRef, prv, i3, nxt, ind4);
/* 429 */ triRef.setAngle(ind4, angle);
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.utils.geometry.Desperate
* JD-Core Version: 0.6.2
*/