-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpatialAlgebra.h
executable file
·4663 lines (3539 loc) · 129 KB
/
SpatialAlgebra.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
----
This file is part of SECONDO.
Copyright (C) 2004, University in Hagen, Department of Computer Science,
Database Systems for New Applications.
SECONDO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
SECONDO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SECONDO; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
----
//paragraph [1] Title: [{\Large \bf \begin {center}] [\end {center}}]
//[TOC] [\tableofcontents]
//[_] [\_]
[1] Header File of the Spatial Algebra
February, 2003 Victor Teixeira de Almeida
March-July, 2003 Zhiming DING
January, 2005 Leonardo Guerreiro Azevedo
December 2005, Victor Almeida deleted the deprecated algebra levels
(~executable~, ~descriptive~, and ~hibrid~). Only the executable
level remains. Models are also removed from type constructors.
[TOC]
1 Overview
This header file essentially contains the definition of the classes ~Point~,
~Points~, ~Line~, and ~Region~ used in the Spatial Algebra. These classes
respectively correspond to the memory representation for the type constructors
~point~, ~points~, ~line~, and ~region~. Figure \cite{fig:spatialdatatypes.eps}
shows examples of these spatial data types.
2 Defines and includes
*/
#ifndef __SPATIAL_ALGEBRA_H__
#define __SPATIAL_ALGEBRA_H__
#include <math.h>
#include <cmath>
#include <fstream>
#include <stack>
#include <vector>
#include <queue>
#include "Attribute.h"
#include "../../Tools/Flob/DbArray.h"
#include "../Rectangle/RectangleAlgebra.h"
#include "WinUnix.h"
#include "AvlTree.h"
#include "AlmostEqual.h"
#include "AVLSegment.h"
#include "HalfSegment.h"
#include "Coord.h"
#include "Geoid.h"
#include "NestedList.h"
#include "ListUtils.h"
/*
Coordinates are represented by real numbers.
*/
/*
The $\pi$ value.
*/
enum WindowEdge { WTOP, WBOTTOM, WLEFT, WRIGHT };
/*
The four edges of a window.
*/
class Point;
class Points;
class HalfSegment;
class Line;
class Region;
class SimpleLine;
class GrahamScan;
class SimplePoint;
/*
Forward declarations.
3 Auxiliary Functions
*/
// const double FACTOR = 0.00000001; // moved to Attribute.h
inline double ApplyFactor( const double d );
inline int CompareDouble(const double a, const double b){
if(AlmostEqual(a,b))
{
return 0;
}
if(a<b)
{
return -1;
}
return 1;
}
bool getDir(const vector<Point>& vp);
int HalfSegmentCompare(const void *a, const void *b);
int PointHalfSegmentCompare( const void *a, const void *b );
int PointHalfSegmentCompareAlmost( const void *a, const void *b );
int LRSCompare( const void *a, const void *b );
// for finding insert position and sorting the DBArray:
int PointCompare( const void *a, const void *b );
// for checking whether DBArray contains an element and
// removing duplicates:
int PointCompareAlmost( const void *a, const void *b );
/*
5 Class Points
This class implements the memory representation of the ~points~ type constructor.
A points value is a finite set of points. An example of a points value can be seen
in the Figure \cite{fig:spatialdatatypes.eps}.
The implementation of the points type constructor is a persistent array of points
ordered by lexicographic order.
*/
class Points: public StandardSpatialAttribute<2>
{
public:
/*
5.1 Constructors and Destructor
There are three ways of constructing a point set:
*/
inline Points() {}
/*
This constructor should not be used.
*/
explicit inline Points( const int initsize );
/*
The first one constructs an empty point set but open space for ~initsize~ points.
*/
inline Points( const Points& ps);
/*
The second one receives another point set ~ps~ as argument and constructs a point
set which is a copy of ~ps~.
*/
inline void Destroy()
{
points.destroy();
}
/*
This function should be called before the destructor if one wants to destroy the
persistent array of points. It marks the persistent array for destroying. The
destructor will perform the real destroying.
*/
inline ~Points()
{}
/*
The destructor.
5.2 Functions for Bulk Load of Points
As said before, the point set is implemented as an ordered persistent array of points.
The time complexity of an insertion operation in an ordered array is $O(n)$, where ~n~
is the size of the point set. In some cases, bulk load of points for example, it is good
to relax the ordered condition to improve the performance. We have relaxed this ordered
condition only for bulk load of points. All other operations assume that the point set is
ordered.
*/
inline bool IsOrdered() const;
/*
Returns whether the point set is ordered. There is a flag ~ordered~ (see attributes) in order
to avoid a scan in the point set to answer this question.
*/
void StartBulkLoad();
/*
Marks the begin of a bulk load of points relaxing the condition that the points must be
ordered.
*/
void EndBulkLoad( bool sort = true, bool remDup = true, bool trim = true );
/*
Marks the end of a bulk load and sorts the point set if the argument ~sort~ is set to true.
5.3 Member functions
*/
inline const Rectangle<2> BoundingBox(const Geoid* geoid = 0) const;
/*
Returns the bounding box that spatially contains all points.
*/
inline bool IsEmpty() const;
/*
Returns true iff the set is undefined or empty.
*/
bool IsValid() const;
/*
Checks if the point set is valid, i.e., if it contains only defined points and
no duplicates.
*/
inline int Size() const;
/*
Returns the size of the point set in terms of number of points.
Returns ~0~ if the set is empty.
*/
void Clear();
/*
Clears the point set.
*/
inline void Resize(const int newSize);
/*
Sets the new capacity of the points array to the
maximum of its original size and the argument.
*/
inline void TrimToSize();
/*
Sets the new capacity of the points array to the amount really required.
*/
inline bool Get( const int i, Point& p ) const;
/*
Retrieves the point ~p~ at position ~i~ in the point set.
*Precondition:* $0 \leq i < Size()$
*/
Points& operator=( const Points& ps );
/*
Assignement operator redefinition.
*/
bool Contains( const Point& p, const Geoid* geoid=0 ) const;
/*
Searches (binary search algorithm) for a point in the point set and
return ~true~ if found and ~false~ if not.
*Precondition:* ~this.IsOrdered() $\&\&$ p.IsDefined()~
*/
bool Contains( const Points& ps, const Geoid* geoid=0 ) const;
/*
Returns ~true~ if this point set contains the ~ps~ point set and
~false~ otherwise.
*Precondition:* ~this.IsOrdered() $\&\&$ ps.IsOrdered()~
*/
/*
5.4 Operations
5.4.1 Operation $=$ (~equal~)
*Precondition:* ~U.IsOrdered() $\&\&$ V.IsOrdered()~
*Semantics:* $U = V$
*Complexity:* $O(n+m)$, where ~n~ is the size of ~U~ and m the size of ~V~.
*/
bool operator==( const Points& ) const;
bool operator==( const Point&) const;
/*
5.4.2 Operation $\neq$ (~not equal~)
*Precondition:* ~U.IsOrdered() $\&\&$ V.IsOrdered()~
*Semantics:* $U = V$
*Complexity:* $O(n+m)$, where ~n~ is the size of ~U~ and m the size of ~V~.
*/
bool operator!=( const Points& ) const;
/*
5.4.3 Operation ~union~ (with ~point~)
*Precondition:* ~v.IsDefined()~
*Semantics:* $U \cup \{v\}$
*Complexity:* $O(1)$, if the set is not ordered, and $O(log(n)+n)$, otherwise, where ~n~ is the size
of ~U~.
*/
Points& operator+=( const Point& p );
/*
5.4.4 Operation ~union~ (with ~points~)
*Semantics:* $U \cup V$
*Complexity:* $O(m)$, if the sets are not ordered, and $O(m+(m+n)log(m+n))$, otherwise, where ~n~ is
the size of ~U~ and ~m~ is the size of ~V~.
*/
Points& operator+=( const Points& ps );
/*
5.4.5 Operation ~minus~ (with ~point~)
*Precondition:* ~U.IsOrdered() $\&\&$ v.IsDefined()~
*Semantics:* $U \backslash \{v\}$
*Complexity:* $O(log(n)+n)$
*/
Points& operator-=( const Point& p );
/*
5.4.6 Operation ~inside~
*Precondition:* ~U.IsOrdered() $\&\&$ V.IsOrdered()~
*Semantics:* $U \subseteq V$
*Complexity:* $O(n+m)$, where ~n~ is the size of ~U~ and m the size of ~V~.
*/
bool Inside( const Points& ps, const Geoid* geoid=0 ) const;
/*
6.4.4 Operation ~inside~ (with ~line~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*Semantics:* $U \subseteq V$
*Complexity:* $O(m.n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool Inside( const Line& l, const Geoid* geoid=0 ) const;
/*
6.4.4 Operation ~inside~ (with ~region~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*Semantics:* $U \subseteq V$
*Complexity:* $O(m \log n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool Inside( const Region& r, const Geoid* geoid=0 ) const;
/*
5.4.7 Operation ~intersects~ (with ~points~)
*Precondition:* ~U.IsOrdered() $\&\&$ V.IsOrdered()~
*Semantics:* $U \cap V \neq \emptyset$
*Complexity:* $O(m+n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool Intersects( const Points& ps, const Geoid* geoid=0 ) const;
/*
5.4.7 Operation ~intersects~ (with ~line~)
*Precondition:* ~U.IsOrdered() $\&\&$ V.IsOrdered()~
*Semantics:* $U \cap V \neq \emptyset$
*Complexity:* $O(m \log n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool Intersects( const Line& l, const Geoid* geoid=0 ) const;
/*
5.4.7 Operation ~intersects~ (with ~region~)
*Precondition:* ~U.IsOrdered() $\&\&$ V.IsOrdered()~
*Semantics:* $U \cap V \neq \emptyset$
*Complexity:* $O(m \log n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool Intersects( const Region& r, const Geoid* geoid=0 ) const;
/*
5.4.7 Operation ~adjacent~ (with ~region~)
*Precondition:* ~U.IsOrdered() $\&\&$ V.IsOrdered()~
*Semantics:* $\partial U \cap \partial V \neq \emptyset \land U^0 \cap V^0 = \emptyset$
*Complexity:* $O(n.m)$, where ~n~ is the size of ~U~ and m the size of ~V~.
*/
bool Adjacent( const Region& r, const Geoid* geoid=0 ) const;
/*
5.4.8 Operation ~intersection~
*/
void Intersection(const Point& p, Points& result,
const Geoid* geoid=0) const;
void Intersection( const Points& ps, Points& result,
const Geoid* geoid=0 ) const;
void Intersection( const Line& l, Points& result,
const Geoid* geoid=0 ) const;
void Intersection( const Region& r, Points& result ,
const Geoid* geoid=0) const;
void Intersection(const SimpleLine&l, Points& result,
const Geoid* geoid=0) const;
/*
5.4.8 Operation ~minus~
*/
void Minus( const Point& p, Points& result, const Geoid* geoid=0 ) const;
void Minus( const Points& ps, Points& result, const Geoid* geoid=0 ) const;
void Minus( const Line& l, Points& result, const Geoid* geoid=0 ) const;
void Minus( const Region& r, Points& result, const Geoid* geoid=0 ) const;
void Minus( const SimpleLine& l, Points& result, const Geoid* geoid=0 ) const;
/*
5.4.9 Operation ~union~
*/
void Union(const Point& p, Points& result, const Geoid* geoid=0 ) const;
void Union(const Points& ps, Points& result, const Geoid* geoid=0 ) const;
void Union(const Line& line, Line& result, const Geoid* geoid=0 ) const;
void Union(const Region& region, Region& result, const Geoid* geoid=0 ) const;
void Union(const SimpleLine& line, SimpleLine& result,
const Geoid* geoid=0 ) const;
double Distance( const Point& p, const Geoid* geoid=0 ) const;
/*
5.4.9 Operation ~distance~ (with ~points~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*Semantics:* $\min\{ dist(u, v) | u \in U, v \in V \}$
*Complexity:* $O(m.n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~
*/
double Distance( const Points& ps, const Geoid* geoid=0 ) const;
/*
5.4.9 Operation ~distance~ (with ~rect2~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*/
double Distance( const Rectangle<2>& r, const Geoid* geoid=0 ) const;
/*
4.3.14 Operation ~translate~
*Precondition:* ~U.IsOrdered()~
*Semantics:* ~U + (x, y)~
*Complexity:* $O(n)$, where ~n~ is the size of ~U~
*/
void Translate( const Coord& x, const Coord& y, Points& ps ) const;
/*
4.3.15 Operation ~rotate~
Rotates all contained points around the point defined by (x,y) with
angle ~alpha~.
*/
void Rotate( const Coord& x, const Coord& y, double alpha,
Points& res ) const;
/*
4.3.16 Operation ~center~
Computes the center of this points object.
*/
Point theCenter() const;
/*
4.4 Object Traversal Functions
These functions are object traversal functions which are useful when we are
using ROSE algebra algorithms.
*Pre-condition:* ~IsOrdered()~
*Complexity:* All these functions have a complexity of $O( 1 )$ .
*/
inline void SelectFirst() const;
/*
Puts the pointer ~pos~ to the first point in the ~points~ value.
*/
inline void SelectNext() const;
/*
Moves the pointer ~pos~ to the next point in the ~points~ value.
*/
inline bool EndOfPt() const;
/*
Decides whether ~pos~ is -1, which indicates that no more points in the ~points~ value
need to be processed.
*/
inline bool GetPt( Point& p ) const;
/*
Gets the current point from the ~points~ value according to the ~pos~ pointer.
5.6 Functions needed to import the the ~points~ data type to tuple
There are totally 10 functions which are defined as virtual functions. They need
to be defined here in order for the Point data type to be used in Tuple definition
as an attribute.
*/
inline int NumOfFLOBs() const;
inline Flob* GetFLOB( const int i );
inline size_t Sizeof() const;
size_t HashValue() const;
void CopyFrom( const Attribute* right );
int Compare( const Attribute *arg ) const;
int CompareAlmost( const Attribute *arg ) const;
bool Adjacent( const Attribute *arg ) const;
virtual Points* Clone() const;
ostream& Print( ostream &os ) const;
virtual uint32_t getshpType() const{
return 8; // Point Type
}
virtual bool hasBox() const{
return IsDefined();
}
virtual double getMinX() const{
return bbox.MinD(0);
}
virtual double getMaxX() const{
return bbox.MaxD(0);
}
virtual double getMinY() const{
return bbox.MinD(1);
}
virtual double getMaxY() const{
return bbox.MaxD(1);
}
virtual void writeShape(ostream& o, uint32_t RecNo) const{
// first, write the record header
WinUnix::writeBigEndian(o,RecNo);
uint32_t size = points.Size();
if(!IsDefined() || size==0){
uint32_t length = 2;
WinUnix::writeBigEndian(o,length);
uint32_t type = 0;
WinUnix::writeLittleEndian(o,type);
} else {
// length = 20 w for header
// + 8* w for eacxh two doubles
// w = 16 bit word
uint32_t length = 20 + 8*size;
WinUnix::writeBigEndian(o,length);
WinUnix::writeLittleEndian(o,getshpType());
double minX = getMinX();
double maxX = getMaxX();
double minY = getMinY();
double maxY = getMaxY();
WinUnix::writeLittle64(o,minX);
WinUnix::writeLittle64(o,minY);
WinUnix::writeLittle64(o,maxX);
WinUnix::writeLittle64(o,maxY);
// number of points
WinUnix::writeLittleEndian(o,size);
Point p(0,0);
for(uint32_t i=0;i<size;i++){
points.Get(i,&p);
double x = p.GetX();
double y = p.GetY();
WinUnix::writeLittle64(o,x);
WinUnix::writeLittle64(o,y);
}
}
}
virtual string getSQLType(){ return "MDSYS.SDO_GEOMETRY"; }
virtual string getSQLRepresentation(){
if(!IsDefined() || IsEmpty()){
return "NULL";
}
return "MDSYS.SDO_GEOMETRY('" + getWKT() + "')";
}
string getWKT() const{
stringstream ss;
ss << "MULTIPOINT(";
for(int i=0;i<Size();i++){
if(i>0){
ss << ", ";
}
Point p;
Get(i,p);
ss << p.GetX() << " " << p.GetY();
}
ss << ")";
return ss.str();
}
static const string BasicType(){
return "points";
}
static const bool checkType(const ListExpr type){
return listutils::isSymbol(type, BasicType());
}
private:
/*
5.7 Private member functions
*/
void Sort(const bool exact = true);
/*
Sorts the persistent array of points.
*/
void RemoveDuplicates();
/*
Remove duplicates in the (ordered) array of points.
*/
bool Find( const Point& p, int& pos, const bool& exact = true ) const;
/*
Searches (binary search algorithm) for a point in the point set and
returns its position. Returns -1 if the point is not found.
If exact is true, an exact search is done. If it is false, AlmostEqual
will be used instead of Equality. Use the first to find insertion
positions in the DBArray, the latter to just lookup keys to check if they
are contained.
5.8 Atrtibutes
*/
DbArray<Point> points;
/*
The persistent array of points.
*/
Rectangle<2> bbox;
/*
The bounding box that spatially contains all points.
*/
bool ordered;
/*
The flag that indicates whether the persistent array is in ordered state.
*/
mutable int pos;
/*
According to ROSE algebra, the carrier set of points should contain a pos pointer
*/
};
/*
5.9 Overloaded output operator
*/
ostream& operator<<( ostream& o, const Points& ps );
/*
6 Struct LRS
This struct implements the Linear Referencing System (LRS) ordering for lines. It basicaly contains
a position to the half segment in the line and its offset in the LRS. A line value will contain an
array ordered by these positions.
*/
struct LRS
{
LRS() {}
LRS( double lrsPos, int hsPos ):
lrsPos( lrsPos ), hsPos( hsPos )
{}
LRS( const LRS& lrs ):
lrsPos( lrs.lrsPos ), hsPos( lrs.hsPos )
{}
LRS& operator=( const LRS& lrs )
{ lrsPos = lrs.lrsPos; hsPos = lrs.hsPos; return *this; }
double lrsPos;
int hsPos;
};
/*
6 Class Line
This class implements the memory representation of the ~line~ type constructor. A line value is
actually composed of a set of arbitrarily arranged line segments. In the ROSE algebra paper, it
is called ~lines~.
A ~line~ value is a set of half segments. In the external (nested list) representation, a line value is
expressed as a set of segments. However, in the internal (class) representation, it is expressed
as a set of sorted half segments, which are stored in a DBArray.
*/
class Line: public StandardSpatialAttribute<2>
{
public:
/*
6.1 Constructors and Destructor
*/
explicit inline Line( const int n );
/*
Constructs an empty line allocating space for ~n~ half segments.
*/
inline Line( const Line& cl );
/*
The copy constructor.
*/
inline void Destroy();
/*
This function should be called before the destructor if one wants to destroy the
persistent array of half segments. It marks the persistent array for destroying. The
destructor will perform the real destroying.
*/
inline ~Line() {}
/*
The destructor.
6.2 Functions for Bulk Load
As said before, the line is implemented as an ordered persistent array of half segments.
The time complexity of an insertion operation in an ordered array is $O(n)$, where ~n~
is the number of half segments. In some cases, bulk load of segments for example, it is good
to relax the ordered condition to improve the performance. We have relaxed this ordered
condition only for bulk load of half segments. All other operations assume that the set of
half segments is ordered.
*/
inline bool IsOrdered() const;
/*
Returns whether the set of half segments is ordered. There is a flag ~ordered~ (see attributes)
in order to avoid a scan in the half segments set to answer this question.
*/
void StartBulkLoad();
/*
Marks the begin of a bulk load of half segments relaxing the condition that the points must be
ordered.
*/
void EndBulkLoad (const bool sort = true,
const bool realminize = true,
const bool robust = false);
/*
Marks the end of a bulk load for this line.
If all parameters are set to __true__, the only condition to the content
of the Halfsegment array is that for each segment both corresponding Halfsegments are
included.
If ~sort~ is set to __false__, the halfsegments must be sorted using the
halfsegment order.
If ~realminize~ is set to __false__, the halfsegments has to be realminized. This means
each pair of different halfsegments has at most a common endpoint.
Furthermore, the edge numbers of the halfsegments must be the same for the
two halfsegments of a segment. The allowed range for the edge numbers is [0..Size()/2-1].
*/
/*
6.2 Member functions
*/
/*
length computed for metric (X,Y)-coordinates
*/
inline double Length() const;
/*
length computed for geographic (LON,LAT)-coordinates and a Geoid
If any coordinate is invalid, ~valid~ is set to false (true otherwise).
*/
double Length(const Geoid& g, bool& valid) const;
/*
Returns the length of the line, i.e. the sum of the lengths of all segments.
*/
inline double SpatialSize() const{
return Length();
}
/*
Returns the length computed for geographic (LON,LAT)-coordinates and a Geoid
If any coordinate is invalid, ~valid~ is set to false (true otherwise).
*/
inline double SpatialSize(const Geoid& g, bool& valid) const{
return Length(g, valid);
}
// inline void SetLength( double length );
/*
Sets the length of the line.
*/
inline const Rectangle<2> BoundingBox(const Geoid* geoid = 0) const;
/*
Returns the bounding box of the line.
*/
// inline void SetBoundingBox( const Rectangle<2>& bbox );
/*
Sets the bounding box of the line.
*/
inline bool IsEmpty() const;
/*
Returns true iff the line is undefined or empty.
*/
inline int Size() const;
/*
Returns the number of half segments in the line value.
*/
bool Contains( const Point& p, const Geoid* geoid=0 ) const;
/*
Checks whether the point ~p~ is contained in the line
*/
inline void Get( const int i, HalfSegment& hs ) const;
/*
Reads the ith half segment from the line value.
*/
inline void Resize(const int newSize);
/*
Sets the new capacity of the halfsegment array to the
maximum of its original size and the argument.
*/
inline void TrimToSize();
/*
Sets the new capacity of the halfsegment array to the
amount really required.
*/
inline void Put( const int i, const HalfSegment& hs );
/*
Writes the the half segment ~hs~ to the ith position.
*/
Line& operator=( const Line& cl );
/*
Assignement operator redefinition.
6.4 Operations
6.4.1 Operation $=$ (~equal~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*Semantics:* $U == V$
*Complexity:* $O(m + n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool operator==( const Line& cl ) const;
/*
6.4.2 Operation $\neq$ (~not equal~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*Semantics:* $U != V$
*Complexity:* $O(m + n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool operator!=( const Line& cl ) const;
/*
6.4.3 Operation ~union~
*Semantics:* $U \cup \{v\}$
*Complexity:* $O( 1 )$, if the set is not ordered; and $O(\log n + n)$, otherwise; where
~n~ is the size of ~U~.
*/
Line& operator+=( const HalfSegment& hs );
/*
6.4.4 Oeration ~plus~
Appends all halfsegments from l to that line.
This instance must must be in bulkload mode.
*/
Line& operator+=(const Line& l);
/*
6.4.4 Operation ~minus~
*Precondition:* ~U.IsOrdered()~
*Semantics:* $U \ \{v\}$
*Complexity:* $O(log(n)+n)$, where ~n~ is the size of ~U~.
*/
Line& operator-=( const HalfSegment& hs );
/*
6.4.4 Operation ~intersects~ (with ~line~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*Semantics:* $U \cap V \neq \emptyset$
*Complexity:* $O(m.n)$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool Intersects( const Line& l, const Geoid* geoid=0 ) const;
/*
6.4.4 Operation ~intersects~ (with ~region~)
*Precondition:* ~U.IsOrdered() and V.IsOrdered()~
*Semantics:* $U \cap V \neq \emptyset$
*Complexity:* $O(m(n + \log n))$, where ~m~ is the size of ~U~ and ~n~ the size of ~V~.
*/
bool Intersects( const Region& r, const Geoid* geoid=0 ) const;