Job- to get the closest 20 points to a point outside a radius 80 from the point.
Problem:
I have type pt ( 2D point) and type arrayofpoints.
But the two subs are accepting type arrayofpoints as type pt and treating the arrayofpoints as an array of pt.
Tested 32/64/gen gas64
Code: Select all
#cmdline "-exx"
type pt
as single x,y
end type
type arrayofpoints
as pt a(any)
end type
sub GetClosest(a() as pt,ans() as pt,v as pt,num as long,rad as long)
#define incircle(cx,cy,radius,x,y) (cx-x)*(cx-x) +(cy-y)*(cy-y)<= radius*radius
dim as single r=rad,ctr
do
r+=.5
ctr=0
for n as long=lbound(a) to ubound(a)
if incircle(v.x,v.y,r,a(n).x,a(n).y) and incircle(v.x,v.y,rad,a(n).x,a(n).y)=0 then
ctr+=1
redim preserve ans(1 to ctr)
ans(ctr)=a(n)
end if
next n
loop until ubound(ans)>=num
redim preserve ans(1 to num)
circle(v.x,v.y),rad,rgba(0,200,0,100)
circle(v.x,v.y),5,rgb(255,255,255),,,,f
end sub
sub drawpoints(p() as pt,col as ulong)
for n as long=lbound(p) to ubound(p)
circle (p(n).x,p(n).y),4,col
draw string(p(n).x+3,p(n).y),str(n),rgba(200,200,200,200)
next n
end sub
dim as pt p(1 to 100)
dim as pt v=type(400,300)
redim as arrayofpoints result()
for n as long=1 to ubound(p)
p(n)=type(rnd*800,rnd*600)
next
screen 19,32,,64
getclosest(p(),result(),v,20,80)
for n as long=1 to ubound(p)
pset(p(n).x,p(n).y),rgb(255,255,255)
next
drawpoints(result(),rgba(0,200,0,100))
sleep