/
sgGeometry.pas
4614 lines (3811 loc) · 140 KB
/
sgGeometry.pas
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
//=============================================================================
// sgGeometry.pas
//=============================================================================
//
// Contains code to create points, vectors and matrices and operations for use
// between them (addition, multiplication). This unit is particularly useful
// for the sgPhysics unit with uses such operations for collision testing.
//
// Most of the code in this unit was in sgPhysics prior to version 3. See
// there for possible relevant change notes.
//
// Change History:
//
// Version 3.0:
// - 2011-05-23: Andrew : Removed "Shape" code, placed in sgVectorShapes.
// - 2010-01-13: Aaron : Added PointAdd which adds 2 pointers together.
// Added PointInShape which checks if a Point is in a shape.
// - 2009-12-21: Andrew : Moved Sprite and Bitmap rectangle function to sgSprites and sgImages
// - 2009-12-18: Andrew : Added code to fix rectangles (+ve width and height)
// - 2009-11-10: Andrew : Added tracing and sn and csn tags to code
// - 2009-10-16: Andrew : Added shapes and prototypes. Ensure they are freed
// - 2009-07-29: Andrew : Renamed cos, sin, tan to avoid conflict in c
// - 2009-07-10: Andrew : Fixed missing const modifier on struct types
// - 2009-07-05: Clinton:
// - 2009-07-03: Andrew : Started adding class indicators
// : Started adding operator overloads
// : Added IdentityMatrix and MatrixToString
// : Added overloaded operators to Vector and Matrix2D
// - 2009-07-02: Andrew : Added comments for returning fixed size var length arrays
// : Increased precision of deg to rad
// - 2009-06-29: Andrew : Removed all need for Collision Side
// : Changed to use Circle Type
// : Added new circle working code
// - 2009-06-26: Andrew : Completed ClosestPointOnRectFromCircle
// : Completed
// : Fixed overloads of PointAt
// : Added RectangleCenter
// : RayCircleIntersectDistance heading can now be non-unit vector
// : Add DistantPointOnCircle
// : Added DistantPointOnCircleHeading
// : Added VectorOutOfRectFromCircle
// : Added PointInCircle
// : Added RectangleFrom Triangle
// - 2009-06-24: Andrew : Renamed to sgGeometry and combined with Shapes
// : Moved CenterPoint to sgSprite.
// : VectorFromCenterSpriteToPoint
// : VectorFromTo
// - 2009-06-23: Clinton: Created unit. Moved math routines from physics and
// : shapes units.
//=============================================================================
/// SwinGame's geometry code includes the features to create, draw, and manipulate
/// shapes.
///
/// @module Geometry
/// @static
unit sgGeometry;
//=============================================================================
interface
uses sgTypes;
//=============================================================================
//---------------------------------------------------------------------------
// Circle creation code
//---------------------------------------------------------------------------
/// Creates a Circle at the point pt with the given radius.
///
/// @lib
/// @sn circleAt:%s radius:%s
function CircleAt(const pt: Point2D; radius: Longint): Circle; overload;
/// Creates a circle at the given x,y location with the indicated radius.
///
/// @lib CircleFromXY
/// @sn circleAtX:%s y:%s radius:%s
///
/// @doc_idx 0
function CircleAt(x, y: Single; radius: Longint): Circle; overload;
/// Creates a Circle at the point pt with the given radius.
///
/// @lib
/// @sn createCircle:%s radius:%s
function CreateCircle(const pt: Point2D; radius: Longint): Circle; overload;
/// Creates a circle at the given x,y location with the indicated radius.
///
/// @lib CreateCircleFromXY
/// @sn createCircleX:%s y:%s radius:%s
///
/// @doc_idx 0
function CreateCircle(x, y: Single; radius: Longint): Circle; overload;
//---------------------------------------------------------------------------
// Circle code
//---------------------------------------------------------------------------
/// Return the center point of a circle.
///
/// @lib CircleCenterPoint
function CenterPoint(const c: Circle): Point2D; overload;
/// Returns the X value of the center point of a circle.
///
/// @lib
function CircleX(const c: Circle): Single;
/// Returns the Y value of the center point of a circle.
///
/// @lib
function CircleY(const c: Circle): Single;
/// Returns the radius of the passed in circle.
///
/// @lib
function CircleRadius(const c: Circle): Longint;
/// Returns the point that lies on the circle's radius that is closest to the fromPt.
///
/// @lib
/// @sn closestPointFrom:%s onCircle:%s
///
/// @class Circle
/// @method ClosestPointTo
/// @self 2
function ClosestPointOnCircle(const fromPt: Point2D; const c: Circle): Point2D;
/// Returns the point at the opposite side of a circle from a given point ``pt``.
///
/// @lib
/// @sn distantPointFrom:%s onCircle:%s
///
/// @class Circle
/// @method DistantPointFrom
/// @self 2
/// @csn distantPointFrom:%s
function DistantPointOnCircle(const pt: Point2D; const c: Circle): Point2D;
/// Finds the opposite side of a circle from a given point ``pt`` when travelling along the
/// vector ``heading``. Returns False if the ray projected from point ``pt`` misses the circle.
///
/// @lib
/// @sn distantPointFrom:%s onCircle:%s heading:%s result:%s
///
/// @class Circle
/// @method DistantPointFrom
/// @self 2
/// @csn distantPointFrom:%s heading:%s result:%s
function DistantPointOnCircleHeading(const pt: Point2D; const c: Circle; const heading: Vector; out oppositePt: Point2D): Boolean;
/// Returns the two widest points on the circle that lie along the indicated vector.
///
/// @lib
/// @sn widestPointsOn:%s along:%s firstPt:%s secondPt:%s
///
/// @class Circle
/// @method WidestPoints
/// @csn widestPointsAlong:%s firstPt:%s secondPt:%s
procedure WidestPoints(const c: Circle; const along: Vector; out pt1, pt2: Point2D);
/// Returns the two tangent points on the circle given the indicated vector.
///
/// @lib
/// @sn tangentPointsFrom:%s on:%s firstPt:%s secondPt:%s
///
/// @class Circle
/// @method TangentPoints
/// @self 2
/// @csn tangentPointsFrom:%s firstPt:%s secondPt:%s
function TangentPoints(const fromPt: Point2D; const c: Circle; out p1, p2: Point2D): Boolean;
/// Returns the distance from the ray origin to the edge of the circle where the ray heads in the
/// direction indicated in the ray_heading parameter. This returns -1 where the ray does not hit
/// the circle.
///
/// @lib
/// @sn distanceRayAt:%s heading:%s hitCircle:%s
///
/// @class Point2D
/// @method RayCircleIntersectDistance
/// @self 1
/// @csn distanceRayHeading:%s toCircle:%s
function RayCircleIntersectDistance(const ray_origin: Point2D; const ray_heading:Vector; const c: Circle): Single;
/// Returns true if the circle is completely within the rectangle.
///
/// @lib
/// @sn circle:%s isWithin:%s
function CircleWithinRect(const c: Circle; const rect: Rectangle): Boolean;
//---------------------------------------------------------------------------
// Line code
//---------------------------------------------------------------------------
/// Returns true if the line segment intersects the circle.
///
/// @lib
/// @sn lineSegment:%s intersectsCircle:%s
function LineIntersectsCircle(const l: LineSegment; const c: Circle): Boolean;
//---------------------------------------------------------------------------
// Sprite <-> Rectangle Collision Detection
//---------------------------------------------------------------------------
/// Returns true if the two line segments intersect.
///
/// @lib
/// @sn lineSegment:%s intersectsLinesSegment:%s
function LineSegmentsIntersect(const line1, line2: LineSegment): Boolean;
/// Returns true if the triangle intersects with the rectangle.
///
/// @lib
/// @sn triangle:%s intersectsRectangle:%s
function TriangleRectangleIntersect(const tri: Triangle; const rect: Rectangle): Boolean;
/// Returns true if any of the lines in the array intersect with the Rectangle `r`.
///
/// @lib
/// @sn lines:%s intersectsRectangle:%s
function LinesRectIntersect(const lines: LinesArray; const r: Rectangle): Boolean;
/// Returns true if any of the triangles intersects with the rectangle.
///
/// @lib
/// @sn triangles:%s intersectsRectangle:%s
function TrianglesRectangleIntersect(const tri: TriangleArray; const rect: Rectangle): Boolean;
/// Which of the lines from the array of line segments did the circle collide with given the
/// indicated velocity.
///
/// @lib
/// @sn circle:%s travelling:%s hitLines:%s result:%s
function LineCircleHit(const c: Circle; const velocity: Vector; const lines: LinesArray; out found: LineSegment): Boolean;
/// Returns distance from the line, or if the intersecting point on the line nearest
/// the point tested is outside the endpoints of the line, the distance to the
/// nearest endpoint.
///
/// Returns -1 on zero-valued denominator conditions to return an illegal distance. (
/// modification of Brandon Crosby's VBA code)
///
/// @lib PointLineDistance
/// @sn point:%s distanceTo:%s
function PointLineDistance(const pt: Point2D; const line: LineSegment): Single; overload;
/// Returns the distance from the x,y point to the line segment.
///
/// @lib PointXYLineDistance
/// @sn pointX:%s y:%s distanceTo:%s
///
/// @doc_idx 0
function PointLineDistance(x, y: Single; const line: LineSegment): Single; overload;
/// Returns the closest point on the line from the x,y point.
///
/// @lib ClosestPointOnLineXY
/// @sn pointFromX:%s y:%s closestToLine:%s
///
/// @doc_idx 0
function ClosestPointOnLine(x, y: Single; const line: LineSegment): Point2D; overload;
/// Returns the point on the line that is closest to the indicated point.
///
/// @lib ClosestPointOnLine
/// @sn pointFrom:%s closestToLine:%s
function ClosestPointOnLine(const fromPt: Point2D; const line: LineSegment): Point2D; overload;
/// Returns the point on the rectangle that is closest to the circle.
///
/// @lib
/// @sn circle:%s closestPointOnRect:%s
function ClosestPointOnRectFromCircle(const c: Circle; const rect: Rectangle): Point2D;
/// Returns the point on the lines that is closest in the indicated array from the circle.
///
/// @lib
/// @sn circle:%s closestPointOnLines:%s
function ClosestPointOnLinesFromCircle(const c: Circle; const lines: LinesArray): Point2D;
/// Returns the point on the line that is closest to the circle.
///
/// @lib
/// @sn circle:%s closestPointOnLine:%s
function ClosestPointOnLineFromCircle(const c: Circle; const line: LineSegment): Point2D;
/// Create a Point2D that points at the X,Y location passed in.
///
/// @lib PointAt
/// @sn pointAtX:%s y:%s
///
/// @class Point2D
/// @constructor
/// @csn initAtX:%s y:%s
function PointAt(x, y: Single): Point2D; overload;
/// Create a Point2D that points at the X,Y location passed in.
///
/// @lib RandomScreenPoint
/// @sn randomScreenPoint
///
/// @class Point2D
/// @constructor
/// @csn init
function RandomScreenPoint(): Point2D;
/// Create a Point2D that points at the point from the startPoint at the end of the offset vector.
///
/// @lib PointAtStartWithOffset
/// @sn point:%s offset:%s
function PointAt(const startPoint: Point2D; const offset: Vector): Point2D; overload;
/// Get a text description of the point2D.
///
/// @lib
///
/// @class Point2D
/// @method ToString
/// @csn description
function PointToString(const pt: Point2D): String;
/// Get a text description of the line segment.
///
/// @lib
///
/// @class LineSegment
/// @method ToString
/// @csn description
function LineToString(const ln: LineSegment): String;
/// Get a text description of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @method ToString
/// @csn description
function RectangleToString(const rect:Rectangle): String;
/// Get a text description of the triangle.
///
/// @lib
///
/// @class Triangle
/// @method ToString
/// @csn description
function TriangleToString(const tri: Triangle): String;
/// Returns the center point of the rectangle.
///
/// @lib
function RectangleCenter(const rect: Rectangle): Point2D;
/// Returns an array containing the four lines of the rectangle.
///
/// @lib LinesFromRect
/// @fixed_result_size 4
///
/// @doc_idx 0
function LinesFrom(const rect: Rectangle): LinesArray; overload;
/// Returns an array containing the three lines from the triangle.
///
/// @lib LinesFromTriangle
/// @fixed_result_size 3
function LinesFrom(const tri: Triangle): LinesArray; overload;
/// Returns a line segment from x1,y1 to x2,y2.
///
/// @lib
/// @sn lineFromX1:%s y1:%s toX2:%s y2:%s
///
/// @doc_idx 0
function LineFrom(x1, y1, x2, y2: Single): LineSegment; overload;
/// Returns a line from pt1 to pt2.
///
/// @lib LineFromPointToPoint
/// @sn lineFrom:%s to:%s
function LineFrom(const pt1, pt2: Point2D): LineSegment; overload;
/// Returns a line from a starting point to the point at the end of the
/// mv vector.
///
/// @lib LineFromVectorWithStartPoint
/// @sn lineFrom:%s toOffset:%s
function LineFromVector(const pt: Point2D; const mv: Vector): LineSegment; overload;
/// Returns a line from the x,y starting point to the point at the end of the
/// mv vector.
///
/// @lib LineFromVectorWithStartXY
/// @sn lineFromX:%s y:%s toOffset:%s
function LineFromVector(x, y: Single; const mv: Vector): LineSegment; overload;
/// Returns a line from the origin to the end of the mv vector.
///
/// @lib
///
/// @doc_idx 0
function LineFromVector(const mv: Vector): LineSegment; overload;
/// Returns a line segment from x1,y1 to x2,y2.
///
/// @lib
/// @sn createLineX1:%s y1:%s toX2:%s y2:%s
///
/// @doc_idx 0
function CreateLine(x1, y1, x2, y2: Single): LineSegment; overload;
/// Returns a line from pt1 to pt2.
///
/// @lib CreateLinePointToPoint
/// @sn createLine:%s to:%s
function CreateLine(const pt1, pt2: Point2D): LineSegment; overload;
/// Returns a line from a starting point to the point at the end of the
/// mv vector.
///
/// @lib CreateLineVectorWithStartPoint
/// @sn createLineFrom:%s toOffset:%s
function CreateLineFromVector(const pt: Point2D; const mv: Vector): LineSegment; overload;
/// Returns a line from the x,y starting point to the point at the end of the
/// mv vector.
///
/// @lib CreateLineVectorWithStartXY
/// @sn createLineFromX:%s y:%s toOffset:%s
function CreateLineFromVector(x, y: Single; const mv: Vector): LineSegment; overload;
/// Returns a line from the origin to the end of the mv vector.
///
/// @lib
///
/// @doc_idx 0
function CreateLineFromVector(const mv: Vector): LineSegment; overload;
/// Returns the mid point of the line segment.
///
/// @lib
function LineMidPoint(const line: LineSegment): Point2D;
/// Returns a rectangle from a given x,y location with a given width
/// and height.
///
/// @lib
/// @sn rectangleFromX:%s y:%s width:%s height:%s
///
/// @doc_idx 0
function RectangleFrom(x, y: Single; w, h: Longint): Rectangle; overload;
/// Returns a rectangle with pt1 and pt2 defining the two distant edge points.
///
/// @lib RectangleForPoints
/// @sn rectangleFrom:%s to:%s
function RectangleFrom(const pt1, pt2: Point2D): Rectangle; overload;
/// Returns a rectangle at a given point with a specified width and height.
///
/// @lib RectangleAtPoint
/// @sn rectangleFrom:%s width:%s height:%s
function RectangleFrom(const pt: Point2D; width, height: Longint): Rectangle; overload;
/// Returns a rectangle that encloses the two points on the line segment.
///
/// @lib RectangleFromLine
function RectangleFrom(const line: LineSegment): Rectangle; overload;
/// Returns a rectangle that encloses a circle.
///
/// @lib RectangleFromCircle
function RectangleFrom(const c: Circle): Rectangle; overload;
/// Returns a rectangle that encloses th epoints in a triangle.
///
/// @lib RectangleFromTriangle
function RectangleFrom(const tri: Triangle): Rectangle; overload;
/// Returns a rectangle that encloses the lines in the lines array.
///
/// @lib RectangleFromLines
function RectangleFrom(const lines: LinesArray): Rectangle; overload;
/// Returns a rectangle from a given x,y location with a given width
/// and height.
///
/// @lib
/// @sn createRectangleX:%s y:%s width:%s height:%s
///
/// @doc_idx 0
function CreateRectangle(x, y: Single; w, h: Longint): Rectangle; overload;
/// Returns a rectangle with pt1 and pt2 defining the two distant edge points.
///
/// @lib CreateRectangleForPoints
/// @sn createRectangle:%s to:%s
function CreateRectangle(const pt1, pt2: Point2D): Rectangle; overload;
/// Returns a rectangle at a given point with a specified width and height.
///
/// @lib CreateRectangleAtPoint
/// @sn createRectangle:%s width:%s height:%s
function CreateRectangle(const pt: Point2D; width, height: Longint): Rectangle; overload;
/// Returns a rectangle that encloses the two points on the line segment.
///
/// @lib CreateRectangleLine
function CreateRectangle(const line: LineSegment): Rectangle; overload;
/// Returns a rectangle that encloses a circle.
///
/// @lib CreateRectangleCircle
function CreateRectangle(const c: Circle): Rectangle; overload;
/// Returns a rectangle that encloses th epoints in a triangle.
///
/// @lib CreateRectangleTriangle
function CreateRectangle(const tri: Triangle): Rectangle; overload;
/// Returns a rectangle that encloses the lines in the lines array.
///
/// @lib CreateRectangleLines
function CreateRectangle(const lines: LinesArray): Rectangle; overload;
/// Returns a rectangle that is inset from rect the amount specified.
///
/// @lib
/// @sn insetRectangle:%s pixels:%s
function InsetRectangle(const rect: Rectangle; insetAmount: Longint): Rectangle;
/// Ensures that the passed in rectangle has a positive width and height.
///
/// @lib FixRectangle
procedure FixRectangle(var rect: Rectangle);
/// Ensures that the passed in rectangle has a positive width and height.
///
/// @lib FixRect
/// @sn fixRectangleX:%s y:%s width:%s height:%s
procedure FixRectangle(var x, y: Single; var width, height: Longint);
//---------------------------------------------------------------------------
// Triangle creation code
//---------------------------------------------------------------------------
/// Returns a triangle from the points passed in.
///
/// @lib
/// @sn triangleFromAx:%s ay:%s bx:%s by:%s cx:%s cy:%s
///
/// @doc_idx 0
function TriangleFrom(ax, ay, bx, by, cx, cy: Single): Triangle; overload;
/// Returns a triangle made up of the three points passed in.
///
/// @lib TriangleFromPoints
/// @sn triangleFromPtA:%s ptB:%s ptC:%s
function TriangleFrom(const a, b, c: Point2D): Triangle; overload;
/// Returns a triangle from the points passed in.
///
/// @lib
/// @sn createTriangleAx:%s ay:%s bx:%s by:%s cx:%s cy:%s
///
/// @doc_idx 0
function CreateTriangle(ax, ay, bx, by, cx, cy: Single): Triangle; overload;
/// Returns a triangle made up of the three points passed in.
///
/// @lib CreateTrianglePoints
/// @sn createTrianglePtA:%s ptB:%s ptC:%s
function CreateTriangle(const a, b, c: Point2D): Triangle; overload;
//----------------------------------------------------------------------------
//
//----------------------------------------------------------------------------
/// Returns the barycenter point of the triangle.
///
/// @lib
///
/// @class Triangle
/// @method Barycenter
function TriangleBarycenter(const tri: Triangle): Point2D;
/// Returns the rectangle details after it moved the amount specified within
/// the vector.
///
/// @lib
/// @sn rectangle:%s rectangleAfterMove:%s
///
/// @class Rectangle
/// @method RectangleAfterMove
function RectangleAfterMove(const rect: Rectangle; const mv: Vector): Rectangle;
/// Returns the top (y) value of a rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter Top
function RectangleTop (const rect: Rectangle): Single;
/// Returns the bottom (y) value of a rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter Bottom
function RectangleBottom(const rect: Rectangle): Single;
/// Returns the left (x) value of a rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter Left
function RectangleLeft (const rect: Rectangle): Single;
/// Returns the right (x) value of a rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter Right
function RectangleRight (const rect: Rectangle): Single;
/// Returns the top left corner of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter TopLeft
function RectangleTopLeft(const rect: Rectangle): Point2D;
/// Returns the top right corner of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter TopRight
function RectangleTopRight(const rect: Rectangle): Point2D;
/// Returns the bottom left corner of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter BottomLeft
function RectangleBottomLeft(const rect: Rectangle): Point2D;
/// Returns the bottom right corner of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter BottomRight
function RectangleBottomRight(const rect: Rectangle): Point2D;
/// Returns the center of the top line of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter CenterTop
function RectangleCenterTop(const rect: Rectangle): Point2D;
/// Returns the center of the bottom line of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter CenterBottom
function RectangleCenterBottom(const rect: Rectangle): Point2D;
/// Returns the center of the left line of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter CenterLeft
function RectangleCenterLeft(const rect: Rectangle): Point2D;
/// Returns the center of the right line of the rectangle.
///
/// @lib
///
/// @class Rectangle
/// @getter CenterRight
function RectangleCenterRight(const rect: Rectangle): Point2D;
/// Returns a rectangle that is offset by the vector.
///
/// @lib
/// @sn rectangleOffset:%s by:%s
function RectangleOffset(const rect: Rectangle; const vec: Vector): Rectangle;
/// Returns true if the two rectangles intersect.
///
/// @lib
/// @sn rectangle:%s intersectsRectangle:%s
///
/// @class Rectangle
/// @method Intersects
function RectanglesIntersect(const rect1, rect2: Rectangle): Boolean;
/// Returns the intersection of two rectangles.
///
/// @lib
/// @sn rectangle:%s intersectionWithRectangle:%s
///
/// @class Rectangle
/// @method Intersection
function Intersection(const rect1, rect2: Rectangle): Rectangle;
/// Returns the intersection point of two lines.
///
/// @lib
/// @sn line:%s intersectionWith:%s result:%s
///
/// @class LineSegment
/// @method IntersectionPoint
/// @csn intersectionWith:%s result:%s
function LineIntersectionPoint(const line1, line2: LineSegment; out pt: Point2D) : Boolean;
/// Returns the intersection point of a ray with a line, returning true if the ray intesects with the line.
///
/// @lib
/// @sn rayFrom:%s heading:%s intersectsLine:%s result:%s
///
/// @class LineSegment
/// @self 3
/// @method RayIntersectionPoint
/// @csn rayFrom:%s heading:%s intersectsAt:%s
function RayIntersectionPoint(const fromPt: Point2D; const heading: Vector; const line: LineSegment; out pt: Point2D) : Boolean;
/// Returns true if the line intersect any of the lines in the array.
///
/// @lib
/// @sn lineSegment:%s intersectsLines:%s
///
/// @class LineSegment
/// @method IntersectsLines
function LineIntersectsLines(const line: LineSegment; const lines: LinesArray): Boolean;
/// Returns true if the line intersects the rectangle.
///
/// @lib
/// @sn lineSegment:%s intersectsRectangle:%s
///
/// @class LineSegment
/// @method IntersectsRect
function LineIntersectsRect(const line: LineSegment; const rect: Rectangle): Boolean;
//---------------------------------------------------------------------------
// Point test operations
//---------------------------------------------------------------------------
/// Returns true if the point ``pt`` is in the Triangle ``tri``.
///
/// @lib
/// @sn point:%s inTriangle:%s
///
/// @class Point2D
/// @method InTriangle
function PointInTriangle(const pt: Point2D; const tri: Triangle): Boolean;
/// Returns true if the point is within the rectangle.
///
/// @lib PointInRectXY
/// @sn point:%s inRectX:%s y:%s width:%s height:%s
///
/// @class Point2D
/// @overload InRect InRectPtXYWH
/// @csn inRectX:%s y:%s width:%s height:%s
function PointInRect(const pt: Point2D; x, y, w, h: Single): Boolean; overload;
/// Returns True if point ``pt`` is in the Rectangle ``rect``.
///
/// @lib
/// @sn point:%s inRect:%s
///
/// @class Point2D
/// @method InRect
///
/// @doc_idx 0
function PointInRect(const pt: Point2D; const rect: Rectangle): Boolean; overload;
/// Returns true if the point (ptX, ptY) is within the rectangle.
///
/// @lib PointXYInRectXY
/// @sn pointX:%s ptY:%s inRectX:%s y:%s width:%s height:%s
function PointInRect(ptX, ptY, x, y, w, h: Single): Boolean; overload;
/// Returns true if the x,y point is within the rectangle.
///
/// @lib PointXYInRect
/// @sn pointX:%s ptY:%s inRect:%s
function PointInRect(x, y: Single; const rect: Rectangle): Boolean; overload;
/// Returns True if the point ``pt`` is in the circle.
///
/// @lib
/// @sn point:%s inCircle:%s
///
/// @class Point2D
/// @method InCircle
function PointInCircle(const pt: Point2D; const c: Circle): Boolean;
/// Returns True if the point ``pt`` is in the circle defined by x, y, radius.
///
/// @lib PointInCirclePt
/// @sn point:%s inCircleAtX:%s y:%s withRadius:%s
///
/// @class Point2D
/// @method InCircle
/// @csn inCircleAtX:%s y:%s withRadius:%s
function PointInCircle(const pt: Point2D; x, y, radius: Single): Boolean;
/// Returns True if the point ``ptX``, ``ptY`` is in the circle.
///
/// @lib PointXYInCircle
/// @sn pointX:%s y:%s inCircleX:%s y:%s radius:%s
function PointInCircle(ptX, ptY, cX, cY, radius: Single): Boolean;
/// Returns True if point ``pt`` is on the line segment ``line``.
///
/// @lib PointOnLine
/// @sn point:%s onLine:%s
///
/// @class Point2D
/// @method OnLine
function PointOnLine(const pt: Point2D; const line: LineSegment): Boolean;
/// Returns True if point ``pt`` is on the line segment ``line``.
///
/// @lib PointOnLineXYXY
/// @sn point:%s onLineAtX:%s Y:%s endX:%s endY:%s
///
/// @class Point2D
/// @method OnLine
/// @csn onLineAtX:%s Y:%s endX:%s endY:%s
function PointOnLine(const pt: Point2D; x, y, endX, endY: Single): Boolean;
/// Returns True of `pt1` is at the same point as `pt2`.
///
/// @lib
/// @sn point:%s atSamePointAs:%s
///
/// @class Point2D
/// @method OnPoint
function PointOnPoint(const pt1,pt2: Point2d): Boolean;
//---------------------------------------------------------------------------
// Vector Creation and Operations
//---------------------------------------------------------------------------
/// Returns a new `Vector` using the ``x`` and ``y`` values provided.
///
/// @lib VectorTo(x, y, False)
/// @uname VectorTo
///
/// @sn vectorToX:%s y:%s
function VectorTo(x, y: Single): Vector; overload;
/// Creates a new `Vector` with the ``x`` and ``y`` values provided, and will
/// invert the ``y`` value if the ``invertY`` parameter is True. The inversion
/// of the ``y`` value provides a convienient option for handling screen
/// related vectors.
///
/// @lib
/// @uname VectorToWithInvertY
///
/// @sn vectorToX:%s y:%s invertY:%s
function VectorTo(x, y: Single; invertY: Boolean): Vector; overload;
/// Adds the two parameter vectors (``v1`` and ``v2``) together and returns
/// the result as a new `Vector`.
///
/// @lib
///
/// @sn vector:%s addVector:%s
///
/// @class Vector
/// @method AddVector
/// @csn vectorByAdding:%s
function AddVectors(const v1, v2: Vector): Vector;
{$ifdef FPC}
/// Adds the two vectors together resulting in a new vector.
///
/// @class Vector
/// @calls AddVectors
operator + (const v1, v2: Vector) r : Vector;
{$endif}
/// Subtracts the second vector parameter (``v2``) from the first vector
/// (``v1``) and returns the result as new `Vector`.
///
/// @lib
/// @sn vector:%s subtractVector:%s
///
/// @class Vector
/// @method SubtractVector
function SubtractVectors(const v1, v2: Vector): Vector;
{$ifdef FPC}
/// @class Vector
/// @calls SubtractVectors
operator - (const v1, v2: Vector) r : Vector;
{$endif}
/// Multiplies each component (``x`` and ``y`` values) of the ``v1`` vector
/// by the ``s`` scalar value and returns the result as a new `Vector`.
///
/// @lib
/// @sn vector:%s multipliedBy:%s
///
/// @class Vector
/// @method Multiply
function VectorMultiply(const v: Vector; s: Single): Vector;
{$ifdef FPC}
/// @class Vector
/// @calls VectorMultiply
operator * (const v: Vector; s: Single) r : Vector;
{$endif}
/// Determines if two vectors are equal.
///
/// @lib
/// @sn vector:%s equals:%s
///
/// @class Vector
/// @method EqualsVector
function VectorsEqual(const v1, v2: Vector): Boolean;
{$ifdef FPC}
/// @class Vector
/// @calls VectorsEqual
operator = (const v1, v2: Vector) r : Boolean;
{$endif}
/// Determines if two vectors are not equal.
///
/// @lib
/// @sn vector:%s doesNotEqual:%s
///
/// @class Vector
/// @method DoesNotEqualVector
function VectorsNotEqual(const v1, v2: Vector): Boolean;
{$ifdef BLAH_BLAH_123}
// Never compile this... FPC doesn't allow <> operator
// but this is required by C#, so we need to pretend it exists...
/// @class Vector
/// @calls VectorsNotEqual
operator <> (const v1, v2: Vector) r : Boolean;
{$endif}
/// Calculates the dot product (scalar product) between the two vector
/// parameters rovided (``v1`` and ``v2``). It returns the result as a
/// scalar value.
///
/// If the result is 0.0 it means that the vectors are orthogonal (at right
/// angles to each other). If ``v1`` and ``v2`` are unit vectors (length of
/// 1.0) and the dot product is 1.0, it means that ``v1`` and ``v2`` vectors
/// are parallel.
///
/// @lib
/// @sn vector:%s dotProduct:%s
///
/// @class Vector
/// @method DotProduct
function DotProduct(const v1, v2: Vector): Single;
/// Returns a new `Vector` that is perpendicular ("normal") to the parameter
/// vector ``v`` provided. The concept of a "normal" vector is usually
/// extracted from (or associated with) a line. See `LineNormal`.
///