Ray-casting algorithm: Difference between revisions

Content added Content deleted
(→‎{{header|PicoLisp}}: Added PureBasic)
(→‎{{header|PureBasic}}: Updated code to allow vertices to be expressed in floating points)
Line 1,248: Line 1,248:
=={{header|PureBasic}}==
=={{header|PureBasic}}==
The code below is includes a GUI for drawing a polygon with the mouse that constantly tests whether the mouse is inside or outside the polygon. It displays a message and changes the windows color slightly to indicate if the pointer is inside or outside the polygon being drawn. The routine that does the checking is called inpoly() and it returns a value of one if the point is with the polygon and zero if it isn't.
The code below is includes a GUI for drawing a polygon with the mouse that constantly tests whether the mouse is inside or outside the polygon. It displays a message and changes the windows color slightly to indicate if the pointer is inside or outside the polygon being drawn. The routine that does the checking is called inpoly() and it returns a value of one if the point is with the polygon and zero if it isn't.
<lang PureBasic>Procedure inpoly(*p.POINT, List poly.POINT())
<lang PureBasic>Structure point_f
x.f
Protected new.POINT, old.POINT, lp.POINT, rp.POINT, i, inside, *poly
y.f
EndStructure
Procedure inpoly(*p.point_f, List poly.point_f())
Protected.point_f new, old, lp, rp
Protected inside
If ListSize(poly()) < 3: ProcedureReturn 0: EndIf
If ListSize(poly()) < 3: ProcedureReturn 0: EndIf
LastElement(poly()): old = poly()
LastElement(poly()): old = poly()
Line 1,279: Line 1,284:
EndIf
EndIf


NewList v.POINT()
NewList v.point_f()
Define.POINT pvp, mp
Define.point_f pvp, mp
Define Col, EventID, mode.b, modetxt.s
Define Col, EventID, mode.b, modetxt.s
Repeat
Repeat