/* */ package com.sun.j3d.utils.picking;
/* */
/* */ import com.sun.j3d.internal.Distance;
/* */ import com.sun.j3d.internal.UtilFreelistManager;
/* */ import com.sun.j3d.internal.UtilMemoryFreelist;
/* */ import com.sun.j3d.utils.geometry.Primitive;
/* */ import java.io.PrintStream;
/* */ import java.util.ArrayList;
/* */ import javax.media.j3d.BoundingBox;
/* */ import javax.media.j3d.BoundingPolytope;
/* */ import javax.media.j3d.BoundingSphere;
/* */ import javax.media.j3d.Bounds;
/* */ import javax.media.j3d.BranchGroup;
/* */ import javax.media.j3d.CompressedGeometry;
/* */ import javax.media.j3d.Geometry;
/* */ import javax.media.j3d.GeometryArray;
/* */ import javax.media.j3d.Group;
/* */ import javax.media.j3d.IndexedGeometryArray;
/* */ import javax.media.j3d.IndexedLineArray;
/* */ import javax.media.j3d.IndexedLineStripArray;
/* */ import javax.media.j3d.IndexedPointArray;
/* */ import javax.media.j3d.IndexedQuadArray;
/* */ import javax.media.j3d.IndexedTriangleArray;
/* */ import javax.media.j3d.IndexedTriangleFanArray;
/* */ import javax.media.j3d.IndexedTriangleStripArray;
/* */ import javax.media.j3d.LineArray;
/* */ import javax.media.j3d.LineStripArray;
/* */ import javax.media.j3d.Link;
/* */ import javax.media.j3d.Morph;
/* */ import javax.media.j3d.Node;
/* */ import javax.media.j3d.PickBounds;
/* */ import javax.media.j3d.PickCone;
/* */ import javax.media.j3d.PickConeRay;
/* */ import javax.media.j3d.PickConeSegment;
/* */ import javax.media.j3d.PickCylinder;
/* */ import javax.media.j3d.PickCylinderRay;
/* */ import javax.media.j3d.PickCylinderSegment;
/* */ import javax.media.j3d.PickPoint;
/* */ import javax.media.j3d.PickRay;
/* */ import javax.media.j3d.PickSegment;
/* */ import javax.media.j3d.PickShape;
/* */ import javax.media.j3d.PointArray;
/* */ import javax.media.j3d.QuadArray;
/* */ import javax.media.j3d.SceneGraphPath;
/* */ import javax.media.j3d.Shape3D;
/* */ import javax.media.j3d.Switch;
/* */ import javax.media.j3d.Transform3D;
/* */ import javax.media.j3d.TransformGroup;
/* */ import javax.media.j3d.TriangleArray;
/* */ import javax.media.j3d.TriangleFanArray;
/* */ import javax.media.j3d.TriangleStripArray;
/* */ import javax.vecmath.Point2d;
/* */ import javax.vecmath.Point3d;
/* */ import javax.vecmath.Point3f;
/* */ import javax.vecmath.Point4d;
/* */ import javax.vecmath.Vector3d;
/* */ import javax.vecmath.Vector4d;
/* */
/* */ public class PickResult
/* */ {
/* */ public static final int SHAPE3D = 1;
/* */ public static final int MORPH = 2;
/* */ public static final int PRIMITIVE = 4;
/* */ public static final int LINK = 8;
/* */ public static final int GROUP = 16;
/* */ public static final int TRANSFORM_GROUP = 32;
/* */ public static final int BRANCH_GROUP = 64;
/* */ public static final int SWITCH = 128;
/* 180 */ static boolean debug = false;
/* */
/* 183 */ boolean firstIntersectOnly = false;
/* */
/* 186 */ SceneGraphPath pickedSceneGraphPath = null;
/* */
/* 189 */ Node pickedNode = null;
/* */
/* 192 */ GeometryArray[] geometryArrays = null;
/* */
/* 195 */ Shape3D[] compressGeomShape3Ds = null;
/* */
/* 198 */ Transform3D localToVWorld = null;
/* */
/* 201 */ PickShape pickShape = null;
/* */
/* 203 */ int pickShapeType = -1;
/* 204 */ Vector3d pickShapeDir = null;
/* 205 */ Point3d pickShapeStart = null;
/* 206 */ Point3d pickShapeEnd = null;
/* 207 */ Bounds pickShapeBounds = null;
/* */
/* 209 */ static final Point3d zeroPnt = new Point3d();
/* */
/* 212 */ ArrayList intersections = null;
/* */ static final double FUZZ = 1.0E-006D;
/* */ static final int PICK_SHAPE_RAY = 1;
/* */ static final int PICK_SHAPE_SEGMENT = 2;
/* */ static final int PICK_SHAPE_POINT = 3;
/* */ static final int PICK_SHAPE_BOUNDING_BOX = 4;
/* */ static final int PICK_SHAPE_BOUNDING_SPHERE = 5;
/* */ static final int PICK_SHAPE_BOUNDING_POLYTOPE = 6;
/* */ static final int PICK_SHAPE_CYLINDER = 7;
/* */ static final int PICK_SHAPE_CONE = 8;
/* */ static final double EPS = 1.0E-013D;
/* */
/* */ PickResult()
/* */ {
/* */ }
/* */
/* */ public PickResult(SceneGraphPath sgp, PickShape ps)
/* */ {
/* 239 */ this.pickedSceneGraphPath = sgp;
/* 240 */ this.pickedNode = sgp.getObject();
/* 241 */ this.localToVWorld = sgp.getTransform();
/* 242 */ this.pickShape = ps;
/* 243 */ initPickShape();
/* */ }
/* */
/* */ public PickResult(Node pn, Transform3D l2vw, PickShape ps)
/* */ {
/* 254 */ if (((pn instanceof Shape3D)) || ((pn instanceof Morph))) {
/* 255 */ this.pickedNode = pn;
/* 256 */ this.localToVWorld = l2vw;
/* 257 */ this.pickShape = ps;
/* 258 */ initPickShape();
/* */ } else {
/* 260 */ throw new IllegalArgumentException();
/* */ }
/* */ }
/* */
/* */ void reset(SceneGraphPath sgp, PickShape ps)
/* */ {
/* 267 */ this.firstIntersectOnly = false;
/* 268 */ this.geometryArrays = null;
/* 269 */ this.compressGeomShape3Ds = null;
/* 270 */ this.pickShapeBounds = null;
/* 271 */ this.intersections = null;
/* 272 */ this.pickedSceneGraphPath = sgp;
/* 273 */ this.pickedNode = sgp.getObject();
/* 274 */ this.localToVWorld = sgp.getTransform();
/* 275 */ this.pickShape = ps;
/* 276 */ initPickShape();
/* */ }
/* */
/* */ void reset(Node pn, Transform3D l2vw, PickShape ps)
/* */ {
/* 282 */ if (((pn instanceof Shape3D)) || ((pn instanceof Morph))) {
/* 283 */ this.firstIntersectOnly = false;
/* 284 */ this.geometryArrays = null;
/* 285 */ this.compressGeomShape3Ds = null;
/* 286 */ this.pickShapeBounds = null;
/* 287 */ this.intersections = null;
/* 288 */ this.pickedSceneGraphPath = null;
/* 289 */ this.pickedNode = pn;
/* 290 */ this.localToVWorld = l2vw;
/* 291 */ this.pickShape = ps;
/* 292 */ initPickShape();
/* */ }
/* */ else {
/* 295 */ throw new IllegalArgumentException();
/* */ }
/* */ }
/* */
/* */ void initPickShape() {
/* 300 */ if ((this.pickShape instanceof PickRay)) {
/* 301 */ if (this.pickShapeStart == null) this.pickShapeStart = new Point3d();
/* 302 */ if (this.pickShapeDir == null) this.pickShapeDir = new Vector3d();
/* 303 */ ((PickRay)this.pickShape).get(this.pickShapeStart, this.pickShapeDir);
/* 304 */ this.pickShapeType = 1;
/* 305 */ } else if ((this.pickShape instanceof PickSegment)) {
/* 306 */ if (this.pickShapeStart == null) this.pickShapeStart = new Point3d();
/* 307 */ if (this.pickShapeEnd == null) this.pickShapeEnd = new Point3d();
/* 308 */ if (this.pickShapeDir == null) this.pickShapeDir = new Vector3d();
/* 309 */ ((PickSegment)this.pickShape).get(this.pickShapeStart, this.pickShapeEnd);
/* 310 */ this.pickShapeDir.set(this.pickShapeEnd.x - this.pickShapeStart.x, this.pickShapeEnd.y - this.pickShapeStart.y, this.pickShapeEnd.z - this.pickShapeStart.z);
/* */
/* 313 */ this.pickShapeType = 2;
/* 314 */ } else if ((this.pickShape instanceof PickBounds)) {
/* 315 */ this.pickShapeBounds = ((PickBounds)this.pickShape).get();
/* 316 */ if ((this.pickShapeBounds instanceof BoundingBox))
/* 317 */ this.pickShapeType = 4;
/* 318 */ else if ((this.pickShapeBounds instanceof BoundingSphere))
/* 319 */ this.pickShapeType = 5;
/* 320 */ else if ((this.pickShapeBounds instanceof BoundingPolytope))
/* 321 */ this.pickShapeType = 6;
/* */ } else { if ((this.pickShape instanceof PickPoint))
/* 323 */ throw new RuntimeException("PickPoint doesn't make sense for geometry-based picking. Java 3D doesn't have spatial information of the surface. Should use PickBounds with BoundingSphere and set radius to a epsilon tolerance.");
/* 324 */ if ((this.pickShape instanceof PickCylinder))
/* 325 */ this.pickShapeType = 7;
/* 326 */ else if ((this.pickShape instanceof PickCone))
/* 327 */ this.pickShapeType = 8;
/* */ else
/* 329 */ throw new RuntimeException("PickShape not supported for intersection");
/* */ }
/* */ }
/* */
/* */ public SceneGraphPath getSceneGraphPath()
/* */ {
/* 339 */ return this.pickedSceneGraphPath;
/* */ }
/* */
/* */ public Transform3D getLocalToVworld()
/* */ {
/* 346 */ return this.localToVWorld;
/* */ }
/* */
/* */ public GeometryArray getGeometryArray()
/* */ {
/* 352 */ if (this.geometryArrays == null) {
/* 353 */ storeGeometry();
/* */ }
/* 355 */ return this.geometryArrays[0];
/* */ }
/* */
/* */ public GeometryArray[] getGeometryArrays()
/* */ {
/* 361 */ if (this.geometryArrays == null) {
/* 362 */ storeGeometry();
/* */ }
/* 364 */ return this.geometryArrays;
/* */ }
/* */
/* */ public int numGeometryArrays()
/* */ {
/* 370 */ if (this.geometryArrays == null) {
/* 371 */ storeGeometry();
/* */ }
/* 373 */ return this.geometryArrays.length;
/* */ }
/* */
/* */ public int numCompressedGeometryShape3Ds()
/* */ {
/* 380 */ if (this.geometryArrays == null) {
/* 381 */ storeGeometry();
/* */ }
/* 383 */ if (this.compressGeomShape3Ds == null) {
/* 384 */ return 0;
/* */ }
/* 386 */ return this.compressGeomShape3Ds.length;
/* */ }
/* */
/* */ public Shape3D[] getCompressedGeometryShape3Ds()
/* */ {
/* 394 */ if (this.geometryArrays == null) {
/* 395 */ storeGeometry();
/* */ }
/* 397 */ if (this.compressGeomShape3Ds == null) {
/* 398 */ return null;
/* */ }
/* 400 */ return this.compressGeomShape3Ds;
/* */ }
/* */
/* */ public PickShape getPickShape()
/* */ {
/* 407 */ return this.pickShape;
/* */ }
/* */
/* */ public void setFirstIntersectOnly(boolean flag)
/* */ {
/* 415 */ this.firstIntersectOnly = flag;
/* */ }
/* */
/* */ public boolean getFirstPickEnable()
/* */ {
/* 420 */ return this.firstIntersectOnly;
/* */ }
/* */
/* */ public int numIntersections()
/* */ {
/* 427 */ if (this.intersections == null) {
/* 428 */ generateIntersections();
/* */ }
/* 430 */ return this.intersections.size();
/* */ }
/* */
/* */ public PickIntersection getIntersection(int index)
/* */ {
/* 438 */ if (this.intersections == null) {
/* 439 */ generateIntersections();
/* */ }
/* 441 */ return (PickIntersection)this.intersections.get(index);
/* */ }
/* */
/* */ public PickIntersection getClosestIntersection(Point3d pt)
/* */ {
/* 449 */ PickIntersection pi = null;
/* 450 */ PickIntersection curPi = null;
/* 451 */ Point3d curPt = null;
/* 452 */ double minDist = 1.7976931348623157E+308D;
/* 453 */ double curDist = 0.0D;
/* */
/* 455 */ if (pt == null) return null;
/* */
/* 457 */ if (this.intersections == null) {
/* 458 */ generateIntersections();
/* */ }
/* */
/* 461 */ for (int i = 0; i < this.intersections.size(); i++) {
/* 462 */ if ((null != (curPi = getIntersection(i))) && (null != (curPt = curPi.getPointCoordinatesVW())))
/* */ {
/* 464 */ curDist = pt.distance(curPt);
/* 465 */ if (curDist < minDist) {
/* 466 */ pi = curPi;
/* 467 */ minDist = curDist;
/* */ }
/* */ }
/* */ }
/* 471 */ return pi;
/* */ }
/* */
/* */ public String toString()
/* */ {
/* 480 */ String rt = new String("PickResult: sgp:" + this.pickedSceneGraphPath + "\n");
/* 481 */ if (this.pickedNode != null) rt = rt + " node:" + this.pickedNode;
/* */
/* 485 */ if (this.intersections == null) {
/* 486 */ generateIntersections();
/* */ }
/* */
/* 489 */ if (this.intersections.size() > 0) {
/* 490 */ for (int i = 0; i < this.intersections.size(); i++) {
/* 491 */ rt = rt + "\n";
/* 492 */ rt = rt + ((PickIntersection)this.intersections.get(i)).toString2();
/* */ }
/* */ }
/* */
/* 496 */ return rt;
/* */ }
/* */
/* */ private void storeGeometry()
/* */ {
/* 501 */ if ((this.pickedNode instanceof Morph)) {
/* 502 */ this.geometryArrays = new GeometryArray[1];
/* 503 */ this.geometryArrays[0] = ((Morph)this.pickedNode).getGeometryArray(0);
/* */ }
/* 505 */ else if ((this.pickedNode instanceof Shape3D)) {
/* 506 */ Shape3D shape = (Shape3D)this.pickedNode;
/* 507 */ ArrayList geoArrays = new ArrayList();
/* 508 */ for (int k = 0; k < shape.numGeometries(); k++) {
/* 509 */ Geometry geometry = shape.getGeometry(k);
/* 510 */ if ((geometry instanceof CompressedGeometry)) {
/* 511 */ Shape3D[] sa = ((CompressedGeometry)geometry).decompress();
/* */
/* 514 */ if (sa != null) {
/* 515 */ for (int j = 0; j < sa.length; j++) {
/* 516 */ for (int i = 0; i < sa[j].numGeometries(); i++) {
/* 517 */ geoArrays.add(sa[j].getGeometry(i));
/* */ }
/* */ }
/* */ }
/* 521 */ if (this.compressGeomShape3Ds == null)
/* */ {
/* 523 */ this.compressGeomShape3Ds = sa;
/* */ }
/* */ else {
/* 526 */ Shape3D[] save = this.compressGeomShape3Ds;
/* 527 */ int newLength = save.length + sa.length;
/* 528 */ this.compressGeomShape3Ds = new Shape3D[newLength];
/* 529 */ System.arraycopy(save, 0, this.compressGeomShape3Ds, 0, save.length);
/* */
/* 531 */ System.arraycopy(sa, 0, this.compressGeomShape3Ds, save.length, sa.length);
/* */ }
/* */ }
/* 534 */ else if ((geometry instanceof GeometryArray)) {
/* 535 */ geoArrays.add(geometry);
/* */ }
/* */ }
/* 538 */ this.geometryArrays = new GeometryArray[geoArrays.size()];
/* 539 */ for (int i = 0; i < geoArrays.size(); i++) {
/* 540 */ this.geometryArrays[i] = ((GeometryArray)geoArrays.get(i));
/* */ }
/* */ }
/* 543 */ if (this.geometryArrays == null)
/* */ {
/* */ Shape3D shape;
/* 544 */ if ((this.pickedNode instanceof Shape3D)) {
/* 545 */ shape = (Shape3D)this.pickedNode;
/* */ }
/* 547 */ throw new RuntimeException("Type of the picked node is not supported");
/* */ }
/* */ }
/* */
/* */ public Node getObject()
/* */ {
/* 554 */ if (this.pickedNode == null) {
/* 555 */ storeNode();
/* */ }
/* 557 */ return this.pickedNode;
/* */ }
/* */
/* */ void setObject(Node n)
/* */ {
/* 562 */ this.pickedNode = n;
/* */ }
/* */
/* */ public Node getNode(int flags)
/* */ {
/* 570 */ if (this.pickedNode == null) {
/* 571 */ storeNode();
/* */ }
/* 573 */ if (((this.pickedNode instanceof Shape3D)) && ((flags & 0x1) != 0)) {
/* 574 */ if (debug) System.out.println("Shape3D found");
/* 575 */ return this.pickedNode;
/* */ }
/* 577 */ if (((this.pickedNode instanceof Morph)) && ((flags & 0x2) != 0)) {
/* 578 */ if (debug) System.out.println("Morph found");
/* 579 */ return this.pickedNode;
/* */ }
/* */
/* 582 */ if (this.pickedSceneGraphPath == null) {
/* 583 */ return null;
/* */ }
/* 585 */ for (int j = this.pickedSceneGraphPath.nodeCount() - 1; j >= 0; j--) {
/* 586 */ Node pNode = this.pickedSceneGraphPath.getNode(j);
/* 587 */ if (debug) System.out.println("looking at node " + pNode);
/* */
/* 589 */ if (((pNode instanceof Primitive)) && ((flags & 0x4) != 0))
/* */ {
/* 591 */ if (debug) System.out.println("Primitive found");
/* 592 */ return pNode;
/* */ }
/* 594 */ if (((pNode instanceof Link)) && ((flags & 0x8) != 0)) {
/* 595 */ if (debug) System.out.println("Link found");
/* 596 */ return pNode;
/* */ }
/* 598 */ if (((pNode instanceof Switch)) && ((flags & 0x80) != 0)) {
/* 599 */ if (debug) System.out.println("Switch found");
/* 600 */ return pNode;
/* */ }
/* 602 */ if (((pNode instanceof TransformGroup)) && ((flags & 0x20) != 0))
/* */ {
/* 604 */ if (debug) System.out.println("xform group found");
/* 605 */ return pNode;
/* */ }
/* 607 */ if (((pNode instanceof BranchGroup)) && ((flags & 0x40) != 0))
/* */ {
/* 609 */ if (debug) System.out.println("Branch group found");
/* 610 */ return pNode;
/* */ }
/* 612 */ if (((pNode instanceof Group)) && ((flags & 0x10) != 0)) {
/* 613 */ if (debug) System.out.println("Group found");
/* 614 */ return pNode;
/* */ }
/* */ }
/* */
/* 618 */ return null;
/* */ }
/* */
/* */ void storeNode()
/* */ {
/* 623 */ if (this.pickedSceneGraphPath == null) {
/* 624 */ throw new RuntimeException("SceneGraphPath missing");
/* */ }
/* 626 */ this.pickedNode = this.pickedSceneGraphPath.getObject();
/* */ }
/* */
/* */ boolean generateIntersections()
/* */ {
/* 631 */ if (this.geometryArrays == null) {
/* 632 */ storeGeometry();
/* */ }
/* 634 */ this.intersections = new ArrayList();
/* 635 */ int hits = 0;
/* */
/* 637 */ for (int i = 0; i < this.geometryArrays.length; i++) {
/* 638 */ if (intersect(i, this.firstIntersectOnly)) {
/* 639 */ if (this.firstIntersectOnly) {
/* 640 */ return true;
/* */ }
/* 642 */ hits++;
/* */ }
/* */ }
/* */
/* 646 */ return hits > 0;
/* */ }
/* */
/* */ final boolean intersect(int geomIndex, boolean firstpick)
/* */ {
/* 656 */ GeometryArray geom = this.geometryArrays[geomIndex];
/* 657 */ int numPts = geom.getVertexCount();
/* 658 */ double[] doubleData = null;
/* 659 */ float[] floatData = null;
/* 660 */ Point3d[] p3dData = null;
/* 661 */ Point3f[] p3fData = null;
/* 662 */ int vformat = geom.getVertexFormat();
/* */
/* 664 */ boolean retFlag = false;
/* */
/* 666 */ if ((vformat & 0x80) == 0) {
/* 667 */ doubleData = new double[numPts * 3];
/* 668 */ geom.getCoordinates(0, doubleData);
/* */ }
/* 671 */ else if ((vformat & 0x100) == 0) {
/* 672 */ doubleData = geom.getCoordRefDouble();
/* */
/* 674 */ if (doubleData == null) {
/* 675 */ floatData = geom.getCoordRefFloat();
/* 676 */ if (floatData == null) {
/* 677 */ p3fData = geom.getCoordRef3f();
/* 678 */ if (p3fData == null)
/* 679 */ p3dData = geom.getCoordRef3d();
/* */ }
/* */ }
/* */ }
/* */ else
/* */ {
/* 685 */ floatData = geom.getInterleavedVertices();
/* */ }
/* */
/* 690 */ Point3d[] pnts = new Point3d[numPts];
/* */
/* 700 */ if (debug) {
/* 701 */ System.out.println("localToVWorld = " + this.localToVWorld);
/* */ }
/* 703 */ if ((vformat & 0x100) == 0) {
/* 704 */ if (doubleData != null) {
/* 705 */ int offset = 0;
/* 706 */ for (int i = 0; i < numPts; i++)
/* */ {
/* 709 */ pnts[i] = getPoint3d();
/* 710 */ pnts[i].x = doubleData[(offset++)];
/* 711 */ pnts[i].y = doubleData[(offset++)];
/* 712 */ pnts[i].z = doubleData[(offset++)];
/* */
/* 714 */ this.localToVWorld.transform(pnts[i]);
/* */ }
/* */ }
/* 717 */ else if (floatData != null) {
/* 718 */ int offset = 0;
/* 719 */ for (int i = 0; i < numPts; i++)
/* */ {
/* 722 */ pnts[i] = getPoint3d();
/* 723 */ pnts[i].x = floatData[(offset++)];
/* 724 */ pnts[i].y = floatData[(offset++)];
/* 725 */ pnts[i].z = floatData[(offset++)];
/* */
/* 727 */ this.localToVWorld.transform(pnts[i]);
/* */ }
/* */ }
/* 730 */ else if (p3fData != null) {
/* 731 */ for (int i = 0; i < numPts; i++)
/* */ {
/* 734 */ pnts[i] = getPoint3d();
/* 735 */ pnts[i].set(p3fData[i]);
/* 736 */ this.localToVWorld.transform(pnts[i]);
/* */ }
/* */ }
/* */ else {
/* 740 */ for (int i = 0; i < numPts; i++)
/* */ {
/* 743 */ pnts[i] = getPoint3d();
/* 744 */ pnts[i].set(p3dData[i]);
/* 745 */ this.localToVWorld.transform(pnts[i]);
/* */ }
/* */ }
/* */ }
/* */ else
/* */ {
/* 751 */ int offset = 0;
/* 752 */ if ((vformat & 0x4) == 4) {
/* 753 */ offset += 3;
/* */ }
/* 755 */ else if ((vformat & 0xC) == 12) {
/* 756 */ offset += 4;
/* */ }
/* 758 */ if ((vformat & 0x2) != 0)
/* 759 */ offset += 3;
/* 760 */ if ((vformat & 0x20) == 32) {
/* 761 */ offset += 2 * geom.getTexCoordSetCount();
/* */ }
/* 763 */ else if ((vformat & 0x40) == 64) {
/* 764 */ offset += 3 * geom.getTexCoordSetCount();
/* */ }
/* 766 */ int stride = offset + 3;
/* 767 */ for (int i = 0; i < numPts; i++)
/* */ {
/* 770 */ pnts[i] = getPoint3d();
/* 771 */ pnts[i].x = floatData[offset];
/* 772 */ pnts[i].y = floatData[(offset + 1)];
/* 773 */ pnts[i].z = floatData[(offset + 2)];
/* */
/* 775 */ this.localToVWorld.transform(pnts[i]);
/* 776 */ offset += stride;
/* */ }
/* */ }
/* */
/* 780 */ PickIntersection pi = new PickIntersection(this, geom);
/* */
/* 782 */ if ((geom instanceof PointArray)) {
/* 783 */ retFlag = intersectPA((PointArray)geom, geomIndex, pnts, firstpick, pi);
/* 784 */ } else if ((geom instanceof IndexedPointArray)) {
/* 785 */ pi.iGeom = ((IndexedGeometryArray)geom);
/* 786 */ retFlag = intersectIPA((IndexedPointArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 788 */ else if ((geom instanceof LineArray)) {
/* 789 */ retFlag = intersectLA((LineArray)geom, geomIndex, pnts, firstpick, pi);
/* 790 */ } else if ((geom instanceof LineStripArray)) {
/* 791 */ retFlag = intersectLSA((LineStripArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 793 */ else if ((geom instanceof IndexedLineArray)) {
/* 794 */ pi.iGeom = ((IndexedGeometryArray)geom);
/* 795 */ retFlag = intersectILA((IndexedLineArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 797 */ else if ((geom instanceof IndexedLineStripArray)) {
/* 798 */ pi.iGeom = ((IndexedGeometryArray)geom);
/* 799 */ retFlag = intersectILSA((IndexedLineStripArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 801 */ else if ((geom instanceof TriangleArray)) {
/* 802 */ retFlag = intersectTA((TriangleArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 804 */ else if ((geom instanceof TriangleStripArray)) {
/* 805 */ retFlag = intersectTSA((TriangleStripArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 807 */ else if ((geom instanceof TriangleFanArray)) {
/* 808 */ retFlag = intersectTFA((TriangleFanArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 810 */ else if ((geom instanceof IndexedTriangleArray)) {
/* 811 */ pi.iGeom = ((IndexedGeometryArray)geom);
/* 812 */ retFlag = intersectITA((IndexedTriangleArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 814 */ else if ((geom instanceof IndexedTriangleStripArray)) {
/* 815 */ pi.iGeom = ((IndexedGeometryArray)geom);
/* 816 */ retFlag = intersectITSA((IndexedTriangleStripArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 818 */ else if ((geom instanceof IndexedTriangleFanArray)) {
/* 819 */ pi.iGeom = ((IndexedGeometryArray)geom);
/* 820 */ retFlag = intersectITFA((IndexedTriangleFanArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* 822 */ else if ((geom instanceof QuadArray)) {
/* 823 */ retFlag = intersectQA((QuadArray)geom, geomIndex, pnts, firstpick, pi);
/* 824 */ } else if ((geom instanceof IndexedQuadArray)) {
/* 825 */ pi.iGeom = ((IndexedGeometryArray)geom);
/* 826 */ retFlag = intersectIQA((IndexedQuadArray)geom, geomIndex, pnts, firstpick, pi);
/* */ }
/* */ else {
/* 829 */ throw new RuntimeException("incorrect class type");
/* */ }
/* */
/* 832 */ if (!retFlag) {
/* 833 */ for (int i = 0; i < numPts; i++) {
/* 834 */ freePoint3d(pnts[i]);
/* */ }
/* */ }
/* */
/* 838 */ return retFlag;
/* */ }
/* */
/* */ boolean intersectPoint(int[] vertidx, int[] coordidx, int geomIndex, Point3d[] pnts, PickIntersection pi)
/* */ {
/* 852 */ Point3d[] point = new Point3d[1];
/* 853 */ point[0] = pnts[coordidx[0]];
/* */
/* 855 */ if (debug) {
/* 856 */ System.out.println("intersect point, point = " + point[0]);
/* */ }
/* */
/* 859 */ boolean intersect = false;
/* 860 */ switch (this.pickShapeType) {
/* */ case 1:
/* 862 */ intersect = intersectPntAndRay(point[0], this.pickShapeStart, this.pickShapeDir, pi);
/* */
/* 864 */ break;
/* */ case 2:
/* 866 */ if ((intersectPntAndRay(point[0], this.pickShapeStart, this.pickShapeDir, pi)) &&
/* 867 */ (pi.getDistance() <= 1.0D))
/* 868 */ intersect = true; break;
/* */ case 4:
/* 878 */ intersect = ((BoundingBox)this.pickShapeBounds).intersect(point[0]);
/* 879 */ pi.setPointCoordinatesVW(point[0]);
/* 880 */ break;
/* */ case 5:
/* 882 */ intersect = ((BoundingSphere)this.pickShapeBounds).intersect(point[0]);
/* 883 */ pi.setPointCoordinatesVW(point[0]);
/* 884 */ break;
/* */ case 6:
/* 886 */ intersect = ((BoundingPolytope)this.pickShapeBounds).intersect(point[0]);
/* 887 */ pi.setPointCoordinatesVW(point[0]);
/* 888 */ break;
/* */ case 7:
/* 890 */ intersect = intersectCylinder(point[0], (PickCylinder)this.pickShape, pi);
/* 891 */ break;
/* */ case 8:
/* 893 */ intersect = intersectCone(point[0], (PickCone)this.pickShape, pi);
/* */ case 3:
/* */ }
/* 896 */ if (intersect) {
/* 897 */ PickIntersection newpi = new PickIntersection(this, pi.geom);
/* 898 */ newpi.iGeom = pi.iGeom;
/* 899 */ newpi.setDistance(pi.distance);
/* 900 */ newpi.setPointCoordinatesVW(pi.getPointCoordinatesVW());
/* */
/* 903 */ newpi.setGeomIndex(geomIndex);
/* 904 */ newpi.setVertexIndices(vertidx);
/* 905 */ newpi.setPrimitiveCoordinatesVW(point);
/* 906 */ this.intersections.add(newpi);
/* 907 */ return true;
/* */ }
/* 909 */ return false;
/* */ }
/* */
/* */ boolean intersectLine(int[] vertidx, int[] coordidx, int geomIndex, Point3d[] pnts, PickIntersection pi)
/* */ {
/* 915 */ Point3d[] linePts = new Point3d[2];
/* 916 */ linePts[0] = pnts[coordidx[0]];
/* 917 */ linePts[1] = pnts[coordidx[1]];
/* */
/* 919 */ boolean intersect = false;
/* 920 */ switch (this.pickShapeType) {
/* */ case 1:
/* 922 */ intersect = intersectLineAndRay(linePts[0], linePts[1], this.pickShapeStart, this.pickShapeDir, pi);
/* */
/* 924 */ break;
/* */ case 2:
/* 926 */ if (intersectLineAndRay(linePts[0], linePts[1], this.pickShapeStart, this.pickShapeDir, pi))
/* */ {
/* 928 */ if (pi.getDistance() <= 1.0D)
/* 929 */ intersect = true; } break;
/* */ case 4:
/* 946 */ intersect = intersectBoundingBox(linePts, (BoundingBox)this.pickShapeBounds);
/* */
/* 948 */ pi.setPointCoordinatesVW(zeroPnt);
/* 949 */ break;
/* */ case 5:
/* 951 */ intersect = intersectBoundingSphere(linePts, (BoundingSphere)this.pickShapeBounds);
/* */
/* 953 */ pi.setPointCoordinatesVW(zeroPnt);
/* 954 */ break;
/* */ case 6:
/* 956 */ intersect = intersectBoundingPolytope(linePts, (BoundingPolytope)this.pickShapeBounds);
/* */
/* 958 */ pi.setPointCoordinatesVW(zeroPnt);
/* 959 */ break;
/* */ case 7:
/* 961 */ intersect = intersectCylinder(linePts, (PickCylinder)this.pickShape, pi);
/* 962 */ break;
/* */ case 8:
/* 964 */ intersect = intersectCone(linePts, (PickCone)this.pickShape, pi);
/* */ case 3:
/* */ }
/* 967 */ if (intersect) {
/* 968 */ PickIntersection newpi = new PickIntersection(this, pi.geom);
/* 969 */ newpi.iGeom = pi.iGeom;
/* 970 */ newpi.setDistance(pi.distance);
/* 971 */ newpi.setPointCoordinatesVW(pi.getPointCoordinatesVW());
/* */
/* 974 */ newpi.setGeomIndex(geomIndex);
/* 975 */ newpi.setVertexIndices(vertidx);
/* 976 */ newpi.setPrimitiveCoordinatesVW(linePts);
/* 977 */ this.intersections.add(newpi);
/* 978 */ return true;
/* */ }
/* 980 */ return false;
/* */ }
/* */
/* */ boolean intersectTri(int[] vertidx, int[] coordidx, int geomIndex, Point3d[] pnts, PickIntersection pi)
/* */ {
/* 986 */ Point3d[] triPts = new Point3d[3];
/* */
/* 988 */ triPts[0] = pnts[coordidx[0]];
/* 989 */ triPts[1] = pnts[coordidx[1]];
/* 990 */ triPts[2] = pnts[coordidx[2]];
/* */
/* 993 */ boolean intersect = false;
/* 994 */ switch (this.pickShapeType) {
/* */ case 1:
/* 996 */ intersect = intersectRay(triPts, (PickRay)this.pickShape, pi);
/* 997 */ break;
/* */ case 2:
/* 999 */ intersect = intersectSegment(triPts, (PickSegment)this.pickShape, pi);
/* 1000 */ break;
/* */ case 4:
/* 1007 */ intersect = intersectBoundingBox(triPts, (BoundingBox)this.pickShapeBounds);
/* */
/* 1009 */ pi.setPointCoordinatesVW(zeroPnt);
/* 1010 */ break;
/* */ case 5:
/* 1012 */ intersect = intersectBoundingSphere(triPts, (BoundingSphere)this.pickShapeBounds);
/* */
/* 1014 */ pi.setPointCoordinatesVW(zeroPnt);
/* 1015 */ break;
/* */ case 6:
/* 1017 */ intersect = intersectBoundingPolytope(triPts, (BoundingPolytope)this.pickShapeBounds);
/* */
/* 1019 */ pi.setPointCoordinatesVW(zeroPnt);
/* 1020 */ break;
/* */ case 7:
/* 1022 */ intersect = intersectCylinder(triPts, (PickCylinder)this.pickShape, pi);
/* 1023 */ break;
/* */ case 8:
/* 1025 */ intersect = intersectCone(triPts, (PickCone)this.pickShape, pi);
/* */ case 3:
/* */ }
/* 1028 */ if (intersect) {
/* 1029 */ PickIntersection newpi = new PickIntersection(this, pi.geom);
/* 1030 */ newpi.iGeom = pi.iGeom;
/* 1031 */ newpi.setDistance(pi.distance);
/* 1032 */ newpi.setPointCoordinatesVW(pi.getPointCoordinatesVW());
/* */
/* 1035 */ newpi.setGeomIndex(geomIndex);
/* 1036 */ newpi.setVertexIndices(vertidx);
/* */
/* 1038 */ newpi.setPrimitiveCoordinatesVW(triPts);
/* 1039 */ this.intersections.add(newpi);
/* 1040 */ return true;
/* */ }
/* 1042 */ return false;
/* */ }
/* */
/* */ boolean intersectQuad(int[] vertidx, int[] coordidx, int geomIndex, Point3d[] pnts, PickIntersection pi)
/* */ {
/* 1048 */ Point3d[] quadPts = new Point3d[4];
/* */
/* 1050 */ quadPts[0] = pnts[coordidx[0]];
/* 1051 */ quadPts[1] = pnts[coordidx[1]];
/* 1052 */ quadPts[2] = pnts[coordidx[2]];
/* 1053 */ quadPts[3] = pnts[coordidx[3]];
/* */
/* 1057 */ boolean intersect = false;
/* 1058 */ switch (this.pickShapeType) {
/* */ case 1:
/* 1060 */ intersect = intersectRay(quadPts, (PickRay)this.pickShape, pi);
/* 1061 */ break;
/* */ case 2:
/* 1063 */ intersect = intersectSegment(quadPts, (PickSegment)this.pickShape, pi);
/* 1064 */ break;
/* */ case 4:
/* 1071 */ intersect = intersectBoundingBox(quadPts, (BoundingBox)this.pickShapeBounds);
/* */
/* 1073 */ pi.setPointCoordinatesVW(zeroPnt);
/* 1074 */ break;
/* */ case 5:
/* 1076 */ intersect = intersectBoundingSphere(quadPts, (BoundingSphere)this.pickShapeBounds);
/* */
/* 1078 */ pi.setPointCoordinatesVW(zeroPnt);
/* 1079 */ break;
/* */ case 6:
/* 1081 */ intersect = intersectBoundingPolytope(quadPts, (BoundingPolytope)this.pickShapeBounds);
/* */
/* 1083 */ pi.setPointCoordinatesVW(zeroPnt);
/* 1084 */ break;
/* */ case 7:
/* 1086 */ intersect = intersectCylinder(quadPts, (PickCylinder)this.pickShape, pi);
/* 1087 */ break;
/* */ case 8:
/* 1089 */ intersect = intersectCone(quadPts, (PickCone)this.pickShape, pi);
/* */ case 3:
/* */ }
/* 1092 */ if (intersect) {
/* 1093 */ PickIntersection newpi = new PickIntersection(this, pi.geom);
/* 1094 */ newpi.iGeom = pi.iGeom;
/* 1095 */ newpi.setDistance(pi.distance);
/* 1096 */ newpi.setPointCoordinatesVW(pi.getPointCoordinatesVW());
/* */
/* 1099 */ newpi.setGeomIndex(geomIndex);
/* 1100 */ newpi.setVertexIndices(vertidx);
/* 1101 */ newpi.setPrimitiveCoordinatesVW(quadPts);
/* 1102 */ this.intersections.add(newpi);
/* 1103 */ return true;
/* */ }
/* 1105 */ return false;
/* */ }
/* */
/* */ boolean intersectPA(PointArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1118 */ if (debug) System.out.println("intersect: PointArray");
/* */
/* 1120 */ int[] pntVertIdx = new int[1];
/* 1121 */ int numint = 0;
/* */
/* 1123 */ for (int i = 0; i < pnts.length; i++) {
/* 1124 */ pntVertIdx[0] = i;
/* 1125 */ if (intersectPoint(pntVertIdx, pntVertIdx, geomIndex, pnts, pi)) {
/* 1126 */ numint++;
/* 1127 */ if (firstpick) return true;
/* */ }
/* */ }
/* 1130 */ if (numint > 0) return true;
/* 1131 */ return false;
/* */ }
/* */
/* */ boolean intersectIPA(IndexedPointArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1140 */ if (debug) System.out.println("intersect: IndexedPointArray");
/* */
/* 1142 */ int[] pntVertIdx = new int[1];
/* 1143 */ int[] pntCoordIdx = new int[1];
/* */
/* 1145 */ int numint = 0;
/* 1146 */ int indexCount = geom.getIndexCount();
/* */
/* 1148 */ for (int i = 0; i < indexCount; i++) {
/* 1149 */ pntVertIdx[0] = i;
/* 1150 */ pntCoordIdx[0] = geom.getCoordinateIndex(i);
/* 1151 */ if (intersectPoint(pntVertIdx, pntCoordIdx, geomIndex, pnts, pi)) {
/* 1152 */ numint++;
/* 1153 */ if (firstpick) return true;
/* */ }
/* */ }
/* 1156 */ if (numint > 0) return true;
/* 1157 */ return false;
/* */ }
/* */
/* */ boolean intersectLA(LineArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1170 */ if (debug) System.out.println("intersect: LineArray");
/* */
/* 1172 */ int[] lineVertIdx = new int[2];
/* */
/* 1174 */ int numint = 0;
/* */
/* 1176 */ for (int i = 0; i < pnts.length; )
/* */ {
/* 1178 */ lineVertIdx[0] = (i++);
/* 1179 */ lineVertIdx[1] = (i++);
/* 1180 */ if (intersectLine(lineVertIdx, lineVertIdx, geomIndex, pnts, pi)) {
/* 1181 */ numint++;
/* 1182 */ if (firstpick) return true;
/* */ }
/* */ }
/* 1185 */ if (numint > 0) return true;
/* 1186 */ return false;
/* */ }
/* */
/* */ boolean intersectLSA(LineStripArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1194 */ int numint = 0;
/* */
/* 1196 */ int[] stripVertexCounts = new int[geom.getNumStrips()];
/* 1197 */ geom.getStripVertexCounts(stripVertexCounts);
/* 1198 */ int stripStart = 0;
/* */
/* 1200 */ if (debug) System.out.println("intersect: LineStripArray");
/* */
/* 1202 */ int[] lineVertIdx = new int[2];
/* */
/* 1204 */ for (int i = 0; i < stripVertexCounts.length; i++) {
/* 1205 */ lineVertIdx[0] = stripStart;
/* 1206 */ int end = stripStart + stripVertexCounts[i];
/* */
/* 1208 */ for (int j = stripStart + 1; j < end; j++) {
/* 1209 */ lineVertIdx[1] = j;
/* 1210 */ if (intersectLine(lineVertIdx, lineVertIdx, geomIndex, pnts, pi)) {
/* 1211 */ numint++;
/* 1212 */ if (firstpick) return true;
/* */ }
/* 1214 */ lineVertIdx[0] = lineVertIdx[1];
/* */ }
/* 1216 */ stripStart += stripVertexCounts[i];
/* */ }
/* 1218 */ if (numint > 0) return true;
/* 1219 */ return false;
/* */ }
/* */
/* */ boolean intersectILA(IndexedLineArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1228 */ int numint = 0;
/* 1229 */ int indexCount = geom.getIndexCount();
/* 1230 */ if (debug) System.out.println("intersect: IndexedLineArray");
/* */
/* 1232 */ int[] lineVertIdx = new int[2];
/* 1233 */ int[] lineCoordIdx = new int[2];
/* */
/* 1235 */ for (int i = 0; i < indexCount; ) {
/* 1236 */ lineVertIdx[0] = i;
/* 1237 */ lineCoordIdx[0] = geom.getCoordinateIndex(i++);
/* 1238 */ lineVertIdx[1] = i;
/* 1239 */ lineCoordIdx[1] = geom.getCoordinateIndex(i++);
/* 1240 */ if (intersectLine(lineVertIdx, lineCoordIdx, geomIndex, pnts, pi)) {
/* 1241 */ numint++;
/* 1242 */ if (firstpick) return true;
/* */ }
/* */ }
/* 1245 */ if (numint > 0) return true;
/* 1246 */ return false;
/* */ }
/* */
/* */ boolean intersectILSA(IndexedLineStripArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1254 */ if (debug) System.out.println("intersect: IndexedLineStripArray");
/* */
/* 1256 */ int[] lineVertIdx = new int[2];
/* 1257 */ int[] lineCoordIdx = new int[2];
/* */
/* 1259 */ int numint = 0;
/* 1260 */ int[] stripVertexCounts = new int[geom.getNumStrips()];
/* 1261 */ geom.getStripIndexCounts(stripVertexCounts);
/* 1262 */ int stripStart = 0;
/* */
/* 1264 */ for (int i = 0; i < stripVertexCounts.length; i++)
/* */ {
/* 1266 */ lineVertIdx[0] = stripStart;
/* 1267 */ lineCoordIdx[0] = geom.getCoordinateIndex(stripStart);
/* 1268 */ int end = stripStart + stripVertexCounts[i];
/* 1269 */ for (int j = stripStart + 1; j < end; j++) {
/* 1270 */ lineVertIdx[1] = j;
/* 1271 */ lineCoordIdx[1] = geom.getCoordinateIndex(j);
/* 1272 */ if (intersectLine(lineVertIdx, lineCoordIdx, geomIndex, pnts, pi)) {
/* 1273 */ numint++;
/* 1274 */ if (firstpick) return true;
/* */ }
/* 1276 */ lineVertIdx[0] = lineVertIdx[1];
/* 1277 */ lineCoordIdx[0] = lineCoordIdx[1];
/* */ }
/* 1279 */ stripStart += stripVertexCounts[i];
/* */ }
/* 1281 */ if (numint > 0) return true;
/* 1282 */ return false;
/* */ }
/* */
/* */ boolean intersectTA(TriangleArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1291 */ if (debug) {
/* 1292 */ System.out.println("intersect: TriangleArray");
/* */ }
/* 1294 */ int[] triVertIdx = new int[3];
/* */
/* 1296 */ int numint = 0;
/* 1297 */ for (int i = 0; i < pnts.length; ) {
/* 1298 */ triVertIdx[0] = (i++);
/* 1299 */ triVertIdx[1] = (i++);
/* 1300 */ triVertIdx[2] = (i++);
/* 1301 */ if (intersectTri(triVertIdx, triVertIdx, geomIndex, pnts, pi)) {
/* 1302 */ numint++;
/* 1303 */ if (firstpick) return true;
/* */ }
/* */ }
/* */
/* 1307 */ if (numint > 0) return true;
/* 1308 */ return false;
/* */ }
/* */
/* */ boolean intersectITA(IndexedTriangleArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1317 */ if (debug) {
/* 1318 */ System.out.println("intersect: IndexedTriangleArray");
/* */ }
/* 1320 */ int[] triVertIdx = new int[3];
/* 1321 */ int[] triCoordIdx = new int[3];
/* */
/* 1323 */ int numint = 0;
/* 1324 */ int indexCount = geom.getIndexCount();
/* 1325 */ for (int i = 0; i < indexCount; ) {
/* 1326 */ triVertIdx[0] = i;
/* 1327 */ triCoordIdx[0] = geom.getCoordinateIndex(i++);
/* 1328 */ triVertIdx[1] = i;
/* 1329 */ triCoordIdx[1] = geom.getCoordinateIndex(i++);
/* 1330 */ triVertIdx[2] = i;
/* 1331 */ triCoordIdx[2] = geom.getCoordinateIndex(i++);
/* 1332 */ if (intersectTri(triVertIdx, triCoordIdx, geomIndex, pnts, pi)) {
/* 1333 */ numint++;
/* 1334 */ if (firstpick) return true;
/* */ }
/* */ }
/* */
/* 1338 */ if (numint > 0) return true;
/* 1339 */ return false;
/* */ }
/* */
/* */ boolean intersectTSA(TriangleStripArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1347 */ if (debug) {
/* 1348 */ System.out.println("intersect: TriangleStripArray");
/* */ }
/* */
/* 1351 */ int numint = 0;
/* 1352 */ int[] stripVertexCounts = new int[geom.getNumStrips()];
/* 1353 */ geom.getStripVertexCounts(stripVertexCounts);
/* 1354 */ int stripStart = 0;
/* */
/* 1356 */ int[] triVertIdx = new int[3];
/* */
/* 1358 */ for (int i = 0; i < stripVertexCounts.length; i++)
/* */ {
/* 1360 */ int start = stripStart;
/* */
/* 1362 */ boolean ccw = true;
/* 1363 */ triVertIdx[0] = (start++);
/* 1364 */ triVertIdx[1] = (start++);
/* */
/* 1366 */ int end = start + stripVertexCounts[i] - 2;
/* 1367 */ for (int j = start; j < end; j++)
/* */ {
/* 1375 */ triVertIdx[2] = j;
/* 1376 */ if (intersectTri(triVertIdx, triVertIdx, geomIndex, pnts, pi)) {
/* 1377 */ numint++;
/* 1378 */ if (firstpick) return true;
/* */
/* */ }
/* */
/* 1394 */ triVertIdx[0] = triVertIdx[1];
/* 1395 */ triVertIdx[1] = triVertIdx[2];
/* */ }
/* */
/* 1398 */ stripStart += stripVertexCounts[i];
/* */ }
/* */
/* 1401 */ if (numint > 0) return true;
/* 1402 */ return false;
/* */ }
/* */
/* */ boolean intersectITSA(IndexedTriangleStripArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1411 */ if (debug)
/* 1412 */ System.out.println("intersect: IndexedTriangleStripArray");
/* 1413 */ int numint = 0;
/* */
/* 1416 */ int[] stripVertexCounts = new int[geom.getNumStrips()];
/* 1417 */ geom.getStripIndexCounts(stripVertexCounts);
/* 1418 */ int stripStart = 0;
/* */
/* 1420 */ int[] triVertIdx = new int[3];
/* 1421 */ int[] triCoordIdx = new int[3];
/* */
/* 1423 */ for (int i = 0; i < stripVertexCounts.length; i++)
/* */ {
/* 1425 */ int start = stripStart;
/* */
/* 1427 */ boolean ccw = true;
/* 1428 */ triCoordIdx[0] = geom.getCoordinateIndex(start);
/* 1429 */ triVertIdx[0] = (start++);
/* 1430 */ triCoordIdx[1] = geom.getCoordinateIndex(start);
/* 1431 */ triVertIdx[1] = (start++);
/* */
/* 1433 */ int end = start + stripVertexCounts[i] - 2;
/* 1434 */ for (int j = start; j < end; j++) {
/* 1435 */ if (ccw) {
/* 1436 */ triVertIdx[2] = j;
/* 1437 */ triCoordIdx[2] = geom.getCoordinateIndex(j);
/* */ } else {
/* 1439 */ triVertIdx[1] = j;
/* 1440 */ triCoordIdx[1] = geom.getCoordinateIndex(j);
/* */ }
/* */
/* 1443 */ if (intersectTri(triVertIdx, triCoordIdx, geomIndex, pnts, pi)) {
/* 1444 */ numint++;
/* 1445 */ if (firstpick) return true;
/* */
/* */ }
/* */
/* 1450 */ if (ccw) {
/* 1451 */ triVertIdx[0] = triVertIdx[1];
/* */
/* 1453 */ triCoordIdx[0] = triCoordIdx[1];
/* 1454 */ ccw = false;
/* */ } else {
/* 1456 */ triVertIdx[0] = triVertIdx[2];
/* */
/* 1458 */ triCoordIdx[0] = triCoordIdx[2];
/* 1459 */ ccw = true;
/* */ }
/* */ }
/* 1462 */ stripStart += stripVertexCounts[i];
/* */ }
/* */
/* 1465 */ if (numint > 0) return true;
/* 1466 */ return false;
/* */ }
/* */
/* */ boolean intersectTFA(TriangleFanArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1476 */ if (debug) System.out.println("intersect: TriangleFanArray");
/* */
/* 1478 */ int numint = 0;
/* */
/* 1480 */ int[] stripVertexCounts = new int[geom.getNumStrips()];
/* 1481 */ geom.getStripVertexCounts(stripVertexCounts);
/* 1482 */ int fanStart = 0;
/* */
/* 1484 */ int[] triVertIdx = new int[3];
/* */
/* 1487 */ for (int i = 0; i < stripVertexCounts.length; i++)
/* */ {
/* 1489 */ int start = fanStart;
/* 1490 */ triVertIdx[0] = (start++);
/* 1491 */ triVertIdx[1] = (start++);
/* */
/* 1493 */ int end = start + stripVertexCounts[i] - 2;
/* 1494 */ for (int j = start; j < end; j++) {
/* 1495 */ triVertIdx[2] = j;
/* 1496 */ if (intersectTri(triVertIdx, triVertIdx, geomIndex, pnts, pi)) {
/* 1497 */ numint++;
/* 1498 */ if (firstpick) return true;
/* */ }
/* 1500 */ triVertIdx[1] = triVertIdx[2];
/* */ }
/* 1502 */ fanStart += stripVertexCounts[i];
/* */ }
/* 1504 */ if (numint > 0) return true;
/* 1505 */ return false;
/* */ }
/* */
/* */ boolean intersectITFA(IndexedTriangleFanArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1514 */ if (debug) System.out.println("intersect: IndexedTriangleFanArray");
/* */
/* 1516 */ int numint = 0;
/* 1517 */ int[] stripVertexCounts = new int[geom.getNumStrips()];
/* 1518 */ geom.getStripIndexCounts(stripVertexCounts);
/* 1519 */ int fanStart = 0;
/* */
/* 1521 */ int[] triVertIdx = new int[3];
/* 1522 */ int[] triCoordIdx = new int[3];
/* */
/* 1524 */ for (int i = 0; i < stripVertexCounts.length; i++)
/* */ {
/* 1526 */ int start = fanStart;
/* 1527 */ triCoordIdx[0] = geom.getCoordinateIndex(start);
/* 1528 */ triVertIdx[0] = (start++);
/* 1529 */ triCoordIdx[1] = geom.getCoordinateIndex(start);
/* 1530 */ triVertIdx[1] = (start++);
/* */
/* 1532 */ int end = start + stripVertexCounts[i] - 2;
/* 1533 */ for (int j = start; j < end; j++) {
/* 1534 */ triVertIdx[2] = j;
/* 1535 */ triCoordIdx[2] = geom.getCoordinateIndex(j);
/* 1536 */ if (intersectTri(triVertIdx, triCoordIdx, geomIndex, pnts, pi)) {
/* 1537 */ numint++;
/* 1538 */ if (firstpick) return true;
/* */ }
/* 1540 */ triVertIdx[1] = triVertIdx[2];
/* 1541 */ triCoordIdx[1] = triCoordIdx[2];
/* */ }
/* 1543 */ fanStart += stripVertexCounts[i];
/* */ }
/* 1545 */ if (numint > 0) return true;
/* 1546 */ return false;
/* */ }
/* */
/* */ boolean intersectQA(QuadArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1555 */ if (debug) System.out.println("intersect: QuadArray");
/* */
/* 1557 */ int[] quadVertIdx = new int[4];
/* */
/* 1559 */ int numint = 0;
/* 1560 */ for (int i = 0; i < pnts.length; ) {
/* 1561 */ quadVertIdx[0] = (i++);
/* 1562 */ quadVertIdx[1] = (i++);
/* 1563 */ quadVertIdx[2] = (i++);
/* 1564 */ quadVertIdx[3] = (i++);
/* 1565 */ if (intersectQuad(quadVertIdx, quadVertIdx, geomIndex, pnts, pi)) {
/* 1566 */ numint++;
/* 1567 */ if (firstpick) return true;
/* */ }
/* */ }
/* */
/* 1571 */ if (numint > 0) return true;
/* 1572 */ return false;
/* */ }
/* */
/* */ final boolean intersectIQA(IndexedQuadArray geom, int geomIndex, Point3d[] pnts, boolean firstpick, PickIntersection pi)
/* */ {
/* 1582 */ if (debug) System.out.println("intersect: IndexedQuadArray");
/* */
/* 1584 */ int[] quadVertIdx = new int[4];
/* 1585 */ int[] quadCoordIdx = new int[4];
/* */
/* 1587 */ int numint = 0;
/* 1588 */ int indexCount = geom.getIndexCount();
/* */
/* 1590 */ for (int i = 0; i < indexCount; ) {
/* 1591 */ quadVertIdx[0] = i;
/* 1592 */ quadCoordIdx[0] = geom.getCoordinateIndex(i++);
/* 1593 */ quadVertIdx[1] = i;
/* 1594 */ quadCoordIdx[1] = geom.getCoordinateIndex(i++);
/* 1595 */ quadVertIdx[2] = i;
/* 1596 */ quadCoordIdx[2] = geom.getCoordinateIndex(i++);
/* 1597 */ quadVertIdx[3] = i;
/* 1598 */ quadCoordIdx[3] = geom.getCoordinateIndex(i++);
/* */
/* 1600 */ if (intersectQuad(quadVertIdx, quadCoordIdx, geomIndex, pnts, pi)) {
/* 1601 */ numint++;
/* 1602 */ if (firstpick) return true;
/* */ }
/* */ }
/* */
/* 1606 */ if (numint > 0) return true;
/* 1607 */ return false;
/* */ }
/* */
/* */ static boolean intersectBoundingBox(Point3d[] coordinates, BoundingBox box)
/* */ {
/* 1617 */ int[] out = new int[6];
/* */
/* 1619 */ Point3d lower = new Point3d();
/* 1620 */ Point3d upper = new Point3d();
/* 1621 */ box.getLower(lower);
/* 1622 */ box.getUpper(upper);
/* */
/* 1625 */ for (int i = 0; i < 6; i++) out[i] = 0;
/* 1626 */ for (i = 0; i < coordinates.length; i++) {
/* 1627 */ if ((coordinates[i].x >= lower.x) && (coordinates[i].x <= upper.x) && (coordinates[i].y >= lower.y) && (coordinates[i].y <= upper.y) && (coordinates[i].z >= lower.z) && (coordinates[i].z <= upper.z))
/* */ {
/* 1634 */ return true;
/* */ }
/* 1636 */ if (coordinates[i].x < lower.x) out[0] += 1;
/* 1637 */ if (coordinates[i].y < lower.y) out[1] += 1;
/* 1638 */ if (coordinates[i].z < lower.z) out[2] += 1;
/* 1639 */ if (coordinates[i].x > upper.x) out[3] += 1;
/* 1640 */ if (coordinates[i].y > upper.y) out[4] += 1;
/* 1641 */ if (coordinates[i].z > upper.z) out[5] += 1;
/* */
/* */ }
/* */
/* 1645 */ if ((out[0] == coordinates.length) || (out[1] == coordinates.length) || (out[2] == coordinates.length) || (out[3] == coordinates.length) || (out[4] == coordinates.length) || (out[5] == coordinates.length))
/* */ {
/* 1649 */ return false;
/* */ }
/* */
/* 1652 */ Point3d[] pCoor = new Point3d[4];
/* 1653 */ for (i = 0; i < 4; i++) pCoor[i] = new Point3d();
/* */
/* 1656 */ pCoor[0].set(lower.x, lower.y, lower.z);
/* 1657 */ pCoor[1].set(lower.x, lower.y, upper.z);
/* 1658 */ pCoor[2].set(lower.x, upper.y, upper.z);
/* 1659 */ pCoor[3].set(lower.x, upper.y, lower.z);
/* 1660 */ if (intersectPolygon(pCoor, coordinates, false) == true) return true;
/* */
/* 1663 */ pCoor[0].set(upper.x, lower.y, lower.z);
/* 1664 */ pCoor[1].set(upper.x, upper.y, lower.z);
/* 1665 */ pCoor[2].set(upper.x, upper.y, upper.z);
/* 1666 */ pCoor[3].set(upper.x, lower.y, upper.z);
/* 1667 */ if (intersectPolygon(pCoor, coordinates, false) == true) return true;
/* */
/* 1670 */ pCoor[0].set(upper.x, lower.y, upper.z);
/* 1671 */ pCoor[1].set(lower.x, lower.y, upper.z);
/* 1672 */ pCoor[2].set(lower.x, lower.y, lower.z);
/* 1673 */ pCoor[3].set(upper.x, lower.y, lower.z);
/* 1674 */ if (intersectPolygon(pCoor, coordinates, false) == true) return true;
/* */
/* 1677 */ pCoor[0].set(upper.x, upper.y, upper.z);
/* 1678 */ pCoor[1].set(upper.x, upper.y, lower.z);
/* 1679 */ pCoor[2].set(lower.x, upper.y, lower.z);
/* 1680 */ pCoor[3].set(lower.x, upper.y, upper.z);
/* 1681 */ if (intersectPolygon(pCoor, coordinates, false) == true) return true;
/* */
/* 1684 */ pCoor[0].set(upper.x, upper.y, upper.z);
/* 1685 */ pCoor[1].set(lower.x, upper.y, upper.z);
/* 1686 */ pCoor[2].set(lower.x, lower.y, upper.z);
/* 1687 */ pCoor[3].set(upper.x, lower.y, upper.z);
/* 1688 */ if (intersectPolygon(pCoor, coordinates, false) == true) return true;
/* */
/* 1691 */ pCoor[0].set(upper.x, upper.y, lower.z);
/* 1692 */ pCoor[1].set(upper.x, lower.y, lower.z);
/* 1693 */ pCoor[2].set(lower.x, lower.y, lower.z);
/* 1694 */ pCoor[3].set(lower.x, upper.y, lower.z);
/* 1695 */ if (intersectPolygon(pCoor, coordinates, false) == true) return true;
/* */
/* 1697 */ return false;
/* */ }
/* */
/* */ static boolean intersectBoundingSphere(Point3d[] coordinates, BoundingSphere sphere)
/* */ {
/* 1705 */ Vector3d tempV3D = new Vector3d();
/* */
/* 1707 */ Point3d center = new Point3d();
/* 1708 */ sphere.getCenter(center);
/* 1709 */ double radius = sphere.getRadius();
/* */
/* 1712 */ for (int i = 0; i < coordinates.length; i++) {
/* 1713 */ tempV3D.x = (coordinates[i].x - center.x);
/* 1714 */ tempV3D.y = (coordinates[i].y - center.y);
/* 1715 */ tempV3D.z = (coordinates[i].z - center.z);
/* */
/* 1717 */ if (tempV3D.length() <= radius)
/* */ {
/* 1719 */ return true;
/* */ }
/* */ }
/* */
/* 1723 */ for (i = 0; i < coordinates.length; i++)
/* */ {
/* */ boolean esFlag;
/* */ boolean esFlag;
/* 1724 */ if (i < coordinates.length - 1) {
/* 1725 */ esFlag = edgeIntersectSphere(sphere, coordinates[i], coordinates[(i + 1)]);
/* */ }
/* */ else {
/* 1728 */ esFlag = edgeIntersectSphere(sphere, coordinates[i], coordinates[0]);
/* */ }
/* */
/* 1731 */ if (esFlag == true) {
/* 1732 */ return true;
/* */ }
/* */ }
/* */
/* 1736 */ if (coordinates.length < 3) return false;
/* */
/* 1740 */ Vector3d vec0 = new Vector3d();
/* 1741 */ Vector3d vec1 = new Vector3d();
/* 1742 */ Vector3d pNrm = new Vector3d();
/* 1743 */ Vector3d pa = new Vector3d();
/* 1744 */ Point3d q = new Point3d();
/* */
/* 1748 */ for (i = 0; i < coordinates.length - 1; ) {
/* 1749 */ vec0.x = (coordinates[(i + 1)].x - coordinates[i].x);
/* 1750 */ vec0.y = (coordinates[(i + 1)].y - coordinates[i].y);
/* 1751 */ vec0.z = (coordinates[(i + 1)].z - coordinates[(i++)].z);
/* 1752 */ if (vec0.length() > 0.0D) break;
/* */ }
/* */
/* 1755 */ for (int j = i; j < coordinates.length - 1; j++) {
/* 1756 */ vec1.x = (coordinates[(j + 1)].x - coordinates[j].x);
/* 1757 */ vec1.y = (coordinates[(j + 1)].y - coordinates[j].y);
/* 1758 */ vec1.z = (coordinates[(j + 1)].z - coordinates[j].z);
/* 1759 */ if (vec1.length() > 0.0D)
/* */ break;
/* */ }
/* 1762 */ if (j == coordinates.length - 1)
/* */ {
/* 1764 */ return false;
/* */ }
/* */
/* 1774 */ pNrm.cross(vec0, vec1);
/* */
/* 1776 */ double nLenSq = pNrm.lengthSquared();
/* 1777 */ if (nLenSq == 0.0D)
/* */ {
/* 1779 */ return false;
/* */ }
/* */
/* 1782 */ pa.x = (coordinates[0].x - center.x);
/* 1783 */ pa.y = (coordinates[0].y - center.y);
/* 1784 */ pa.z = (coordinates[0].z - center.z);
/* */
/* 1786 */ double pNrmDotPa = pNrm.dot(pa);
/* */
/* 1788 */ double pqLen = Math.sqrt(pNrmDotPa * pNrmDotPa / nLenSq);
/* */
/* 1790 */ if (pqLen > radius) {
/* 1791 */ return false;
/* */ }
/* 1793 */ double tq = pNrmDotPa / nLenSq;
/* */
/* 1795 */ center.x += tq * pNrm.x;
/* 1796 */ center.y += tq * pNrm.y;
/* 1797 */ center.z += tq * pNrm.z;
/* */
/* 1800 */ return pointIntersectPolygon2D(pNrm, coordinates, q);
/* */ }
/* */
/* */ static boolean intersectBoundingPolytope(Point3d[] coordinates, BoundingPolytope polytope)
/* */ {
/* 1806 */ boolean debug = false;
/* */
/* 1809 */ double distanceSign = -1.0D;
/* */
/* 1811 */ Point4d tP4d = new Point4d();
/* */
/* 1813 */ Vector4d[] planes = new Vector4d[polytope.getNumPlanes()];
/* 1814 */ polytope.getPlanes(planes);
/* */
/* 1816 */ if (coordinates.length == 2)
/* */ {
/* 1818 */ throw new RuntimeException("TODO: must make polytope.intersect(coordinates[0], coordinates[1], tP4d) public!");
/* */ }
/* */
/* 1830 */ if (debug) {
/* 1831 */ System.out.println("The value of the input vertices are: ");
/* 1832 */ for (int i = 0; i < coordinates.length; i++) {
/* 1833 */ System.out.println("The " + i + " th vertex is: " + coordinates[i]);
/* */ }
/* */
/* 1836 */ System.out.println("The value of the input bounding Polytope's planes =");
/* 1837 */ for (int i = 0; i < planes.length; i++) {
/* 1838 */ System.out.println("The " + i + " th plane is: " + planes[i]);
/* */ }
/* */
/* */ }
/* */
/* 1844 */ double[] centers = new double[4];
/* 1845 */ centers[0] = 0.8D; centers[1] = 0.9D; centers[2] = 1.1D; centers[3] = 1.2D;
/* */
/* 1847 */ boolean intersection = true;
/* 1848 */ boolean PreTest = false;
/* */
/* 1850 */ if (PreTest)
/* */ {
/* 1852 */ for (int i = 0; i < coordinates.length; i++) {
/* 1853 */ for (int j = 0; j < planes.length; j++) {
/* 1854 */ if (planes[j].x * coordinates[i].x + planes[j].y * coordinates[i].y + planes[j].z * coordinates[i].z <= distanceSign * planes[j].w)
/* */ {
/* 1859 */ intersection = true;
/* */ }
/* */ else {
/* 1862 */ intersection = false;
/* 1863 */ break;
/* */ }
/* */ }
/* 1866 */ if (intersection)
/* */ {
/* 1868 */ return true;
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 1876 */ int numberCols = planes.length + 2 + coordinates.length + 1;
/* 1877 */ int numberRows = 1 + coordinates.length;
/* */
/* 1879 */ double[][] problemTableau = new double[numberRows][numberCols];
/* */
/* 1882 */ for (int i = 0; i < planes.length; i++) {
/* 1883 */ for (int j = 0; j < coordinates.length; j++) {
/* 1884 */ problemTableau[j][i] = (-1.0D * (planes[i].x * coordinates[j].x + planes[i].y * coordinates[j].y + planes[i].z * coordinates[j].z));
/* */ }
/* */
/* */ }
/* */
/* 1891 */ for (int i = 0; i < coordinates.length; i++) {
/* 1892 */ problemTableau[i][planes.length] = -1.0D;
/* 1893 */ problemTableau[i][(planes.length + 1)] = 1.0D;
/* */
/* 1895 */ for (int j = 0; j < coordinates.length; j++) {
/* 1896 */ if (i == j)
/* 1897 */ problemTableau[i][(j + planes.length + 2)] = 1.0D;
/* */ else {
/* 1899 */ problemTableau[i][(j + planes.length + 2)] = 0.0D;
/* */ }
/* */
/* 1903 */ problemTableau[i][(numberCols - 1)] = centers[i];
/* */ }
/* */
/* */ }
/* */
/* 1908 */ for (int j = 0; j < planes.length; j++) {
/* 1909 */ problemTableau[(numberRows - 1)][j] = (distanceSign * planes[j].w);
/* */ }
/* */
/* 1912 */ problemTableau[(numberRows - 1)][planes.length] = 1.0D;
/* 1913 */ problemTableau[(numberRows - 1)][(planes.length + 1)] = -1.0D;
/* 1914 */ for (int j = 0; j < coordinates.length; j++) {
/* 1915 */ problemTableau[(numberRows - 1)][(planes.length + 2 + j)] = 0.0D;
/* */ }
/* */
/* 1918 */ if (debug) {
/* 1919 */ System.out.println("The value of the problem tableau is: ");
/* 1920 */ for (int i = 0; i < problemTableau.length; i++) {
/* 1921 */ for (int j = 0; j < problemTableau[0].length; j++) {
/* 1922 */ System.out.print(problemTableau[i][j] + " ");
/* */ }
/* 1924 */ System.out.println();
/* */ }
/* */ }
/* */
/* 1928 */ double distance = generalStandardSimplexSolver(problemTableau, (-1.0D / 0.0D));
/* */
/* 1930 */ if (debug) {
/* 1931 */ System.out.println("The value returned by the general standard simplex = " + distance);
/* */ }
/* */
/* 1934 */ if (distance == (1.0D / 0.0D)) {
/* 1935 */ return false;
/* */ }
/* 1937 */ return true;
/* */ }
/* */
/* */ static double generalStandardSimplexSolver(double[][] problemTableau, double stopingValue)
/* */ {
/* 1947 */ boolean debug = false;
/* 1948 */ int numRow = problemTableau.length;
/* 1949 */ int numCol = problemTableau[0].length;
/* 1950 */ boolean optimal = false;
/* */
/* 1953 */ int count = 0;
/* */
/* 1956 */ if (debug) {
/* 1957 */ System.out.println("The number of rows is : " + numRow);
/* 1958 */ System.out.println("The number of columns is : " + numCol);
/* */ }
/* */
/* 1963 */ while (!optimal)
/* */ {
/* 1965 */ if (debug) {
/* 1966 */ System.out.println("input problem tableau is:");
/* 1967 */ for (int k = 0; k < numRow; k++) {
/* 1968 */ for (int j = 0; j < numCol; j++) {
/* 1969 */ System.out.println("kth, jth value is:" + k + " " + j + " : " + problemTableau[k][j]);
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 1978 */ int i = 0; double maxElement = 0.0D; for (int pivotColIndex = -1; i < numCol - 1; i++)
/* */ {
/* 1980 */ double element = problemTableau[(numRow - 1)][i];
/* 1981 */ if (element < maxElement) {
/* 1982 */ maxElement = element;
/* 1983 */ pivotColIndex = i;
/* */ }
/* */
/* */ }
/* */
/* 1989 */ if (pivotColIndex == -1)
/* */ {
/* 1992 */ optimal = true;
/* */ }
/* */
/* 1997 */ if (!optimal)
/* */ {
/* 2008 */ double prevRatio = (1.0D / 0.0D);
/* 2009 */ double ratio = 0.0D;
/* 2010 */ int pivotRowIndex = -1;
/* */
/* 2014 */ for (i = 0; i < numRow - 1; i++) {
/* 2015 */ double element = problemTableau[i][pivotColIndex];
/* 2016 */ double endElement = problemTableau[i][(numCol - 1)];
/* */
/* 2022 */ if (element == 0.0D) {
/* 2023 */ if (debug) {
/* 2024 */ System.out.println("Division by zero has occurred");
/* 2025 */ System.out.println("Within the linear program solver");
/* 2026 */ System.out.println("Ignoring the zero as a potential pivot");
/* */ }
/* 2028 */ } else if ((element < 0.0D) || (endElement < 0.0D)) {
/* 2029 */ if (debug) {
/* 2030 */ System.out.println("Ignoring cases where element is negative");
/* 2031 */ System.out.println("The value of element is: " + element);
/* 2032 */ System.out.println("The value of end Element is: " + endElement);
/* */ }
/* */ } else {
/* 2035 */ ratio = endElement / element;
/* 2036 */ if (debug) {
/* 2037 */ System.out.println("The value of element is: " + element);
/* 2038 */ System.out.println("The value of endElement is: " + endElement);
/* 2039 */ System.out.println("The value of ratio is: " + ratio);
/* 2040 */ System.out.println("The value of prevRatio is: " + prevRatio);
/* 2041 */ System.out.println("Value of ratio <= prevRatio is :" + (ratio <= prevRatio));
/* */ }
/* */
/* 2044 */ if (ratio <= prevRatio) {
/* 2045 */ if (debug) {
/* 2046 */ System.out.println("updating prevRatio with ratio");
/* */ }
/* 2048 */ prevRatio = ratio;
/* 2049 */ pivotRowIndex = i;
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 2058 */ if (pivotRowIndex == -1) {
/* 2059 */ if (debug) {
/* 2060 */ System.out.println("UNABLE TO FIND SOLUTION");
/* 2061 */ System.out.println("The system is infeasable or unbounded");
/* */ }
/* 2063 */ return (1.0D / 0.0D);
/* */ }
/* */
/* 2073 */ double pivotValue = problemTableau[pivotRowIndex][pivotColIndex];
/* */
/* 2075 */ if (debug) {
/* 2076 */ System.out.println("The value of row index is: " + pivotRowIndex);
/* 2077 */ System.out.println("The value of col index is: " + pivotColIndex);
/* 2078 */ System.out.println("The value of pivotValue is: " + pivotValue);
/* */ }
/* */
/* 2081 */ for (i = 0; i < numCol; i++) {
/* 2082 */ problemTableau[pivotRowIndex][i] /= pivotValue;
/* */ }
/* */
/* 2088 */ for (i = 0; i < numRow; i++) {
/* 2089 */ if (i != pivotRowIndex) {
/* 2090 */ double multiplier = problemTableau[i][pivotColIndex];
/* 2091 */ for (int j = 0; j < numCol; j++) {
/* 2092 */ problemTableau[i][j] -= multiplier * problemTableau[pivotRowIndex][j];
/* */ }
/* */ }
/* */ }
/* */ }
/* */
/* */ }
/* */
/* 2100 */ return problemTableau[(numRow - 1)][(numCol - 1)];
/* */ }
/* */
/* */ static boolean edgeIntersectSphere(BoundingSphere sphere, Point3d start, Point3d end)
/* */ {
/* 2107 */ Vector3d ab = new Vector3d();
/* 2108 */ Vector3d ap = new Vector3d();
/* */
/* 2110 */ Point3d center = new Point3d();
/* 2111 */ sphere.getCenter(center);
/* 2112 */ double radius = sphere.getRadius();
/* */
/* 2114 */ ab.x = (end.x - start.x);
/* 2115 */ ab.y = (end.y - start.y);
/* 2116 */ ab.z = (end.z - start.z);
/* */
/* 2118 */ ap.x = (center.x - start.x);
/* 2119 */ ap.y = (center.y - start.y);
/* 2120 */ ap.z = (center.z - start.z);
/* */
/* 2122 */ double abDotAp = ab.dot(ap);
/* */
/* 2124 */ if (abDotAp < 0.0D) {
/* 2125 */ return false;
/* */ }
/* 2127 */ double abLenSq = ab.lengthSquared();
/* 2128 */ double acLenSq = abDotAp * abDotAp / abLenSq;
/* */
/* 2130 */ if (acLenSq < abLenSq) {
/* 2131 */ return false;
/* */ }
/* 2133 */ double radiusSq = radius * radius;
/* 2134 */ double apLenSq = ap.lengthSquared();
/* */
/* 2136 */ if (apLenSq - acLenSq <= radiusSq) {
/* 2137 */ return true;
/* */ }
/* 2139 */ return false;
/* */ }
/* */
/* */ static double det2D(Point2d a, Point2d b, Point2d p)
/* */ {
/* 2144 */ return (p.x - a.x) * (a.y - b.y) + (a.y - p.y) * (a.x - b.x);
/* */ }
/* */
/* */ static boolean pointIntersectPolygon2D(Vector3d normal, Point3d[] coord, Point3d point)
/* */ {
/* 2153 */ Point2d[] coord2D = new Point2d[coord.length];
/* 2154 */ Point2d pnt = new Point2d();
/* */
/* 2163 */ double absNrmX = Math.abs(normal.x);
/* 2164 */ double absNrmY = Math.abs(normal.y);
/* 2165 */ double absNrmZ = Math.abs(normal.z);
/* */ int axis;
/* */ int axis;
/* 2167 */ if (absNrmX > absNrmY)
/* 2168 */ axis = 0;
/* */ else {
/* 2170 */ axis = 1;
/* */ }
/* 2172 */ if (axis == 0) {
/* 2173 */ if (absNrmX < absNrmZ)
/* 2174 */ axis = 2;
/* */ }
/* 2176 */ else if ((axis == 1) &&
/* 2177 */ (absNrmY < absNrmZ)) {
/* 2178 */ axis = 2;
/* */ }
/* */
/* 2183 */ for (int i = 0; i < coord.length; i++) {
/* 2184 */ coord2D[i] = new Point2d();
/* */
/* 2186 */ switch (axis) {
/* */ case 0:
/* 2188 */ coord2D[i].x = coord[i].y;
/* 2189 */ coord2D[i].y = coord[i].z;
/* 2190 */ break;
/* */ case 1:
/* 2193 */ coord2D[i].x = coord[i].x;
/* 2194 */ coord2D[i].y = coord[i].z;
/* 2195 */ break;
/* */ case 2:
/* 2198 */ coord2D[i].x = coord[i].x;
/* 2199 */ coord2D[i].y = coord[i].y;
/* */ }
/* */
/* */ }
/* */
/* 2205 */ switch (axis) {
/* */ case 0:
/* 2207 */ pnt.x = point.y;
/* 2208 */ pnt.y = point.z;
/* 2209 */ break;
/* */ case 1:
/* 2212 */ pnt.x = point.x;
/* 2213 */ pnt.y = point.z;
/* 2214 */ break;
/* */ case 2:
/* 2217 */ pnt.x = point.x;
/* 2218 */ pnt.y = point.y;
/* */ }
/* */
/* 2223 */ for (int j = 0; j < coord.length; j++)
/* 2224 */ if (j < coord.length - 1) {
/* 2225 */ if (det2D(coord2D[j], coord2D[(j + 1)], pnt) <= 0.0D)
/* */ {
/* 2228 */ return false;
/* */ }
/* 2230 */ } else if (det2D(coord2D[j], coord2D[0], pnt) <= 0.0D)
/* */ {
/* 2233 */ return false;
/* */ }
/* 2235 */ return true;
/* */ }
/* */
/* */ static boolean edgeIntersectPlane(Vector3d normal, Point3d pnt, Point3d start, Point3d end, Point3d iPnt)
/* */ {
/* 2242 */ Vector3d tempV3d = new Vector3d();
/* 2243 */ Vector3d direction = new Vector3d();
/* */
/* 2247 */ tempV3d.set(pnt);
/* 2248 */ double pD = normal.dot(tempV3d);
/* */
/* 2250 */ direction.x = (end.x - start.x);
/* 2251 */ direction.y = (end.y - start.y);
/* 2252 */ direction.z = (end.z - start.z);
/* */
/* 2254 */ double pNrmDotrDir = normal.dot(direction);
/* */
/* 2257 */ if (pNrmDotrDir == 0.0D)
/* */ {
/* 2259 */ return false;
/* */ }
/* */
/* 2262 */ tempV3d.set(start);
/* */
/* 2264 */ double tr = (pD - normal.dot(tempV3d)) / pNrmDotrDir;
/* */
/* 2268 */ if ((tr < 0.0D) || (tr > 1.0D))
/* */ {
/* 2270 */ return false;
/* */ }
/* */
/* 2273 */ start.x += tr * direction.x;
/* 2274 */ start.y += tr * direction.y;
/* 2275 */ start.z += tr * direction.z;
/* */
/* 2277 */ return true;
/* */ }
/* */
/* */ static boolean edgeIntersectPolygon2D(Vector3d normal, Point3d[] coord, Point3d[] seg)
/* */ {
/* 2285 */ Point2d[] coord2D = new Point2d[coord.length];
/* 2286 */ Point2d[] seg2D = new Point2d[2];
/* */
/* 2295 */ double absNrmX = Math.abs(normal.x);
/* 2296 */ double absNrmY = Math.abs(normal.y);
/* 2297 */ double absNrmZ = Math.abs(normal.z);
/* */ int axis;
/* */ int axis;
/* 2299 */ if (absNrmX > absNrmY)
/* 2300 */ axis = 0;
/* */ else {
/* 2302 */ axis = 1;
/* */ }
/* 2304 */ if (axis == 0) {
/* 2305 */ if (absNrmX < absNrmZ)
/* 2306 */ axis = 2;
/* */ }
/* 2308 */ else if ((axis == 1) &&
/* 2309 */ (absNrmY < absNrmZ)) {
/* 2310 */ axis = 2;
/* */ }
/* */
/* 2315 */ for (int i = 0; i < coord.length; i++) {
/* 2316 */ coord2D[i] = new Point2d();
/* */
/* 2318 */ switch (axis) {
/* */ case 0:
/* 2320 */ coord2D[i].x = coord[i].y;
/* 2321 */ coord2D[i].y = coord[i].z;
/* 2322 */ break;
/* */ case 1:
/* 2325 */ coord2D[i].x = coord[i].x;
/* 2326 */ coord2D[i].y = coord[i].z;
/* 2327 */ break;
/* */ case 2:
/* 2330 */ coord2D[i].x = coord[i].x;
/* 2331 */ coord2D[i].y = coord[i].y;
/* */ }
/* */
/* */ }
/* */
/* 2337 */ for (i = 0; i < 2; i++) {
/* 2338 */ seg2D[i] = new Point2d();
/* 2339 */ switch (axis) {
/* */ case 0:
/* 2341 */ seg2D[i].x = seg[i].y;
/* 2342 */ seg2D[i].y = seg[i].z;
/* 2343 */ break;
/* */ case 1:
/* 2346 */ seg2D[i].x = seg[i].x;
/* 2347 */ seg2D[i].y = seg[i].z;
/* 2348 */ break;
/* */ case 2:
/* 2351 */ seg2D[i].x = seg[i].x;
/* 2352 */ seg2D[i].y = seg[i].y;
/* */ }
/* */
/* */ }
/* */
/* 2359 */ boolean[][] pntTest = new boolean[2][coord.length];
/* */
/* 2362 */ for (int j = 0; j < coord.length; j++) {
/* 2363 */ for (i = 0; i < 2; i++) {
/* 2364 */ if (j < coord.length - 1)
/* 2365 */ pntTest[i][j] = (det2D(coord2D[j], coord2D[(j + 1)], seg2D[i]) < 0.0D ? 1 : 0);
/* */ else {
/* 2367 */ pntTest[i][j] = (det2D(coord2D[j], coord2D[0], seg2D[i]) < 0.0D ? 1 : 0);
/* */ }
/* */ }
/* 2370 */ if ((pntTest[0][j] == 0) && (pntTest[1][j] == 0)) {
/* 2371 */ return false;
/* */ }
/* */ }
/* 2374 */ boolean testFlag = true;
/* 2375 */ for (i = 0; i < coord.length; i++) {
/* 2376 */ if (pntTest[0][i] == 0) {
/* 2377 */ testFlag = false;
/* 2378 */ break;
/* */ }
/* */ }
/* */
/* 2382 */ if (testFlag == true) {
/* 2383 */ return true;
/* */ }
/* 2385 */ testFlag = true;
/* 2386 */ for (i = 0; i < coord.length; i++) {
/* 2387 */ if (pntTest[1][i] == 0) {
/* 2388 */ testFlag = false;
/* 2389 */ break;
/* */ }
/* */ }
/* */
/* 2393 */ if (testFlag == true) {
/* 2394 */ return true;
/* */ }
/* */
/* 2397 */ int cnt = 0;
/* 2398 */ for (i = 0; i < coord.length; i++) {
/* 2399 */ if (det2D(seg2D[0], seg2D[1], coord2D[i]) < 0.0D) {
/* 2400 */ cnt++;
/* */ }
/* */ }
/* 2403 */ if ((cnt == 0) || (cnt == coord.length)) {
/* 2404 */ return false;
/* */ }
/* 2406 */ return true;
/* */ }
/* */
/* */ static boolean intersectPolygon(Point3d[] coord1, Point3d[] coord2, boolean doTrivialTest)
/* */ {
/* 2412 */ Vector3d vec0 = new Vector3d();
/* 2413 */ Vector3d vec1 = new Vector3d();
/* 2414 */ Vector3d pNrm = new Vector3d();
/* */
/* 2418 */ for (int i = 0; i < coord1.length - 1; ) {
/* 2419 */ vec0.x = (coord1[(i + 1)].x - coord1[i].x);
/* 2420 */ vec0.y = (coord1[(i + 1)].y - coord1[i].y);
/* 2421 */ vec0.z = (coord1[(i + 1)].z - coord1[(i++)].z);
/* 2422 */ if (vec0.length() > 0.0D) {
/* 2423 */ break;
/* */ }
/* */ }
/* 2426 */ for (int j = i; j < coord1.length - 1; j++) {
/* 2427 */ vec1.x = (coord1[(j + 1)].x - coord1[j].x);
/* 2428 */ vec1.y = (coord1[(j + 1)].y - coord1[j].y);
/* 2429 */ vec1.z = (coord1[(j + 1)].z - coord1[j].z);
/* 2430 */ if (vec1.length() > 0.0D) {
/* */ break;
/* */ }
/* */ }
/* 2434 */ if (j == coord1.length - 1)
/* */ {
/* 2436 */ return false;
/* */ }
/* */
/* 2446 */ pNrm.cross(vec0, vec1);
/* */
/* 2448 */ if (pNrm.length() == 0.0D)
/* */ {
/* 2450 */ return false;
/* */ }
/* */
/* 2454 */ if (doTrivialTest == true);
/* 2458 */ j = 0;
/* 2459 */ Point3d[] seg = new Point3d[2];
/* 2460 */ seg[0] = new Point3d();
/* 2461 */ seg[1] = new Point3d();
/* */
/* 2463 */ for (i = 0; i < coord2.length; i++)
/* */ {
/* */ boolean epFlag;
/* */ boolean epFlag;
/* 2464 */ if (i < coord2.length - 1) {
/* 2465 */ epFlag = edgeIntersectPlane(pNrm, coord1[0], coord2[i], coord2[(i + 1)], seg[j]);
/* */ }
/* */ else {
/* 2468 */ epFlag = edgeIntersectPlane(pNrm, coord1[0], coord2[i], coord2[0], seg[j]);
/* */ }
/* 2470 */ if (epFlag == true) {
/* 2471 */ j++;
/* 2472 */ if (j > 1) {
/* */ break;
/* */ }
/* */ }
/* */ }
/* 2477 */ if (j == 0) {
/* 2478 */ return false;
/* */ }
/* 2480 */ if (coord2.length < 3) {
/* 2481 */ return pointIntersectPolygon2D(pNrm, coord1, seg[0]);
/* */ }
/* 2483 */ return edgeIntersectPolygon2D(pNrm, coord1, seg);
/* */ }
/* */
/* */ static final boolean isNonZero(double v)
/* */ {
/* 2488 */ return (v > 1.0E-013D) || (v < -1.0E-013D);
/* */ }
/* */
/* */ static boolean intersectRay(Point3d[] coordinates, PickRay ray, PickIntersection pi)
/* */ {
/* 2495 */ Point3d origin = getPoint3d();
/* 2496 */ Vector3d direction = getVector3d();
/* */
/* 2498 */ ray.get(origin, direction);
/* 2499 */ boolean result = intersectRayOrSegment(coordinates, direction, origin, pi, false);
/* 2500 */ freeVector3d(direction);
/* 2501 */ freePoint3d(origin);
/* 2502 */ return result;
/* */ }
/* */
/* */ static boolean intersectRayOrSegment(Point3d[] coordinates, Vector3d direction, Point3d origin, PickIntersection pi, boolean isSegment)
/* */ {
/* 2515 */ Vector3d vec0 = getVector3d();
/* 2516 */ Vector3d vec1 = getVector3d();
/* 2517 */ Vector3d pNrm = getVector3d();
/* */
/* 2519 */ double pD = 0.0D;
/* 2520 */ double pNrmDotrDir = 0.0D;
/* */
/* 2522 */ boolean isIntersect = false;
/* 2523 */ int k = 0; int l = 0;
/* */
/* 2526 */ for (int i = 0; i < coordinates.length; i++) {
/* 2527 */ if (i != coordinates.length - 1)
/* 2528 */ l = i + 1;
/* */ else {
/* 2530 */ l = 0;
/* */ }
/* 2532 */ vec0.x = (coordinates[l].x - coordinates[i].x);
/* 2533 */ vec0.y = (coordinates[l].y - coordinates[i].y);
/* 2534 */ vec0.z = (coordinates[l].z - coordinates[i].z);
/* 2535 */ if (vec0.length() > 0.0D)
/* */ {
/* */ break;
/* */ }
/* */ }
/* */
/* 2541 */ for (int j = l; j < coordinates.length; j++) {
/* 2542 */ if (j != coordinates.length - 1)
/* 2543 */ k = j + 1;
/* */ else {
/* 2545 */ k = 0;
/* */ }
/* 2547 */ vec1.x = (coordinates[k].x - coordinates[j].x);
/* 2548 */ vec1.y = (coordinates[k].y - coordinates[j].y);
/* 2549 */ vec1.z = (coordinates[k].z - coordinates[j].z);
/* 2550 */ if (vec1.length() > 0.0D)
/* */ {
/* */ break;
/* */ }
/* */ }
/* 2555 */ pNrm.cross(vec0, vec1);
/* */
/* 2557 */ if ((vec1.length() == 0.0D) || (pNrm.length() == 0.0D))
/* */ {
/* 2560 */ k = l == 0 ? coordinates.length - 1 : l - 1;
/* 2561 */ isIntersect = intersectLineAndRay(coordinates[l], coordinates[k], origin, direction, pi);
/* */
/* 2568 */ freeVector3d(vec0);
/* 2569 */ freeVector3d(vec1);
/* 2570 */ freeVector3d(pNrm);
/* 2571 */ return isIntersect;
/* */ }
/* */
/* 2577 */ pNrmDotrDir = pNrm.dot(direction);
/* */
/* 2580 */ if (pNrmDotrDir == 0.0D)
/* */ {
/* 2583 */ for (i = 0; i < coordinates.length; i++) {
/* 2584 */ if (i != coordinates.length - 1)
/* 2585 */ k = i + 1;
/* */ else {
/* 2587 */ k = 0;
/* */ }
/* 2589 */ if (intersectLineAndRay(coordinates[i], coordinates[k], origin, direction, pi))
/* */ {
/* 2594 */ isIntersect = true;
/* 2595 */ break;
/* */ }
/* */ }
/* 2598 */ freeVector3d(vec0);
/* 2599 */ freeVector3d(vec1);
/* 2600 */ freeVector3d(pNrm);
/* 2601 */ return isIntersect;
/* */ }
/* */
/* 2605 */ Vector3d tempV3d = getVector3d();
/* 2606 */ tempV3d.set(coordinates[0]);
/* 2607 */ pD = pNrm.dot(tempV3d);
/* 2608 */ tempV3d.set(origin);
/* */
/* 2614 */ double dist = (pD - pNrm.dot(tempV3d)) / pNrmDotrDir;
/* */
/* 2617 */ if ((dist < -1.0E-013D) || ((isSegment) && (dist > 1.0000000000001D)))
/* */ {
/* 2621 */ freeVector3d(vec0);
/* 2622 */ freeVector3d(vec1);
/* 2623 */ freeVector3d(pNrm);
/* 2624 */ freeVector3d(tempV3d);
/* 2625 */ return false;
/* */ }
/* */
/* 2630 */ Point3d iPnt = getPoint3d();
/* 2631 */ origin.x += direction.x * dist;
/* 2632 */ origin.y += direction.y * dist;
/* 2633 */ origin.z += direction.z * dist;
/* */
/* 2637 */ double absNrmX = Math.abs(pNrm.x);
/* 2638 */ double absNrmY = Math.abs(pNrm.y);
/* 2639 */ double absNrmZ = Math.abs(pNrm.z);
/* */
/* 2646 */ double lastSign = 0.0D;
/* 2647 */ Point3d p0 = coordinates[(coordinates.length - 1)];
/* 2648 */ Point3d p1 = coordinates[0];
/* */
/* 2650 */ isIntersect = true;
/* */
/* 2652 */ if (absNrmX > absNrmY) {
/* 2653 */ if (absNrmX < absNrmZ) {
/* 2654 */ for (i = 0; i < coordinates.length; i++) {
/* 2655 */ p0 = coordinates[i];
/* 2656 */ p1 = i != coordinates.length - 1 ? coordinates[(i + 1)] : coordinates[0];
/* 2657 */ double sign = (iPnt.y - p0.y) * (p1.x - p0.x) - (iPnt.x - p0.x) * (p1.y - p0.y);
/* */
/* 2659 */ if (isNonZero(sign)) {
/* 2660 */ if (sign * lastSign < 0.0D) {
/* 2661 */ isIntersect = false;
/* 2662 */ break;
/* */ }
/* 2664 */ lastSign = sign;
/* */ } else {
/* 2666 */ double t = p1.y - p0.y;
/* 2667 */ if (isNonZero(t)) {
/* 2668 */ t = (iPnt.y - p0.y) / t;
/* 2669 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2670 */ break;
/* */ }
/* 2672 */ t = p1.x - p0.x;
/* 2673 */ if (isNonZero(t)) {
/* 2674 */ t = (iPnt.x - p0.x) / t;
/* 2675 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2676 */ break;
/* */ }
/* 2678 */ lastSign = 0.0D;
/* */ }
/* */ }
/* */
/* */ }
/* */
/* 2684 */ for (i = 0; i < coordinates.length; i++) {
/* 2685 */ p0 = coordinates[i];
/* 2686 */ p1 = i != coordinates.length - 1 ? coordinates[(i + 1)] : coordinates[0];
/* 2687 */ double sign = (iPnt.y - p0.y) * (p1.z - p0.z) - (iPnt.z - p0.z) * (p1.y - p0.y);
/* */
/* 2689 */ if (isNonZero(sign)) {
/* 2690 */ if (sign * lastSign < 0.0D) {
/* 2691 */ isIntersect = false;
/* 2692 */ break;
/* */ }
/* 2694 */ lastSign = sign;
/* */ } else {
/* 2696 */ double t = p1.y - p0.y;
/* */
/* 2698 */ if (isNonZero(t)) {
/* 2699 */ t = (iPnt.y - p0.y) / t;
/* 2700 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2701 */ break;
/* */ }
/* */
/* 2704 */ t = p1.z - p0.z;
/* 2705 */ if (isNonZero(t)) {
/* 2706 */ t = (iPnt.z - p0.z) / t;
/* 2707 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2708 */ break;
/* */ }
/* 2710 */ lastSign = 0.0D;
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 2717 */ if (absNrmY < absNrmZ) {
/* 2718 */ for (i = 0; i < coordinates.length; i++) {
/* 2719 */ p0 = coordinates[i];
/* 2720 */ p1 = i != coordinates.length - 1 ? coordinates[(i + 1)] : coordinates[0];
/* 2721 */ double sign = (iPnt.y - p0.y) * (p1.x - p0.x) - (iPnt.x - p0.x) * (p1.y - p0.y);
/* */
/* 2723 */ if (isNonZero(sign)) {
/* 2724 */ if (sign * lastSign < 0.0D) {
/* 2725 */ isIntersect = false;
/* 2726 */ break;
/* */ }
/* 2728 */ lastSign = sign;
/* */ } else {
/* 2730 */ double t = p1.y - p0.y;
/* 2731 */ if (isNonZero(t)) {
/* 2732 */ t = (iPnt.y - p0.y) / t;
/* 2733 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2734 */ break;
/* */ }
/* 2736 */ t = p1.x - p0.x;
/* 2737 */ if (isNonZero(t)) {
/* 2738 */ t = (iPnt.x - p0.x) / t;
/* 2739 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2740 */ break;
/* */ }
/* 2742 */ lastSign = 0.0D;
/* */ }
/* */ }
/* */
/* */ }
/* */
/* 2748 */ for (i = 0; i < coordinates.length; i++) {
/* 2749 */ p0 = coordinates[i];
/* 2750 */ p1 = i != coordinates.length - 1 ? coordinates[(i + 1)] : coordinates[0];
/* 2751 */ double sign = (iPnt.x - p0.x) * (p1.z - p0.z) - (iPnt.z - p0.z) * (p1.x - p0.x);
/* */
/* 2753 */ if (isNonZero(sign)) {
/* 2754 */ if (sign * lastSign < 0.0D) {
/* 2755 */ isIntersect = false;
/* 2756 */ break;
/* */ }
/* 2758 */ lastSign = sign;
/* */ } else {
/* 2760 */ double t = p1.x - p0.x;
/* 2761 */ if (isNonZero(t)) {
/* 2762 */ t = (iPnt.x - p0.x) / t;
/* 2763 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2764 */ break;
/* */ }
/* 2766 */ t = p1.z - p0.z;
/* 2767 */ if (isNonZero(t)) {
/* 2768 */ t = (iPnt.z - p0.z) / t;
/* 2769 */ isIntersect = (t > -1.0E-013D) && (t < 1.0000000000001D);
/* 2770 */ break;
/* */ }
/* 2772 */ lastSign = 0.0D;
/* */ }
/* */
/* */ }
/* */
/* 2780 */ if (isIntersect) {
/* 2781 */ pi.setDistance(dist * direction.length());
/* 2782 */ pi.setPointCoordinatesVW(iPnt);
/* */ }
/* 2784 */ freeVector3d(vec0);
/* 2785 */ freeVector3d(vec1);
/* 2786 */ freeVector3d(pNrm);
/* 2787 */ freeVector3d(tempV3d);
/* 2788 */ freePoint3d(iPnt);
/* 2789 */ return isIntersect;
/* */ }
/* */
/* */ static boolean intersectSegment(Point3d[] coordinates, PickSegment segment, PickIntersection pi)
/* */ {
/* 2799 */ Point3d start = getPoint3d();
/* 2800 */ Point3d end = getPoint3d();
/* 2801 */ Vector3d direction = getVector3d();
/* */
/* 2803 */ segment.get(start, end);
/* 2804 */ direction.x = (end.x - start.x);
/* 2805 */ direction.y = (end.y - start.y);
/* 2806 */ direction.z = (end.z - start.z);
/* 2807 */ boolean result = intersectRayOrSegment(coordinates, direction, start, pi, true);
/* 2808 */ freeVector3d(direction);
/* 2809 */ freePoint3d(start);
/* 2810 */ freePoint3d(end);
/* 2811 */ return result;
/* */ }
/* */
/* */ static boolean inside(Point3d[] coordinates, PickPoint point, int ccw)
/* */ {
/* 2822 */ Vector3d vec0 = new Vector3d();
/* 2823 */ Vector3d vec1 = new Vector3d();
/* 2824 */ Vector3d pNrm = new Vector3d();
/* 2825 */ double pD = 0.0D;
/* 2826 */ Vector3d tempV3d = new Vector3d();
/* 2827 */ double pNrmDotrDir = 0.0D;
/* */
/* 2833 */ Point3d location = new Point3d();
/* 2834 */ point.get(location);
/* */
/* 2837 */ for (int i = 0; i < coordinates.length - 1; ) {
/* 2838 */ vec0.x = (coordinates[(i + 1)].x - coordinates[i].x);
/* 2839 */ vec0.y = (coordinates[(i + 1)].y - coordinates[i].y);
/* 2840 */ vec0.z = (coordinates[(i + 1)].z - coordinates[(i++)].z);
/* 2841 */ if (vec0.length() > 0.0D) {
/* 2842 */ break;
/* */ }
/* */ }
/* 2845 */ for (int j = i; j < coordinates.length - 1; j++) {
/* 2846 */ vec1.x = (coordinates[(j + 1)].x - coordinates[j].x);
/* 2847 */ vec1.y = (coordinates[(j + 1)].y - coordinates[j].y);
/* 2848 */ vec1.z = (coordinates[(j + 1)].z - coordinates[j].z);
/* 2849 */ if (vec1.length() > 0.0D) {
/* */ break;
/* */ }
/* */ }
/* 2853 */ if (j == coordinates.length - 1)
/* */ {
/* 2855 */ return false;
/* */ }
/* */
/* 2865 */ if (ccw == 1)
/* 2866 */ pNrm.cross(vec0, vec1);
/* */ else {
/* 2868 */ pNrm.cross(vec1, vec0);
/* */ }
/* 2870 */ if (pNrm.length() == 0.0D)
/* */ {
/* 2872 */ return false;
/* */ }
/* */
/* 2875 */ tempV3d.set(coordinates[0]);
/* 2876 */ pD = pNrm.dot(tempV3d);
/* */
/* 2878 */ tempV3d.set(location);
/* */
/* 2880 */ if (pD - pNrm.dot(tempV3d) > 0.0D)
/* */ {
/* 2882 */ return false;
/* */ }
/* */
/* 2885 */ return true;
/* */ }
/* */
/* */ static boolean intersectPntAndPnt(Point3d pnt1, Point3d pnt2, PickIntersection pi)
/* */ {
/* 2891 */ if ((pnt1.x == pnt2.x) && (pnt1.y == pnt2.y) && (pnt1.z == pnt2.z)) {
/* 2892 */ pi.setPointCoordinatesVW(pnt1);
/* 2893 */ pi.setDistance(0.0D);
/* 2894 */ return true;
/* */ }
/* */
/* 2897 */ return false;
/* */ }
/* */
/* */ static boolean intersectPntAndRay(Point3d pnt, Point3d ori, Vector3d dir, PickIntersection pi)
/* */ {
/* 2902 */ int flag = 0;
/* */ double dist;
/* 2906 */ if (dir.x != 0.0D) {
/* 2907 */ flag = 0;
/* 2908 */ dist = (pnt.x - ori.x) / dir.x;
/* */ }
/* */ else
/* */ {
/* */ double dist;
/* 2910 */ if (dir.y != 0.0D) {
/* 2911 */ if (pnt.x != ori.x)
/* 2912 */ return false;
/* 2913 */ flag = 1;
/* 2914 */ dist = (pnt.y - ori.y) / dir.y;
/* */ }
/* */ else
/* */ {
/* */ double dist;
/* 2916 */ if (dir.z != 0.0D) {
/* 2917 */ if ((pnt.x != ori.x) || (pnt.y != ori.y))
/* 2918 */ return false;
/* 2919 */ flag = 2;
/* 2920 */ dist = (pnt.z - ori.z) / dir.z;
/* */ }
/* */ else
/* */ {
/* 2924 */ return false;
/* */ }
/* */ }
/* */ }
/* */ double dist;
/* 2926 */ if (dist < 0.0D) {
/* 2927 */ return false;
/* */ }
/* 2929 */ if (flag == 0) {
/* 2930 */ double temp = ori.y + dist * dir.y;
/* 2931 */ if ((pnt.y < temp - 4.9E-324D) || (pnt.y > temp + 4.9E-324D)) {
/* 2932 */ return false;
/* */ }
/* */ }
/* 2935 */ if (flag < 2) {
/* 2936 */ double temp = ori.z + dist * dir.z;
/* 2937 */ if ((pnt.z < temp - 4.9E-324D) || (pnt.z > temp + 4.9E-324D)) {
/* 2938 */ return false;
/* */ }
/* */ }
/* 2941 */ pi.setPointCoordinatesVW(pnt);
/* 2942 */ pi.setDistance(dist);
/* */
/* 2944 */ return true;
/* */ }
/* */
/* */ static boolean intersectLineAndRay(Point3d start, Point3d end, Point3d ori, Vector3d dir, PickIntersection pi)
/* */ {
/* 2962 */ Vector3d lDir = new Vector3d(end.x - start.x, end.y - start.y, end.z - start.z);
/* */
/* 2965 */ double m00 = lDir.x;
/* 2966 */ double m01 = -dir.x;
/* 2967 */ double m10 = lDir.y;
/* 2968 */ double m11 = -dir.y;
/* */
/* 2971 */ double dmt = m00 * m11 - m10 * m01;
/* */
/* 2973 */ if (dmt == 0.0D)
/* */ {
/* 2975 */ boolean isIntersect = false;
/* 2976 */ if ((lDir.x == 0.0D) && (lDir.y == 0.0D) && (lDir.z == 0.0D)) {
/* 2977 */ isIntersect = intersectPntAndRay(start, ori, dir, pi);
/* 2978 */ if (isIntersect) {
/* 2979 */ pi.setPointCoordinatesVW(start);
/* 2980 */ pi.setDistance(0.0D);
/* */ }
/* */ }
/* 2983 */ freeVector3d(lDir);
/* 2984 */ return isIntersect;
/* */ }
/* */
/* 2987 */ double tmp1 = 1.0D / dmt;
/* */
/* 2989 */ double mInv00 = tmp1 * m11;
/* 2990 */ double mInv01 = tmp1 * -m01;
/* 2991 */ double mInv10 = tmp1 * -m10;
/* 2992 */ double mInv11 = tmp1 * m00;
/* */
/* 2994 */ tmp1 = ori.x - start.x;
/* 2995 */ double tmp2 = ori.y - start.y;
/* */
/* 2997 */ double t = mInv00 * tmp1 + mInv01 * tmp2;
/* 2998 */ double s = mInv10 * tmp1 + mInv11 * tmp2;
/* */
/* 3000 */ if (s < 0.0D)
/* */ {
/* 3002 */ return false;
/* */ }
/* 3004 */ if ((t < 0.0D) || (t > 1.0D))
/* */ {
/* 3006 */ return false;
/* */ }
/* */
/* 3009 */ tmp1 = ori.z + s * dir.z;
/* 3010 */ tmp2 = start.z + t * lDir.z;
/* */
/* 3012 */ if ((tmp1 < tmp2 - 4.9E-324D) || (tmp1 > tmp2 + 4.9E-324D))
/* */ {
/* 3015 */ return false;
/* */ }
/* 3017 */ double dist = s;
/* */
/* 3019 */ pi.setDistance(dist);
/* 3020 */ Point3d iPnt = new Point3d();
/* 3021 */ iPnt.scaleAdd(s, dir, ori);
/* 3022 */ pi.setPointCoordinatesVW(iPnt);
/* */
/* 3025 */ return true;
/* */ }
/* */
/* */ static boolean intersectCylinder(Point3d[] coordinates, PickCylinder cyl, PickIntersection pi)
/* */ {
/* 3035 */ Point3d origin = getPoint3d();
/* 3036 */ Point3d end = getPoint3d();
/* 3037 */ Vector3d direction = getVector3d();
/* 3038 */ Point3d iPnt1 = getPoint3d();
/* 3039 */ Point3d iPnt2 = getPoint3d();
/* 3040 */ Vector3d originToIpnt = getVector3d();
/* */
/* 3043 */ cyl.getOrigin(origin);
/* 3044 */ cyl.getDirection(direction);
/* 3045 */ double radius = cyl.getRadius();
/* */
/* 3047 */ if ((cyl instanceof PickCylinderSegment)) {
/* 3048 */ ((PickCylinderSegment)cyl).getEnd(end);
/* */ }
/* */
/* 3053 */ if (coordinates.length > 2) {
/* 3054 */ if ((cyl instanceof PickCylinderRay)) {
/* 3055 */ if (intersectRay(coordinates, new PickRay(origin, direction), pi)) {
/* 3056 */ freePoint3d(origin);
/* 3057 */ freePoint3d(end);
/* 3058 */ freeVector3d(direction);
/* 3059 */ freePoint3d(iPnt1);
/* 3060 */ freePoint3d(iPnt2);
/* 3061 */ freeVector3d(originToIpnt);
/* */
/* 3063 */ return true;
/* */ }
/* */
/* */ }
/* 3067 */ else if (intersectSegment(coordinates, new PickSegment(origin, end), pi)) {
/* 3068 */ freePoint3d(origin);
/* 3069 */ freePoint3d(end);
/* 3070 */ freeVector3d(direction);
/* 3071 */ freePoint3d(iPnt1);
/* 3072 */ freePoint3d(iPnt2);
/* 3073 */ freeVector3d(originToIpnt);
/* */
/* 3075 */ return true;
/* */ }
/* */
/* */ }
/* */
/* 3082 */ for (int i = 0; i < coordinates.length - 1; i++)
/* */ {
/* */ double sqDistToEdge;
/* */ double sqDistToEdge;
/* 3083 */ if ((cyl instanceof PickCylinderSegment)) {
/* 3084 */ sqDistToEdge = Distance.segmentToSegment(origin, end, coordinates[i], coordinates[(i + 1)], iPnt1, iPnt2, null);
/* */ }
/* */ else
/* */ {
/* 3090 */ sqDistToEdge = Distance.rayToSegment(origin, direction, coordinates[i], coordinates[(i + 1)], iPnt1, iPnt2, null);
/* */ }
/* */
/* 3095 */ if (sqDistToEdge <= radius * radius) {
/* 3096 */ pi.setPointCoordinatesVW(iPnt2);
/* 3097 */ originToIpnt.sub(iPnt1, origin);
/* 3098 */ pi.setDistance(originToIpnt.length());
/* */
/* 3100 */ freePoint3d(origin);
/* 3101 */ freePoint3d(end);
/* 3102 */ freeVector3d(direction);
/* 3103 */ freePoint3d(iPnt1);
/* 3104 */ freePoint3d(iPnt2);
/* 3105 */ freeVector3d(originToIpnt);
/* */
/* 3107 */ return true;
/* */ }
/* */ }
/* */
/* 3111 */ freePoint3d(origin);
/* 3112 */ freePoint3d(end);
/* 3113 */ freeVector3d(direction);
/* 3114 */ freePoint3d(iPnt1);
/* 3115 */ freePoint3d(iPnt2);
/* 3116 */ freeVector3d(originToIpnt);
/* */
/* 3118 */ return false;
/* */ }
/* */
/* */ static boolean intersectCone(Point3d[] coordinates, PickCone cone, PickIntersection pi)
/* */ {
/* 3128 */ Point3d origin = getPoint3d();
/* 3129 */ Point3d end = getPoint3d();
/* 3130 */ Vector3d direction = getVector3d();
/* 3131 */ Vector3d originToIpnt = getVector3d();
/* */
/* 3134 */ Point3d iPnt1 = getPoint3d();
/* 3135 */ Point3d iPnt2 = getPoint3d();
/* 3136 */ Vector3d vector = getVector3d();
/* */
/* 3139 */ cone.getOrigin(origin);
/* 3140 */ cone.getDirection(direction);
/* */
/* 3143 */ if ((cone instanceof PickConeSegment)) {
/* 3144 */ ((PickConeSegment)cone).getEnd(end);
/* */ }
/* */
/* 3149 */ if (coordinates.length > 2) {
/* 3150 */ if ((cone instanceof PickConeRay)) {
/* 3151 */ if (intersectRay(coordinates, new PickRay(origin, direction), pi)) {
/* 3152 */ freePoint3d(origin);
/* 3153 */ freePoint3d(end);
/* 3154 */ freePoint3d(iPnt1);
/* 3155 */ freePoint3d(iPnt2);
/* 3156 */ freeVector3d(direction);
/* 3157 */ freeVector3d(originToIpnt);
/* 3158 */ freeVector3d(vector);
/* 3159 */ return true;
/* */ }
/* */
/* */ }
/* 3163 */ else if (intersectSegment(coordinates, new PickSegment(origin, end), pi))
/* */ {
/* 3165 */ freePoint3d(origin);
/* 3166 */ freePoint3d(end);
/* 3167 */ freePoint3d(iPnt1);
/* 3168 */ freePoint3d(iPnt2);
/* 3169 */ freeVector3d(direction);
/* 3170 */ freeVector3d(originToIpnt);
/* 3171 */ freeVector3d(vector);
/* 3172 */ return true;
/* */ }
/* */
/* */ }
/* */
/* 3179 */ for (int i = 0; i < coordinates.length - 1; i++)
/* */ {
/* */ double sqDistToEdge;
/* */ double sqDistToEdge;
/* 3180 */ if ((cone instanceof PickConeSegment)) {
/* 3181 */ sqDistToEdge = Distance.segmentToSegment(origin, end, coordinates[i], coordinates[(i + 1)], iPnt1, iPnt2, null);
/* */ }
/* */ else
/* */ {
/* 3187 */ sqDistToEdge = Distance.rayToSegment(origin, direction, coordinates[i], coordinates[(i + 1)], iPnt1, iPnt2, null);
/* */ }
/* */
/* 3192 */ originToIpnt.sub(iPnt1, origin);
/* 3193 */ double distance = originToIpnt.length();
/* 3194 */ double radius = Math.tan(cone.getSpreadAngle()) * distance;
/* 3195 */ if (sqDistToEdge <= radius * radius)
/* */ {
/* 3197 */ pi.setPointCoordinatesVW(iPnt2);
/* 3198 */ pi.setDistance(distance);
/* */
/* 3200 */ freePoint3d(origin);
/* 3201 */ freePoint3d(end);
/* 3202 */ freePoint3d(iPnt1);
/* 3203 */ freePoint3d(iPnt2);
/* 3204 */ freeVector3d(direction);
/* 3205 */ freeVector3d(originToIpnt);
/* 3206 */ freeVector3d(vector);
/* */
/* 3208 */ return true;
/* */ }
/* */ }
/* */
/* 3212 */ freePoint3d(origin);
/* 3213 */ freePoint3d(end);
/* 3214 */ freePoint3d(iPnt1);
/* 3215 */ freePoint3d(iPnt2);
/* 3216 */ freeVector3d(direction);
/* 3217 */ freeVector3d(originToIpnt);
/* 3218 */ freeVector3d(vector);
/* */
/* 3220 */ return false;
/* */ }
/* */
/* */ static boolean intersectCylinder(Point3d pt, PickCylinder cyl, PickIntersection pi)
/* */ {
/* 3231 */ Point3d origin = getPoint3d();
/* 3232 */ Point3d end = getPoint3d();
/* 3233 */ Vector3d direction = getVector3d();
/* 3234 */ Point3d iPnt = getPoint3d();
/* 3235 */ Vector3d originToIpnt = getVector3d();
/* */
/* 3238 */ cyl.getOrigin(origin);
/* 3239 */ cyl.getDirection(direction);
/* 3240 */ double radius = cyl.getRadius();
/* */ double sqDist;
/* */ double sqDist;
/* 3243 */ if ((cyl instanceof PickCylinderSegment)) {
/* 3244 */ ((PickCylinderSegment)cyl).getEnd(end);
/* 3245 */ sqDist = Distance.pointToSegment(pt, origin, end, iPnt, null);
/* */ }
/* */ else {
/* 3248 */ sqDist = Distance.pointToRay(pt, origin, direction, iPnt, null);
/* */ }
/* 3250 */ if (sqDist <= radius * radius) {
/* 3251 */ pi.setPointCoordinatesVW(pt);
/* 3252 */ originToIpnt.sub(iPnt, origin);
/* 3253 */ pi.setDistance(originToIpnt.length());
/* */
/* 3255 */ freePoint3d(origin);
/* 3256 */ freePoint3d(end);
/* 3257 */ freeVector3d(direction);
/* 3258 */ freePoint3d(iPnt);
/* 3259 */ freeVector3d(originToIpnt);
/* 3260 */ return true;
/* */ }
/* 3262 */ freePoint3d(origin);
/* 3263 */ freePoint3d(end);
/* 3264 */ freeVector3d(direction);
/* 3265 */ freePoint3d(iPnt);
/* 3266 */ freeVector3d(originToIpnt);
/* 3267 */ return false;
/* */ }
/* */
/* */ static boolean intersectCone(Point3d pt, PickCone cone, PickIntersection pi)
/* */ {
/* 3278 */ Point3d origin = getPoint3d();
/* 3279 */ Point3d end = getPoint3d();
/* 3280 */ Vector3d direction = getVector3d();
/* 3281 */ Point3d iPnt = getPoint3d();
/* 3282 */ Vector3d originToIpnt = getVector3d();
/* */
/* 3285 */ cone.getOrigin(origin);
/* 3286 */ cone.getDirection(direction);
/* */ double sqDist;
/* */ double sqDist;
/* 3291 */ if ((cone instanceof PickConeSegment)) {
/* 3292 */ ((PickConeSegment)cone).getEnd(end);
/* 3293 */ sqDist = Distance.pointToSegment(pt, origin, end, iPnt, null);
/* */ }
/* */ else {
/* 3296 */ sqDist = Distance.pointToRay(pt, origin, direction, iPnt, null);
/* */ }
/* 3298 */ originToIpnt.sub(iPnt, origin);
/* 3299 */ double distance = originToIpnt.length();
/* 3300 */ double radius = Math.tan(cone.getSpreadAngle()) * distance;
/* 3301 */ if (sqDist <= radius * radius) {
/* 3302 */ pi.setPointCoordinatesVW(pt);
/* 3303 */ pi.setDistance(distance);
/* */
/* 3305 */ freePoint3d(origin);
/* 3306 */ freePoint3d(end);
/* 3307 */ freeVector3d(direction);
/* 3308 */ freePoint3d(iPnt);
/* 3309 */ freeVector3d(originToIpnt);
/* */
/* 3311 */ return true;
/* */ }
/* 3313 */ freePoint3d(origin);
/* 3314 */ freePoint3d(end);
/* 3315 */ freeVector3d(direction);
/* 3316 */ freePoint3d(iPnt);
/* 3317 */ freeVector3d(originToIpnt);
/* */
/* 3319 */ return false;
/* */ }
/* */
/* */ static Vector3d getVector3d() {
/* 3323 */ return (Vector3d)UtilFreelistManager.vector3dFreelist.getObject();
/* */ }
/* */
/* */ static void freeVector3d(Vector3d v) {
/* 3327 */ UtilFreelistManager.vector3dFreelist.add(v);
/* */ }
/* */
/* */ static Point3d getPoint3d() {
/* 3331 */ return (Point3d)UtilFreelistManager.point3dFreelist.getObject();
/* */ }
/* */
/* */ static void freePoint3d(Point3d p) {
/* 3335 */ UtilFreelistManager.point3dFreelist.add(p);
/* */ }
/* */ }
/* Location: Z:\System\Library\Java\Extensions\j3dutils.jar
* Qualified Name: com.sun.j3d.utils.picking.PickResult
* JD-Core Version: 0.6.2
*/