summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-10-23 17:41:57 +0000
committerIan C <ianc@noddybox.co.uk>2005-10-23 17:41:57 +0000
commit72e37d7e83692074fa9d5ad00b2e7c660f78c060 (patch)
tree8ad596f6b32bbd23b26e6c8bb9cb954836e6a50c
parent508f1229169dd298346dade8357e8db93313740f (diff)
Added IsInside()
-rw-r--r--vectorgfx.mod/vectorgfx.bmx30
1 files changed, 27 insertions, 3 deletions
diff --git a/vectorgfx.mod/vectorgfx.bmx b/vectorgfx.mod/vectorgfx.bmx
index 57df6ee..fbf5064 100644
--- a/vectorgfx.mod/vectorgfx.bmx
+++ b/vectorgfx.mod/vectorgfx.bmx
@@ -325,10 +325,34 @@ Type TVectorGfxObject
End Method
Rem
+ bbdoc: Whether a point is inside the object
+ returns: True if the point lies inside the object. The object is assumed to be a closed polygon for this test.
+ about: @cx, @cy is the point to test.
+ about: Calling it before drawing the object will cause runtime errors.
+ about: This routine is based on code from comp.graphics.algorithms FAQ 2.03
+ EndRem
+ Method IsInside:Int(cx:Int, cy:Int)
+ Local cross:Int=False
+
+ For Local l:TVectorGfxLine=EachIn lines
+ Local x1:Int=x+rotated[l.i1].x
+ Local y1:Int=y+rotated[l.i1].y
+ Local x2:Int=x+rotated[l.i2].x
+ Local y2:Int=y+rotated[l.i2].y
+
+ If ((((y1<=cy) And (cy<y2)) Or ((y2<=cy) And (cy<y1))) And (cx < (x2 - x1) * (cy - y1) / (y2 - y1) + x1))
+ cross=Not cross
+ EndIf
+ Next
+
+ Return cross
+ End Method
+
+ Rem
bbdoc: A line's adjusted co-ordinates.
- returns: The rotated points (in object co-ordinates) of the line.
+ returns: The rotated and scaled points (in object co-ordinates) of the line.
about: @i is the index of the line to return the points for.
- about: Calling it before drawing then will cause runtime errors.
+ about: Calling it before drawing the object will cause runtime errors.
EndRem
Method AdjustedCoords:TVectorGfxPoint[](i:Int)
Local p:TVectorGfxPoint[]=New TVectorGfxPoint[2]
@@ -342,7 +366,7 @@ Type TVectorGfxObject
bbdoc: A line's normal.
returns: The normal of the selected line.
about: @i is the index of the line to return the normal of. This will return the normal due to the rotation of the object after the object is drawn.
- about: Calling it before drawing then will cause runtime errors.
+ about: Calling it before drawing the object will cause runtime errors.
EndRem
Method Normal:TVector(i:Int)
Local l:TVectorGfxLine=lines[i]