001: /*
002: * $RCSfile: BBox.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.4 $
041: * $Date: 2007/02/09 17:20:17 $
042: * $State: Exp $
043: */
044:
045: // ----------------------------------------------------------------------
046: //
047: // The reference to Fast Industrial Strength Triangulation (FIST) code
048: // in this release by Sun Microsystems is related to Sun's rewrite of
049: // an early version of FIST. FIST was originally created by Martin
050: // Held and Joseph Mitchell at Stony Brook University and is
051: // incorporated by Sun under an agreement with The Research Foundation
052: // of SUNY (RFSUNY). The current version of FIST is available for
053: // commercial use under a license agreement with RFSUNY on behalf of
054: // the authors and Stony Brook University. Please contact the Office
055: // of Technology Licensing at Stony Brook, phone 631-632-9009, for
056: // licensing information.
057: //
058: // ----------------------------------------------------------------------
059: package com.sun.j3d.utils.geometry;
060:
061: import java.io.*;
062: import java.util.*;
063: import javax.vecmath.*;
064:
065: /**
066: * Bounding Box class for Triangulator.
067: */
068: class BBox {
069: int imin; /* lexicographically smallest point, determines min-x */
070: int imax; /* lexicographically largest point, determines max-x */
071: double ymin; /* minimum y-coordinate */
072: double ymax; /* maximum y-coordinate */
073:
074: /**
075: * This constructor computes the bounding box of a line segment whose end
076: * points i, j are sorted according to x-coordinates.
077: */
078: BBox(Triangulator triRef, int i, int j) {
079: // assert(InPointsList(i));
080: // assert(InPointsList(j));
081:
082: imin = Math.min(i, j);
083: imax = Math.max(i, j);
084: ymin = Math.min(triRef.points[imin].y, triRef.points[imax].y);
085: ymax = Math.max(triRef.points[imin].y, triRef.points[imax].y);
086: }
087:
088: boolean pntInBBox(Triangulator triRef, int i) {
089: return (((imax < i) ? false
090: : ((imin > i) ? false
091: : ((ymax < triRef.points[i].y) ? false
092: : ((ymin > triRef.points[i].y) ? false
093: : true)))));
094: }
095:
096: boolean BBoxOverlap(BBox bb) {
097: return (((imax < (bb).imin) ? false
098: : ((imin > (bb).imax) ? false
099: : ((ymax < (bb).ymin) ? false
100: : ((ymin > (bb).ymax) ? false : true)))));
101: }
102:
103: boolean BBoxContained(BBox bb) {
104: return ((imin <= (bb).imin) && (imax >= (bb).imax)
105: && (ymin <= (bb).ymin) && (ymax >= (bb).ymax));
106: }
107:
108: boolean BBoxIdenticalLeaf(BBox bb) {
109: return ((imin == (bb).imin) && (imax == (bb).imax));
110: }
111:
112: void BBoxUnion(BBox bb1, BBox bb3) {
113: (bb3).imin = Math.min(imin, (bb1).imin);
114: (bb3).imax = Math.max(imax, (bb1).imax);
115: (bb3).ymin = Math.min(ymin, (bb1).ymin);
116: (bb3).ymax = Math.max(ymax, (bb1).ymax);
117: }
118:
119: double BBoxArea(Triangulator triRef) {
120: return (triRef.points[imax].x - triRef.points[imin].x)
121: * (ymax - ymin);
122: }
123: }
|