SAGA API v9.10
Loading...
Searching...
No Matches
geo_classes.cpp
Go to the documentation of this file.
1
3// //
4// SAGA //
5// //
6// System for Automated Geoscientific Analyses //
7// //
8// Application Programming Interface //
9// //
10// Library: SAGA_API //
11// //
12//-------------------------------------------------------//
13// //
14// geo_classes.cpp //
15// //
16// Copyright (C) 2005 by Olaf Conrad //
17// //
18//-------------------------------------------------------//
19// //
20// This file is part of 'SAGA - System for Automated //
21// Geoscientific Analyses'. //
22// //
23// This library is free software; you can redistribute //
24// it and/or modify it under the terms of the GNU Lesser //
25// General Public License as published by the Free //
26// Software Foundation, either version 2.1 of the //
27// License, or (at your option) any later version. //
28// //
29// This library is distributed in the hope that it will //
30// be useful, but WITHOUT ANY WARRANTY; without even the //
31// implied warranty of MERCHANTABILITY or FITNESS FOR A //
32// PARTICULAR PURPOSE. See the GNU Lesser General Public //
33// License for more details. //
34// //
35// You should have received a copy of the GNU Lesser //
36// General Public License along with this program; if //
37// not, see <http://www.gnu.org/licenses/>. //
38// //
39//-------------------------------------------------------//
40// //
41// contact: Olaf Conrad //
42// Institute of Geography //
43// University of Goettingen //
44// Goldschmidtstr. 5 //
45// 37077 Goettingen //
46// Germany //
47// //
48// e-mail: oconrad@saga-gis.org //
49// //
51
52//---------------------------------------------------------
53#include "parameters.h"
54
55#include "geo_tools.h"
56
57
59// //
60// CSG_Point //
61// //
63
64//---------------------------------------------------------
66{
67 Assign(0., 0.);
68}
69
71{
72 Assign(Point.x, Point.y);
73}
74
76{
77 Assign(Point.x, Point.y);
78}
79
80CSG_Point::CSG_Point(double _x, double _y)
81{
82 Assign(_x, _y);
83}
84
85//---------------------------------------------------------
86void CSG_Point::Assign(double _x, double _y)
87{
88 x = _x;
89 y = _y;
90}
91
92void CSG_Point::Assign(const CSG_Point &Point)
93{
94 x = Point.x;
95 y = Point.y;
96}
97
98//---------------------------------------------------------
99void CSG_Point::Add(const CSG_Point &Point)
100{
101 x += Point.x;
102 y += Point.y;
103}
104
106{
107 x -= Point.x;
108 y -= Point.y;
109}
110
112{
113 x *= Point.x;
114 y *= Point.y;
115}
116
117void CSG_Point::Multiply(double Value)
118{
119 x *= Value;
120 y *= Value;
121}
122
123void CSG_Point::Divide(double Value)
124{
125 x /= Value;
126 y /= Value;
127}
128
129//---------------------------------------------------------
130double CSG_Point::Get_Length(void) const
131{
132 return( sqrt(x*x + y*y) );
133}
134
135
137// //
139
140//---------------------------------------------------------
142{
143 Assign(0., 0., 0.);
144}
145
147{
148 Assign(Point.x, Point.y, Point.z);
149}
150
152{
153 Assign(Point.x, Point.y, Point.z);
154}
155
156CSG_Point_3D::CSG_Point_3D(double _x, double _y, double _z)
157{
158 Assign(_x, _y, _z);
159}
160
161//---------------------------------------------------------
162void CSG_Point_3D::Assign(double _x, double _y, double _z)
163{
164 x = _x;
165 y = _y;
166 z = _z;
167}
168
170{
171 x = Point.x;
172 y = Point.y;
173 z = Point.z;
174}
175
176//---------------------------------------------------------
178{
179 x += Point.x;
180 y += Point.y;
181 z += Point.z;
182}
183
185{
186 x -= Point.x;
187 y -= Point.y;
188 z -= Point.z;
189}
190
192{
193 x *= Point.x;
194 y *= Point.y;
195 z *= Point.z;
196}
197
198void CSG_Point_3D::Multiply(double Value)
199{
200 x *= Value;
201 y *= Value;
202 z *= Value;
203}
204
205void CSG_Point_3D::Divide(double Value)
206{
207 x /= Value;
208 y /= Value;
209 z /= Value;
210}
211
212//---------------------------------------------------------
213double CSG_Point_3D::Get_Length(void) const
214{
215 return( sqrt(x*x + y*y + z*z) );
216}
217
218
220// //
222
223//---------------------------------------------------------
225{
226 Assign(0., 0., 0., 0.);
227}
228
230{
231 Assign(Point.x, Point.y, Point.z, Point.m);
232}
233
235{
236 Assign(Point.x, Point.y, Point.z, Point.m);
237}
238
239CSG_Point_4D::CSG_Point_4D(double _x, double _y, double _z, double _m)
240{
241 Assign(_x, _y, _z, _m);
242}
243
244//---------------------------------------------------------
245void CSG_Point_4D::Assign(double _x, double _y, double _z, double _m)
246{
247 x = _x;
248 y = _y;
249 z = _z;
250 m = _m;
251}
252
254{
255 x = Point.x;
256 y = Point.y;
257 z = Point.z;
258 m = Point.m;
259}
260
261//---------------------------------------------------------
263{
264 x += Point.x;
265 y += Point.y;
266 z += Point.z;
267 m += Point.m;
268}
269
271{
272 x -= Point.x;
273 y -= Point.y;
274 z -= Point.z;
275 m -= Point.m;
276}
277
279{
280 x *= Point.x;
281 y *= Point.y;
282 z *= Point.z;
283 m *= Point.m;
284}
285
286void CSG_Point_4D::Multiply(double Value)
287{
288 x *= Value;
289 y *= Value;
290 z *= Value;
291 m *= Value;
292}
293
294void CSG_Point_4D::Divide(double Value)
295{
296 x /= Value;
297 y /= Value;
298 z /= Value;
299 m /= Value;
300}
301
302//---------------------------------------------------------
303double CSG_Point_4D::Get_Length(void) const
304{
305 return( sqrt(x*x + y*y + z*z + m*m) );
306}
307
308
310// //
311// //
312// //
314
315//---------------------------------------------------------
317{
318 m_Points.Create(sizeof(TSG_Point), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_1);
319}
320
322{
323 m_Points.Create(sizeof(TSG_Point), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_1);
324
325 Assign(Points);
326}
327
329{
330 m_Points.Create(sizeof(TSG_Point), nPoints, Growth);
331}
332
333//---------------------------------------------------------
335{
336 if( m_Points.Set_Array(Points.m_Points.Get_Size()) )
337 {
338 if( m_Points.Get_Size() > 0 )
339 {
340 memcpy(m_Points.Get_Array(), Points.m_Points.Get_Array(), m_Points.Get_Size() * m_Points.Get_Value_Size());
341 }
342
343 return( true );
344 }
345
346 return( false );
347}
348
349//---------------------------------------------------------
350bool CSG_Points::Add(double x, double y)
351{
352 if( m_Points.Inc_Array() )
353 {
354 TSG_Point *Point = (TSG_Point *)m_Points.Get_Entry(m_Points.Get_Size() - 1);
355
356 Point->x = x;
357 Point->y = y;
358
359 return( true );
360 }
361
362 return( false );
363}
364
365
367// //
368// //
369// //
371
372//---------------------------------------------------------
374{
375 m_Lines.Create(0, TSG_Array_Growth::SG_ARRAY_GROWTH_0);
376}
377
379{
380 m_Lines.Create(0, TSG_Array_Growth::SG_ARRAY_GROWTH_0);
381
382 Create(Lines);
383}
384
385bool CSG_Lines::Create(const CSG_Lines &Lines)
386{
387 return( Assign(Lines) );
388}
389
391{
392 m_Lines.Create(0, TSG_Array_Growth::SG_ARRAY_GROWTH_0);
393
394 Create(nLines);
395}
396
398{
399 return( Set_Count(nLines) );
400}
401
402//---------------------------------------------------------
404{
405 Destroy();
406}
407
408//---------------------------------------------------------
410{
411 return( Set_Count(0) );
412}
413
414//---------------------------------------------------------
416{
417 return( Set_Count(0) );
418}
419
420//---------------------------------------------------------
421bool CSG_Lines::Assign(const CSG_Lines &Lines)
422{
423 if( Set_Count(Lines.Get_Count()) )
424 {
425 for(sLong i=0; i<Lines.Get_Count(); i++)
426 {
427 Get_Line(i).Assign(Lines[i]);
428 }
429
430 return( true );
431 }
432
433 return( false );
434}
435
436//---------------------------------------------------------
438{
439 Set_Count(Get_Count() + 1);
440
441 return( Get_Line(Get_Count() - 1) );
442}
443
444//---------------------------------------------------------
445bool CSG_Lines::Add(const CSG_Points &Line)
446{
447 Add().Assign(Line);
448
449 return( true );
450}
451
452//---------------------------------------------------------
453bool CSG_Lines::Add(const CSG_Lines &Lines)
454{
455 for(sLong i=0; i<Lines.Get_Count(); i++)
456 {
457 Add(Lines[i]);
458 }
459
460 return( true );
461}
462
463//---------------------------------------------------------
465{
466 if( Index >= 0 && Index < m_Lines.Get_Size() )
467 {
468 delete((CSG_Points *)m_Lines[Index]);
469
470 return( m_Lines.Del(Index) );
471 }
472
473 return( false );
474}
475
476//---------------------------------------------------------
478{
479 if( new_Count < 0 )
480 {
481 new_Count = 0;
482 }
483
484 sLong old_Count = m_Lines.Get_Size();
485
486 if( new_Count > old_Count )
487 {
488 m_Lines.Set_Array(new_Count);
489
490 for(sLong i=old_Count; i<new_Count; i++)
491 {
492 m_Lines[i] = new CSG_Points;
493 }
494 }
495 else if( new_Count < old_Count )
496 {
497 for(sLong i=new_Count; i<old_Count; i++)
498 {
499 delete((CSG_Points *)m_Lines[i]);
500 }
501
502 m_Lines.Set_Array(new_Count);
503 }
504
505 return( true );
506}
507
508double CSG_Lines::Get_Length(void) const
509{
510 double Length = 0.;
511
512 for(sLong i=0; i<Get_Count(); i++)
513 {
514 Length += Get_Length(i);
515 }
516
517 return( Length );
518}
519
520double CSG_Lines::Get_Length(sLong Index) const
521{
522 double Length = 0.;
523
524 if( Index >= 0 && Index < Get_Count() )
525 {
526 const CSG_Points &Line = Get_Line(Index);
527
528 if( Line.Get_Count() > 1 )
529 {
530 for(sLong i=0, j=1; j<Line.Get_Count(); i++, j++)
531 {
532 Length += SG_Get_Distance(Line[i], Line[j]);
533 }
534 }
535 }
536
537 return( Length );
538}
539
540
542// //
543// //
544// //
546
547//---------------------------------------------------------
549{
550 m_Points.Create(sizeof(TSG_Point_3D), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_1);
551}
552
554{
555 m_Points.Create(sizeof(CSG_Points_3D), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_1);
556
557 Assign(Points);
558}
559
561{
562 m_Points.Create(sizeof(TSG_Point_3D), nPoints, Growth);
563}
564
565//---------------------------------------------------------
567{
568 if( m_Points.Set_Array(Points.m_Points.Get_Size()) )
569 {
570 if( m_Points.Get_Size() > 0 )
571 {
572 memcpy(m_Points.Get_Array(), Points.m_Points.Get_Array(), m_Points.Get_Size() * m_Points.Get_Value_Size());
573 }
574
575 return( true );
576 }
577
578 return( false );
579}
580
581//---------------------------------------------------------
582bool CSG_Points_3D::Add(double x, double y, double z)
583{
584 if( m_Points.Inc_Array() )
585 {
586 TSG_Point_3D *Point = (TSG_Point_3D *)m_Points.Get_Entry(m_Points.Get_Size() - 1);
587
588 Point->x = x;
589 Point->y = y;
590 Point->z = z;
591
592 return( true );
593 }
594
595 return( false );
596}
597
598
600// //
601// //
602// //
604
605//---------------------------------------------------------
610
612{
613 m_Points.Create(sizeof(TSG_Point_Int), 0, TSG_Array_Growth::SG_ARRAY_GROWTH_1);
614
615 Assign(Points);
616}
617
619{
620 m_Points.Create(sizeof(TSG_Point_Int), nPoints, Growth);
621}
622
623//---------------------------------------------------------
625{
626 if( m_Points.Set_Array(Points.m_Points.Get_Size()) )
627 {
628 if( m_Points.Get_Size() > 0 )
629 {
630 memcpy(m_Points.Get_Array(), Points.m_Points.Get_Array(), m_Points.Get_Size() * m_Points.Get_Value_Size());
631 }
632
633 return( true );
634 }
635
636 return( false );
637}
638
639//---------------------------------------------------------
640bool CSG_Points_Int::Add(int x, int y)
641{
642 if( m_Points.Inc_Array() )
643 {
644 TSG_Point_Int *Point = (TSG_Point_Int *)m_Points.Get_Entry(m_Points.Get_Size() - 1);
645
646 Point->x = x;
647 Point->y = y;
648
649 return( true );
650 }
651
652 return( false );
653}
654
655
657// //
658// CSG_Rect //
659// //
661
662//---------------------------------------------------------
664{
665 Assign(0., 0., 0., 0.);
666}
667
669{
670 Assign(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax);
671}
672
674{
675 Assign(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax);
676}
677
679{
680 Assign(A.x, A.y, B.x, B.y);
681}
682
683CSG_Rect::CSG_Rect(double xMin, double yMin, double xMax, double yMax)
684{
686}
687
688//---------------------------------------------------------
691
692
694// //
696
697//---------------------------------------------------------
698bool CSG_Rect::Create(double _xMin, double _yMin, double _xMax, double _yMax)
699{
700 xMin = _xMin < _xMax ? _xMin : _xMax;
701 xMax = _xMin < _xMax ? _xMax : _xMin;
702
703 yMin = _yMin < _yMax ? _yMin : _yMax;
704 yMax = _yMin < _yMax ? _yMax : _yMin;
705
706 return( xMin < xMax && yMin < yMax );
707}
708
709//---------------------------------------------------------
711{
712 return( Create(A.x, A.y, B.x, B.y) );
713}
714
715//---------------------------------------------------------
716bool CSG_Rect::Create(const CSG_Rect &Rect)
717{
718 return( Create(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax) );
719}
720
721
723// //
725
726//---------------------------------------------------------
727CSG_Rect & CSG_Rect::Assign(double xMin, double yMin, double xMax, double yMax)
728{
730
731 return( *this );
732}
733
735{
736 Create(A.x, A.y, B.x, B.y);
737
738 return( *this );
739}
740
742{
743 Create(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax);
744
745 return( *this );
746}
747
748//---------------------------------------------------------
750{
751 Assign(x, y, xMax, yMax);
752
753 return( *this );
754}
755
757{
758 Set_BottomLeft(Point.x, Point.y );
759
760 return( *this );
761}
762
763CSG_Rect & CSG_Rect::Set_TopRight(double x, double y)
764{
765 Assign(xMin, yMin, x, y);
766
767 return( *this );
768}
769
771{
772 Set_TopRight(Point.x, Point.y );
773
774 return( *this );
775}
776
777//---------------------------------------------------------
778CSG_Rect & CSG_Rect::Move(double dx, double dy)
779{
780 xMin += dx; yMin += dy;
781 xMax += dx; yMax += dy;
782
783 return( *this );
784}
785
787{
788 return( Move(Point.x, Point.y) );
789}
790
791//---------------------------------------------------------
792CSG_Rect & CSG_Rect::Inflate(double dx, double dy, bool bPercent)
793{
794 if( bPercent )
795 {
796 dx = (Get_XRange() * 0.01 * dx) / 2.;
797 dy = (Get_YRange() * 0.01 * dy) / 2.;
798 }
799
800 Assign(
801 xMin - dx, yMin - dy,
802 xMax + dx, yMax + dy
803 );
804
805 return( *this );
806}
807
808CSG_Rect & CSG_Rect::Inflate(double d, bool bPercent)
809{
810 return( Inflate(d, d, bPercent) );
811}
812
813CSG_Rect & CSG_Rect::Deflate(double dx, double dy, bool bPercent)
814{
815 return( Inflate(-dx, -dy, bPercent) );
816}
817
818CSG_Rect & CSG_Rect::Deflate(double d, bool bPercent)
819{
820 return( Deflate(d, d, bPercent) );
821}
822
823//---------------------------------------------------------
824CSG_Rect & CSG_Rect::Union(double x, double y)
825{
826 if( xMin > x ) { xMin = x; } else if( xMax < x ) { xMax = x; }
827 if( yMin > y ) { yMin = y; } else if( yMax < y ) { yMax = y; }
828
829 return( *this );
830}
831
832//---------------------------------------------------------
834{
835 if( xMin > Point.x ) { xMin = Point.x; } else if( xMax < Point.x ) { xMax = Point.x; }
836 if( yMin > Point.y ) { yMin = Point.y; } else if( yMax < Point.y ) { yMax = Point.y; }
837
838 return( *this );
839}
840
841//---------------------------------------------------------
843{
844 if( xMin > Rect.Get_XMin() ) { xMin = Rect.Get_XMin(); }
845 if( yMin > Rect.Get_YMin() ) { yMin = Rect.Get_YMin(); }
846 if( xMax < Rect.Get_XMax() ) { xMax = Rect.Get_XMax(); }
847 if( yMax < Rect.Get_YMax() ) { yMax = Rect.Get_YMax(); }
848
849 return( *this );
850}
851
852
854// //
856
857//---------------------------------------------------------
858bool CSG_Rect::is_Equal(double xMin, double yMin, double xMax, double yMax, double epsilon) const
859{
860 return( SG_Is_Equal(this->xMin, xMin, epsilon) && SG_Is_Equal(this->yMin, yMin, epsilon)
861 && SG_Is_Equal(this->xMax, xMax, epsilon) && SG_Is_Equal(this->yMax, yMax, epsilon) );
862}
863
864bool CSG_Rect::is_Equal(const CSG_Rect &Rect, double epsilon) const
865{
866 return( is_Equal(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax, epsilon) );
867}
868
869//---------------------------------------------------------
870bool CSG_Rect::Contains(double x, double y) const
871{
872 return( xMin <= x && x <= xMax && yMin <= y && y <= yMax );
873}
874
875bool CSG_Rect::Contains(const CSG_Point &Point) const
876{
877 return( Contains(Point.x, Point.y) );
878}
879
880//---------------------------------------------------------
882{
883 if( xMax < Rect.Get_XMin() || Rect.Get_XMax() < xMin
884 || yMax < Rect.Get_YMin() || Rect.Get_YMax() < yMin )
885 {
886 return( INTERSECTION_None );
887 }
888
889 if( is_Equal(Rect) )
890 {
891 return( INTERSECTION_Identical );
892 }
893
894 if( Contains(Rect.Get_XMin(), Rect.Get_YMin())
895 && Contains(Rect.Get_XMax(), Rect.Get_YMax()) )
896 {
897 return( INTERSECTION_Contains );
898 }
899
900 if( Rect.Contains(Get_XMin(), Get_YMin())
901 && Rect.Contains(Get_XMax(), Get_YMax()) )
902 {
903 return( INTERSECTION_Contained );
904 }
905
906 return( INTERSECTION_Overlaps );
907}
908
909//---------------------------------------------------------
911{
912 switch( Intersects(Rect) )
913 {
914 case INTERSECTION_None: default:
915 return( false );
916
919 break;
920
922 (*this) = Rect;
923 break;
924
926 if( xMin < Rect.Get_XMin() ) { xMin = Rect.Get_XMin(); }
927 if( yMin < Rect.Get_YMin() ) { yMin = Rect.Get_YMin(); }
928 if( xMax > Rect.Get_XMax() ) { xMax = Rect.Get_XMax(); }
929 if( yMax > Rect.Get_YMax() ) { yMax = Rect.Get_YMax(); }
930 break;
931 }
932
933 return( true );
934}
935
936
938// //
940
941//---------------------------------------------------------
943{
944 m_nRects = 0; m_Rects = NULL;
945}
946
947//---------------------------------------------------------
949{
950 m_nRects = 0; m_Rects = NULL;
951
952 Assign(Rects);
953}
954
955//---------------------------------------------------------
957{
958 Clear();
959}
960
961//---------------------------------------------------------
963{
964 if( m_Rects )
965 {
966 for(int i=0; i<m_nRects; i++)
967 {
968 delete(m_Rects[i]);
969 }
970
971 SG_Free(m_Rects);
972 }
973
974 m_nRects = 0;
975 m_Rects = NULL;
976}
977
978//---------------------------------------------------------
979bool CSG_Rects::Assign(const CSG_Rects &Rects)
980{
981 Clear();
982
983 for(int i=0; i<Rects.m_nRects; i++)
984 {
985 Add(*Rects.m_Rects[i]);
986 }
987
988 return( true );
989}
990
991//---------------------------------------------------------
993{
994 Assign(Rects);
995
996 return( *this );
997}
998
999//---------------------------------------------------------
1001{
1002 return( Add(CSG_Rect()) );
1003}
1004
1005//---------------------------------------------------------
1006bool CSG_Rects::Add(double xMin, double yMin, double xMax, double yMax)
1007{
1008 return( Add(CSG_Rect(xMin, yMin, xMax, yMax)) );
1009}
1010
1011//---------------------------------------------------------
1012bool CSG_Rects::Add(const CSG_Rect &Rect)
1013{
1014 m_Rects = (CSG_Rect **)SG_Realloc(m_Rects, ((uLong)m_nRects + 1) * sizeof(CSG_Rect *));
1015 m_Rects[m_nRects] = new CSG_Rect(Rect);
1016 m_nRects++;
1017
1018 return( true );
1019}
1020
1021
1023// //
1024// CSG_Rect_Int //
1025// //
1027
1028//---------------------------------------------------------
1030{
1031 Create(0, 0, 0, 0);
1032}
1033
1035{
1036 Create(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax);
1037}
1038
1040{
1041 Create(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax);
1042}
1043
1045{
1046 Create(A.x, A.y, B.x, B.y);
1047}
1048
1050{
1051 Create(xMin, yMin, xMax, yMax);
1052}
1053
1054//---------------------------------------------------------
1057
1058
1060// //
1062
1063//---------------------------------------------------------
1064bool CSG_Rect_Int::Create(int _xMin, int _yMin, int _xMax, int _yMax)
1065{
1066 xMin = _xMin < _xMax ? _xMin : _xMax;
1067 xMax = _xMin < _xMax ? _xMax : _xMin;
1068
1069 yMin = _yMin < _yMax ? _yMin : _yMax;
1070 yMax = _yMin < _yMax ? _yMax : _yMin;
1071
1072 return( xMin < xMax && yMin < yMax );
1073}
1074
1075//---------------------------------------------------------
1077{
1078 return( Create(A.x, A.y, B.x, B.y) );
1079}
1080
1081//---------------------------------------------------------
1083{
1084 return( Create(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax) );
1085}
1086
1087
1089// //
1091
1092//---------------------------------------------------------
1094{
1095 Create(xMin, yMin, xMax, yMax); return( *this );
1096}
1097
1099{
1100 return( Assign(A.x, A.y, B.x, B.y) );
1101}
1102
1104{
1105 return( Assign(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax) );
1106}
1107
1108//---------------------------------------------------------
1110{
1111 return( Assign(x, y, xMax, yMax) );
1112}
1113
1115{
1116 return( Set_BottomLeft(Point.x, Point.y) );
1117}
1118
1120{
1121 return( Assign(xMin, yMin, x, y) );
1122}
1123
1125{
1126 return( Set_TopRight(Point.x, Point.y ) );
1127}
1128
1129//---------------------------------------------------------
1131{
1132 xMin += dx; yMin += dy;
1133 xMax += dx; yMax += dy;
1134
1135 return( *this );
1136}
1137
1139{
1140 return( Move(Point.x, Point.y) );
1141}
1142
1143//---------------------------------------------------------
1145{
1146 return( Assign(xMin - dx, yMin - dy, xMax + dx, yMax + dy) );
1147}
1148
1150{
1151 return( Inflate(d, d) );
1152}
1153
1155{
1156 return( Inflate(-dx, -dy) );
1157}
1158
1160{
1161 return( Deflate(d, d) );
1162}
1163
1164//---------------------------------------------------------
1166{
1167 if( xMin > x ) { xMin = x; } else if( xMax < x ) { xMax = x; }
1168 if( yMin > y ) { yMin = y; } else if( yMax < y ) { yMax = y; }
1169
1170 return( *this );
1171}
1172
1173//---------------------------------------------------------
1175{
1176 if( xMin > Point.x ) { xMin = Point.x; } else if( xMax < Point.x ) { xMax = Point.x; }
1177 if( yMin > Point.y ) { yMin = Point.y; } else if( yMax < Point.y ) { yMax = Point.y; }
1178
1179 return( *this );
1180}
1181
1182//---------------------------------------------------------
1184{
1185 if( xMin > Rect.Get_XMin() ) { xMin = Rect.Get_XMin(); }
1186 if( yMin > Rect.Get_YMin() ) { yMin = Rect.Get_YMin(); }
1187 if( xMax < Rect.Get_XMax() ) { xMax = Rect.Get_XMax(); }
1188 if( yMax < Rect.Get_YMax() ) { yMax = Rect.Get_YMax(); }
1189
1190 return( *this );
1191}
1192
1193//---------------------------------------------------------
1195{
1196 switch( Intersects(Rect) )
1197 {
1198 case INTERSECTION_None: default:
1199 return( false );
1200
1203 break;
1204
1206 (*this) = Rect;
1207 break;
1208
1210 if( xMin < Rect.Get_XMin() ) { xMin = Rect.Get_XMin(); }
1211 if( yMin < Rect.Get_YMin() ) { yMin = Rect.Get_YMin(); }
1212 if( xMax > Rect.Get_XMax() ) { xMax = Rect.Get_XMax(); }
1213 if( yMax > Rect.Get_YMax() ) { yMax = Rect.Get_YMax(); }
1214 break;
1215 }
1216
1217 return( true );
1218}
1219
1220
1222// //
1224
1225//---------------------------------------------------------
1226bool CSG_Rect_Int::is_Equal(int xMin, int yMin, int xMax, int yMax) const
1227{
1228 return( (this->xMin == xMin) && (this->yMin == yMin)
1229 && (this->xMax == xMax) && (this->yMax == yMax) );
1230}
1231
1233{
1234 return( is_Equal(Rect.xMin, Rect.yMin, Rect.xMax, Rect.yMax) );
1235}
1236
1237//---------------------------------------------------------
1238bool CSG_Rect_Int::Contains(double x, double y) const
1239{
1240 return( xMin <= x && x <= xMax && yMin <= y && y <= yMax );
1241}
1242
1244{
1245 return( Contains(Point.x, Point.y) );
1246}
1247
1248//---------------------------------------------------------
1250{
1251 if( xMax < Rect.Get_XMin() || Rect.Get_XMax() < xMin
1252 || yMax < Rect.Get_YMin() || Rect.Get_YMax() < yMin )
1253 {
1254 return( INTERSECTION_None );
1255 }
1256
1257 if( is_Equal(Rect) )
1258 {
1259 return( INTERSECTION_Identical );
1260 }
1261
1262 if( Contains(Rect.Get_XMin(), Rect.Get_YMin())
1263 && Contains(Rect.Get_XMax(), Rect.Get_YMax()) )
1264 {
1265 return( INTERSECTION_Contains );
1266 }
1267
1268 if( Rect.Contains(Get_XMin(), Get_YMin())
1269 && Rect.Contains(Get_XMax(), Get_YMax()) )
1270 {
1271 return( INTERSECTION_Contained );
1272 }
1273
1274 return( INTERSECTION_Overlaps );
1275}
1276
1277
1279// //
1281
1282//---------------------------------------------------------
1284{
1285 m_nRects = 0;
1286 m_Rects = NULL;
1287}
1288
1289//---------------------------------------------------------
1291{
1292 Clear();
1293}
1294
1295//---------------------------------------------------------
1297{
1298 if( m_Rects )
1299 {
1300 for(int i=0; i<m_nRects; i++)
1301 {
1302 delete(m_Rects[i]);
1303 }
1304
1305 SG_Free(m_Rects);
1306 }
1307
1308 m_nRects = 0;
1309 m_Rects = NULL;
1310}
1311
1312//---------------------------------------------------------
1314{
1315 Clear();
1316
1317 for(int i=0; i<Rects.m_nRects; i++)
1318 {
1319 Add(*Rects.m_Rects[i]);
1320 }
1321
1322 return( true );
1323}
1324
1325//---------------------------------------------------------
1327{
1328 Assign(Rects);
1329
1330 return( *this );
1331}
1332
1333//---------------------------------------------------------
1335{
1336 return( Add(CSG_Rect_Int()) );
1337}
1338
1339//---------------------------------------------------------
1340bool CSG_Rects_Int::Add(int xMin, int yMin, int xMax, int yMax)
1341{
1342 return( Add(CSG_Rect_Int(xMin, yMin, xMax, yMax)) );
1343}
1344
1345//---------------------------------------------------------
1347{
1348 m_Rects = (CSG_Rect_Int **)SG_Realloc(m_Rects, ((uLong)m_nRects + 1) * sizeof(CSG_Rect_Int *));
1349 m_Rects[m_nRects] = new CSG_Rect_Int(Rect);
1350 m_nRects++;
1351
1352 return( true );
1353}
1354
1355
1357// //
1358// //
1359// //
1361
1362//---------------------------------------------------------
1364{
1365 m_Weighting = SG_DISTWGHT_None;
1366
1367 m_IDW_Power = 2.;
1368 m_IDW_bOffset = true;
1369
1370 m_Bandwidth = 1.;
1371}
1372
1373//---------------------------------------------------------
1376
1377//---------------------------------------------------------
1378bool CSG_Distance_Weighting::Create_Parameters(CSG_Parameters &Parameters, const CSG_String &Parent, bool bIDW_Offset)
1379{
1380 if( Add_Parameters(Parameters, Parent, bIDW_Offset) )
1381 {
1382 #define INIT_VALUE(id, val) if( Parameters(id) ) { Parameters(id)->Set_Value(val); Parameters(id)->Set_Default(val); }
1383
1384 INIT_VALUE("DW_WEIGHTING" ,(int)m_Weighting );
1385 INIT_VALUE("DW_IDW_POWER" , m_IDW_Power );
1386 INIT_VALUE("DW_IDW_OFFSET", m_IDW_bOffset);
1387 INIT_VALUE("DW_BANDWIDTH" , m_Bandwidth );
1388
1389 return( true );
1390 }
1391
1392 return( false );
1393}
1394
1395//---------------------------------------------------------
1396bool CSG_Distance_Weighting::Add_Parameters(CSG_Parameters &Parameters, const CSG_String &Parent, bool bIDW_Offset)
1397{
1398 Parameters.Add_Choice(Parent,
1399 "DW_WEIGHTING" , _TL("Weighting Function"),
1400 _TL(""),
1401 CSG_String::Format("%s|%s|%s|%s",
1402 _TL("no distance weighting"),
1403 _TL("inverse distance to a power"),
1404 _TL("exponential"),
1405 _TL("gaussian")
1406 ), 0
1407 );
1408
1409 Parameters.Add_Double("DW_WEIGHTING",
1410 "DW_IDW_POWER" , _TL("Power"),
1411 _TL(""),
1412 2., 0., true
1413 );
1414
1415 if( bIDW_Offset )
1416 {
1417 Parameters.Add_Bool ("DW_WEIGHTING",
1418 "DW_IDW_OFFSET" , _TL("Offset"),
1419 _TL("Calculates weights for distance plus one, avoiding division by zero for zero distances"),
1420 true
1421 );
1422 }
1423
1424 Parameters.Add_Double("DW_WEIGHTING",
1425 "DW_BANDWIDTH" , _TL("Bandwidth"),
1426 _TL("Bandwidth for exponential and Gaussian weighting"),
1427 1., 0., true
1428 );
1429
1430 return( true );
1431}
1432
1433//---------------------------------------------------------
1435{
1436 if( Parameters("DW_WEIGHTING") )
1437 {
1438 int Method = Parameters("DW_WEIGHTING")->asInt();
1439
1440 Parameters.Set_Enabled("DW_IDW_OFFSET", Method == 1);
1441 Parameters.Set_Enabled("DW_IDW_POWER" , Method == 1);
1442 Parameters.Set_Enabled("DW_BANDWIDTH" , Method >= 2);
1443 }
1444
1445 return( true );
1446}
1447
1448//---------------------------------------------------------
1450{
1451 if( Parameters("DW_WEIGHTING") )
1452 {
1453 switch( Parameters("DW_WEIGHTING")->asInt() )
1454 {
1455 case 0: Set_Weighting(SG_DISTWGHT_None ); break;
1456 case 1: Set_Weighting(SG_DISTWGHT_IDW ); break;
1457 case 2: Set_Weighting(SG_DISTWGHT_EXP ); break;
1458 case 3: Set_Weighting(SG_DISTWGHT_GAUSS); break;
1459 }
1460 }
1461
1462 if( Parameters("DW_IDW_OFFSET") )
1463 {
1464 Set_IDW_Offset(Parameters("DW_IDW_OFFSET")->asBool ());
1465 }
1466
1467 if( Parameters("DW_IDW_POWER" ) )
1468 {
1469 Set_IDW_Power (Parameters("DW_IDW_POWER" )->asDouble());
1470 }
1471
1472 if( Parameters("DW_BANDWIDTH" ) )
1473 {
1474 Set_BandWidth (Parameters("DW_BANDWIDTH" )->asDouble());
1475 }
1476
1477 return( true );
1478}
1479
1480
1482// //
1484
1485//---------------------------------------------------------
1487{
1488 m_Weighting = Weighting;
1489
1490 return( true );
1491}
1492
1493//---------------------------------------------------------
1495{
1496 if( Value <= 0. )
1497 {
1498 return( false );
1499 }
1500
1501 m_IDW_Power = Value;
1502
1503 return( true );
1504}
1505
1506//---------------------------------------------------------
1508{
1509 m_IDW_bOffset = bOn;
1510
1511 return( true );
1512}
1513
1514//---------------------------------------------------------
1516{
1517 if( Value <= 0. )
1518 {
1519 return( false );
1520 }
1521
1522 m_Bandwidth = Value;
1523
1524 return( true );
1525}
1526
1527
1529// //
1530// //
1531// //
1533
1534//---------------------------------------------------------
TSG_Array_Growth
Definition api_core.h:291
unsigned long long uLong
Definition api_core.h:159
signed long long sLong
Definition api_core.h:158
SAGA_API_DLL_EXPORT void SG_Free(void *memblock)
SAGA_API_DLL_EXPORT void * SG_Realloc(void *memblock, size_t size)
#define _TL(s)
Definition api_core.h:1568
void * Get_Array(void) const
Definition api_core.h:336
sLong Get_Size(void) const
Definition api_core.h:327
bool Set_Weighting(TSG_Distance_Weighting Weighting)
virtual ~CSG_Distance_Weighting(void)
static bool Add_Parameters(class CSG_Parameters &Parameters, const CSG_String &Parent="", bool bIDW_Offset=false)
bool Set_IDW_Offset(bool bOn=true)
bool Set_BandWidth(double Value)
bool Create_Parameters(class CSG_Parameters &Parameters, const CSG_String &Parent="", bool bIDW_Offset=false)
static bool Enable_Parameters(class CSG_Parameters &Parameters)
bool Set_IDW_Power(double Value)
bool Set_Parameters(class CSG_Parameters &Parameters)
CSG_Points & Get_Line(sLong Index)
Definition geo_tools.h:242
CSG_Lines(void)
CSG_Points & Add(void)
double Get_Length(void) const
sLong Get_Count(void) const
Definition geo_tools.h:240
bool Del(sLong Index)
bool Create(const CSG_Lines &Lines)
bool Destroy(void)
bool Clear(void)
bool Set_Count(sLong nLines)
bool Assign(const CSG_Lines &Lines)
virtual ~CSG_Lines(void)
CSG_Parameter * Add_Choice(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, const CSG_String &Items, int Default=0)
void Set_Enabled(bool bEnabled=true)
CSG_Parameter * Add_Double(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, double Value=0.0, double Minimum=0.0, bool bMinimum=false, double Maximum=0.0, bool bMaximum=false)
CSG_Parameter * Add_Bool(const CSG_String &ParentID, const CSG_String &ID, const CSG_String &Name, const CSG_String &Description, bool Value=false)
virtual void Subtract(const CSG_Point_3D &Point)
virtual void Assign(double x, double y, double z)
virtual void Multiply(const CSG_Point_3D &Point)
virtual void Divide(double Value)
virtual double Get_Length(void) const
virtual void Add(const CSG_Point_3D &Point)
virtual void Subtract(const CSG_Point_4D &Point)
virtual void Assign(double x, double y, double z, double m)
virtual void Multiply(const CSG_Point_4D &Point)
virtual void Add(const CSG_Point_4D &Point)
virtual void Divide(double Value)
virtual double Get_Length(void) const
virtual void Add(const CSG_Point &Point)
CSG_Point(void)
virtual void Divide(double Value)
virtual void Assign(double x, double y)
virtual void Subtract(const CSG_Point &Point)
virtual void Multiply(const CSG_Point &Point)
virtual double Get_Length(void) const
bool Add(double x, double y, double z)
bool Assign(const CSG_Points_3D &Points)
bool Add(int x, int y)
bool Assign(const CSG_Points_Int &Points)
bool Assign(const CSG_Points &Points)
bool Add(double x, double y)
sLong Get_Count(void) const
Definition geo_tools.h:201
bool is_Equal(int xMin, int yMin, int xMax, int yMax) const
int Get_YMin(void) const
Definition geo_tools.h:624
CSG_Rect_Int & Set_BottomLeft(int x, int y)
CSG_Rect_Int & Union(int x, int y)
CSG_Rect_Int & Deflate(int d)
TSG_Intersection Intersects(const CSG_Rect_Int &Rect) const
CSG_Rect_Int & Move(int dx, int dy)
int Get_YMax(void) const
Definition geo_tools.h:625
CSG_Rect_Int & Set_TopRight(int x, int y)
int Get_XMax(void) const
Definition geo_tools.h:623
bool Contains(double x, double y) const
CSG_Rect_Int & Assign(int xMin, int yMin, int xMax, int yMax)
bool Intersect(const CSG_Rect_Int &Rect)
int Get_XMin(void) const
Definition geo_tools.h:622
CSG_Rect_Int & Inflate(int d)
bool Create(int xMin, int yMin, int xMax, int yMax)
bool Create(double xMin, double yMin, double xMax, double yMax)
bool is_Equal(double xMin, double yMin, double xMax, double yMax, double epsilon=0.) const
bool Intersect(const CSG_Rect &Rect)
double Get_YRange(void) const
Definition geo_tools.h:511
CSG_Rect & Union(double x, double y)
CSG_Rect & Set_TopRight(double x, double y)
CSG_Rect(void)
CSG_Rect & Inflate(double d, bool bPercent=true)
CSG_Rect & Set_BottomLeft(double x, double y)
CSG_Rect & Deflate(double d, bool bPercent=true)
CSG_Rect & Move(double dx, double dy)
bool Contains(double x, double y) const
double Get_XMax(void) const
Definition geo_tools.h:506
double Get_XRange(void) const
Definition geo_tools.h:510
double Get_XMin(void) const
Definition geo_tools.h:505
TSG_Intersection Intersects(const CSG_Rect &Rect) const
double Get_YMin(void) const
Definition geo_tools.h:507
double Get_YMax(void) const
Definition geo_tools.h:508
~CSG_Rect(void)
CSG_Rect & Assign(double xMin, double yMin, double xMax, double yMax)
void Clear(void)
bool Assign(const CSG_Rects_Int &Rects)
virtual ~CSG_Rects_Int(void)
CSG_Rects_Int & operator=(const CSG_Rects_Int &Rects)
virtual ~CSG_Rects(void)
bool Add(void)
CSG_Rects(void)
void Clear(void)
bool Assign(const CSG_Rects &Rects)
CSG_Rects & operator=(const CSG_Rects &Rects)
static CSG_String Format(const char *Format,...)
#define INIT_VALUE(id, val)
#define B
#define A
SAGA_API_DLL_EXPORT double SG_Get_Distance(double ax, double ay, double bx, double by, bool bPolar)
struct SSG_Point TSG_Point
TSG_Distance_Weighting
Definition geo_tools.h:698
@ SG_DISTWGHT_GAUSS
Definition geo_tools.h:702
@ SG_DISTWGHT_None
Definition geo_tools.h:699
@ SG_DISTWGHT_EXP
Definition geo_tools.h:701
@ SG_DISTWGHT_IDW
Definition geo_tools.h:700
struct SSG_Point_3D TSG_Point_3D
SAGA_API_DLL_EXPORT bool SG_Is_Equal(double a, double b, double epsilon=0.)
struct SSG_Point_4D TSG_Point_4D
struct SSG_Rect_Int TSG_Rect_Int
struct SSG_Point_Int TSG_Point_Int
TSG_Intersection
Definition geo_tools.h:101
@ INTERSECTION_Overlaps
Definition geo_tools.h:104
@ INTERSECTION_None
Definition geo_tools.h:102
@ INTERSECTION_Contains
Definition geo_tools.h:106
@ INTERSECTION_Identical
Definition geo_tools.h:103
@ INTERSECTION_Contained
Definition geo_tools.h:105
struct SSG_Rect TSG_Rect
double x
Definition geo_tools.h:129
double y
Definition geo_tools.h:129
double xMin
Definition geo_tools.h:468
double xMax
Definition geo_tools.h:468
double yMin
Definition geo_tools.h:468
double yMax
Definition geo_tools.h:468