~sharpie/geos/3.3.2

« back to all changes in this revision

Viewing changes to source/headers/geos/geom.h

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2006-11-06 21:35:52 UTC
  • mfrom: (3.1.3 feisty)
  • Revision ID: james.westby@ubuntu.com-20061106213552-m03o92ggj1na737b
Tags: 2.2.3-3
debian/control: move doxygen from build-depends-indep to build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**********************************************************************
2
 
 * $Id: geom.h,v 1.35 2004/12/16 16:27:24 strk Exp $
 
2
 * $Id: geom.h,v 1.34.2.2.2.5 2006/04/28 18:39:57 sgillies Exp $
3
3
 *
4
4
 * GEOS - Geometry Engine Open Source
5
5
 * http://geos.refractions.net
6
6
 *
7
7
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
 
8
 * Copyright (C) 2005 Refractions Research Inc.
8
9
 *
9
10
 * This is free software; you can redistribute and/or modify it under
10
11
 * the terms of the GNU Lesser General Public Licence as published
22
23
#include <vector>
23
24
#include <algorithm>
24
25
#include <map>
25
 
#include <math.h>
 
26
#include <cmath>
26
27
#include <geos/platform.h>
27
28
 
28
29
using namespace std;
337
338
 * The standard comparison functions will ignore the z-ordinate.
338
339
 *
339
340
 */
 
341
// Define the following to make assignments and copy constructions
 
342
// NON-inline (will let profilers report usages)
 
343
//#define PROFILE_COORDINATE_COPIES 1
340
344
class Coordinate {
341
345
public:
342
346
        //void setNull(void);
354
358
        //double distance(Coordinate& p);
355
359
        static Coordinate nullCoord;
356
360
 
357
 
        void Coordinate::setNull() {
 
361
        void setNull() {
358
362
                x=DoubleNotANumber;
359
363
                y=DoubleNotANumber;
360
364
                z=DoubleNotANumber;
361
365
        }
362
366
 
363
 
        static Coordinate& Coordinate::getNull() {
 
367
        static Coordinate& getNull() {
364
368
                return nullCoord;
365
369
        }
366
370
 
367
 
        Coordinate::Coordinate() {
 
371
        Coordinate() {
368
372
                x=0.0;
369
373
                y=0.0;
370
374
                z=DoubleNotANumber;
371
375
        }
372
376
 
373
 
        Coordinate::Coordinate(double xNew, double yNew, double zNew) {
 
377
        Coordinate(double xNew, double yNew, double zNew) {
374
378
                x=xNew;
375
379
                y=yNew;
376
380
                z=zNew;
377
381
        }
378
382
 
379
 
        Coordinate::Coordinate(const Coordinate& c){
 
383
#ifndef PROFILE_COORDINATE_COPIES
 
384
        Coordinate(const Coordinate& c){
380
385
                x=c.x;
381
386
                y=c.y;
382
387
                z=c.z;
383
388
        }
 
389
#else
 
390
        Coordinate(const Coordinate& c);
 
391
        Coordinate &operator=(const Coordinate &c);
 
392
#endif
384
393
 
385
 
        Coordinate::Coordinate(double xNew, double yNew){
 
394
        Coordinate(double xNew, double yNew){
386
395
                x=xNew;
387
396
                y=yNew;
388
397
                z=DoubleNotANumber;
389
398
        }
390
399
 
391
 
        void Coordinate::setCoordinate(const Coordinate& other) {
 
400
        void setCoordinate(const Coordinate& other) {
392
401
                x = other.x;
393
402
                y = other.y;
394
403
                z = other.z;
395
404
        }
396
405
 
397
 
        bool Coordinate::equals2D(const Coordinate& other) const {
 
406
        bool equals2D(const Coordinate& other) const {
398
407
                if (x != other.x) {
399
408
                return false;
400
409
                }
404
413
                return true;
405
414
        }
406
415
 
407
 
        int Coordinate::compareTo(const Coordinate& other) const {
 
416
        int compareTo(const Coordinate& other) const {
408
417
                if (x < other.x) {
409
418
                return -1;
410
419
                }
420
429
                return 0;
421
430
        }
422
431
 
423
 
        bool Coordinate::equals3D(const Coordinate& other) const {
 
432
        bool equals3D(const Coordinate& other) const {
424
433
                return (x == other.x) && ( y == other.y) && ((z == other.z)||(ISNAN(z) && ISNAN(other.z)));
425
434
        }
426
435
 
427
 
        void Coordinate::makePrecise(const PrecisionModel *precisionModel) {
 
436
        void makePrecise(const PrecisionModel *precisionModel) {
428
437
                x = precisionModel->makePrecise(x);
429
438
                y = precisionModel->makePrecise(y);
430
439
        }
431
440
 
432
 
        double Coordinate::distance(const Coordinate& p) const {
 
441
        double distance(const Coordinate& p) const {
433
442
                double dx = x - p.x;
434
443
                double dy = y - p.y;
435
444
                return sqrt(dx * dx + dy * dy);
436
445
        }
437
446
 
438
 
        int Coordinate::hashCode() {
 
447
        int hashCode() {
439
448
                //Algorithm from Effective Java by Joshua Bloch [Jon Aquino]
440
449
                int result = 17;
441
450
                result = 37 * result + hashCode(x);
447
456
        * Returns a hash code for a double value, using the algorithm from
448
457
        * Joshua Bloch's book <i>Effective Java</i>
449
458
        */
450
 
        static int Coordinate::hashCode(double x) {
 
459
        static int hashCode(double x) {
451
460
                int64 f = (int64)(x);
452
461
                return (int)(f^(f>>32));
453
462
        }
689
698
        /// Reverse Coordinate order in given CoordinateSequence
690
699
        static void reverse(CoordinateSequence *cl);
691
700
 
 
701
        /// Get number of dimensions
 
702
        virtual unsigned int getDimension() const=0;
 
703
 
 
704
        virtual double getOrdinate(unsigned int index, unsigned int ordinateIndex) const=0;
 
705
 
 
706
        virtual void setOrdinate(unsigned int index, unsigned int ordinateIndex, double value)=0;
 
707
 
 
708
        /// Standard ordinate index values
 
709
        enum { X,Y,Z,M };
 
710
 
 
711
        double getX(unsigned int index) const { return getOrdinate(index, X); }
 
712
        double getY(unsigned int index) const { return getOrdinate(index, Y); }
 
713
        double getZ(unsigned int index) const { return getOrdinate(index, Z); }
692
714
};
693
715
 
694
716
/**
729
751
        void setPoints(const vector<Coordinate> &v);
730
752
private:
731
753
        vector<Coordinate> *vect;
 
754
 
 
755
public:
 
756
        unsigned int getDimension() const { return 3; }
 
757
        void setOrdinate(unsigned int index, unsigned int ordinateIndex, double value);
 
758
        double getOrdinate(unsigned int index, unsigned int ordinateIndex) const;
732
759
};
733
760
 
734
761
struct point_3d {
763
790
private:
764
791
        vector<point_3d> *vect;
765
792
        mutable vector<Coordinate>*cached_vector;
 
793
public:
 
794
        unsigned int getDimension() const { return 3; }
 
795
        void setOrdinate(unsigned int index, unsigned int ordinateIndex, double value);
 
796
        double getOrdinate(unsigned int index, unsigned int ordinateIndex) const;
766
797
};
767
798
 
768
799
/**
794
825
         * create an empty CoordinateSequence.
795
826
         */
796
827
        virtual CoordinateSequence *create(vector<Coordinate> *coordinates) const=0;
 
828
 
 
829
        virtual CoordinateSequence *create(unsigned int size, unsigned int dims) const=0;
797
830
};
798
831
 
799
832
/**
826
859
         * Returns the singleton instance of DefaultCoordinateSequenceFactory
827
860
         */
828
861
        static const CoordinateSequenceFactory *instance();
 
862
 
 
863
        CoordinateSequence *create(unsigned int size, unsigned int dims) const;
829
864
};
830
865
 
831
866
/*
838
873
public:
839
874
 
840
875
        CoordinateSequence *create(vector<Coordinate> *coords) const;
 
876
        CoordinateSequence *create(unsigned int size, unsigned int dims) const;
841
877
};
842
878
 
843
879
/*
1074
1110
 *  analysis methods, it will throw an exception. If possible the exception will
1075
1111
 *  report the location of the collapse. <P>
1076
1112
 *
1077
 
 *  #equals(Object) and #hashCode are not overridden, so that when two
 
1113
 *  equals(Object) and hashCode are not overridden, so that when two
1078
1114
 *  topologically equal Geometries are added to HashMaps and HashSets, they
1079
1115
 *  remain distinct. This behaviour is desired in many cases.
1080
1116
 *
1841
1877
#else        
1842
1878
        static const int64 serialVersionUID = 4902022702746614570LL;
1843
1879
#endif        
 
1880
public:
 
1881
        const CoordinateSequence *getCoordinatesRO() const;
1844
1882
};
1845
1883
 
1846
1884
/**
1947
1985
        */
1948
1986
        LinearRing(CoordinateSequence* points, const GeometryFactory *newFactory);
1949
1987
 
1950
 
        virtual Geometry *clone() const;
1951
1988
        virtual ~LinearRing();
1952
1989
        bool isSimple() const;
1953
1990
        string getGeometryType() const;
1954
1991
        virtual GeometryTypeId getGeometryTypeId() const;
1955
1992
        bool isClosed() const;
1956
1993
        void setPoints(CoordinateSequence* cl);
 
1994
    Geometry* clone() const;
1957
1995
private:
1958
1996
#ifdef INT64_CONST_IS_I64
1959
1997
        static const int64 serialVersionUID = -4261142084085851829I64;
2432
2470
 
2433
2471
/**********************************************************************
2434
2472
 * $Log: geom.h,v $
2435
 
 * Revision 1.35  2004/12/16 16:27:24  strk
2436
 
 * Fixed LinearRing::clone() to return LinearRing instead of LineString
 
2473
 * Revision 1.34.2.2.2.5  2006/04/28 18:39:57  sgillies
 
2474
 * Add LinearRing::clone (bug 102)
 
2475
 *
 
2476
 * Revision 1.34.2.2.2.4  2006/01/16 11:08:38  strk
 
2477
 * Removed invalid full qualification of in-class-declaration methods.
 
2478
 *
 
2479
 * Revision 1.34.2.2.2.3  2005/11/29 17:52:21  strk
 
2480
 * undef PROFILE_COORDINATE_COPIES (was introduced by previous commit, to easy profiling)
 
2481
 *
 
2482
 * Revision 1.34.2.2.2.2  2005/11/29 17:51:15  strk
 
2483
 * Forgot to add the capi/ dir
 
2484
 *
 
2485
 * Revision 1.34.2.2.2.1  2005/11/29 16:58:17  strk
 
2486
 * Back-ported WKB IO and C api.
 
2487
 * Added required higher dimensional interfaces for CoordinateSequence
 
2488
 *
 
2489
 * Revision 1.34.2.2  2005/11/08 09:08:07  strk
 
2490
 * Cleaned up a couple of Doxygen warnings
 
2491
 *
 
2492
 * Revision 1.34.2.1  2005/05/23 18:16:40  strk
 
2493
 * more math.h to cmath conversions
2437
2494
 *
2438
2495
 * Revision 1.34  2004/12/03 22:52:56  strk
2439
2496
 * enforced const return of CoordinateSequence::toVector() method to derivate classes.