001: /*
002: * This file is part of the GeOxygene project source files.
003: *
004: * GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
005: * the development and deployment of geographic (GIS) applications. It is a open source
006: * contribution of the COGIT laboratory at the Institut Géographique National (the French
007: * National Mapping Agency).
008: *
009: * See: http://oxygene-project.sourceforge.net
010: *
011: * Copyright (C) 2005 Institut Géographique National
012: *
013: * This library is free software; you can redistribute it and/or modify it under the terms
014: * of the GNU Lesser General Public License as published by the Free Software Foundation;
015: * either version 2.1 of the License, or any later version.
016: *
017: * This library is distributed in the hope that it will be useful, but WITHOUT ANY
018: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
019: * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser General Public License along with
022: * this library (see file LICENSE if present); if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: *
025: */
026:
027: package fr.ign.cogit.geoxygene.contrib.geometrie;
028:
029: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPosition;
030: import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPositionList;
031: import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString;
032:
033: /**
034: * Rectangle.
035: *
036: * NB: utiliser autant que possible directement la classe GM_Envelope qui
037: * représente aussi des rectangles.
038: * Cette classe n'est là que pour optimiser quelques méthodes,
039: * et est essentiellement utilisée pour l'index de dallage.
040: *
041: * @author Mustière
042: * @version 1.0
043: */
044:
045: public class Rectangle {
046:
047: public double xmin;
048: public double xmax;
049: public double ymin;
050: public double ymax;
051:
052: public Rectangle() {
053: }
054:
055: public static Rectangle rectangleEnglobant(GM_LineString L) {
056: DirectPositionList listepoints = L.coord();
057: DirectPosition point;
058: Rectangle R = new Rectangle();
059: R.xmin = listepoints.get(0).getX();
060: R.xmax = listepoints.get(0).getX();
061: R.ymin = listepoints.get(0).getY();
062: R.ymax = listepoints.get(0).getY();
063:
064: for (int i = 1; i < listepoints.size(); i++) {
065: point = listepoints.get(i);
066: if (point.getX() < R.xmin)
067: R.xmin = point.getX();
068: if (point.getX() > R.xmax)
069: R.xmax = point.getX();
070: if (point.getY() < R.ymin)
071: R.ymin = point.getY();
072: if (point.getY() > R.ymax)
073: R.ymax = point.getY();
074: }
075: ;
076: return R;
077: }
078:
079: public Rectangle dilate(double dilatation) {
080: Rectangle R = new Rectangle();
081: R.xmin = this .xmin - dilatation;
082: R.xmax = this .xmax + dilatation;
083: R.ymin = this .ymin - dilatation;
084: R.ymax = this .ymax + dilatation;
085: return R;
086: };
087:
088: public boolean intersecte(Rectangle R) {
089: boolean intersecteX = false;
090: boolean intersecteY = false;
091: if (R.xmin < this .xmin && R.xmax > this .xmin)
092: intersecteX = true;
093: if (R.xmin > this .xmin && R.xmin < this .xmax)
094: intersecteX = true;
095: if (R.ymin < this .ymin && R.ymax > this .ymin)
096: intersecteY = true;
097: if (R.ymin > this .ymin && R.ymin < this .ymax)
098: intersecteY = true;
099: return (intersecteX && intersecteY);
100: }
101: }
|