How can I tell if a line control is drawn on top of another canvas (and get that canvas’ index). In the best of all worlds I would like to have an event fired upon entering the canvas.

Thanks!

Carl

How can I tell if a line control is drawn on top of another canvas (and get that canvas’ index). In the best of all worlds I would like to have an event fired upon entering the canvas.

Thanks!

Carl

any reason you can’t use the MouseEnter and MouseExit events then?

Can the line be diagonal or is it always horizontal/vertical?

What are you doing with the Canvases and lines? It might be easier to use a single canvas instead of several controls.

The line (simulated laser line) is being drawn by code. The canvas instances have 2D graphics of prisms and lenses of various user designated sizes, orientations and geometry.

This all worked in realBasic. Data was stored as a fillColor so by inspecting a pixel color that the laser-line tips’ touched I knew the identity of the canvas index (red); the type of object (prism, lens, or neither) (green); the refractive index of the optic (blue). Now there is no easy way to get the pixel color other than using Jason K’s routine–thank you Jason–but I am getting unreliable data for the .red data. Everything has slowed by a factor of 100 at least.

Maybe making the line a set of realBasic.points, and using realBasic.rect . However, usable code examples are nonexistent.

Why something so basic as color=object.pixel(x,y) is no longer available escapes me.

It would really be nice to recompile old code that worked with older mac OS10 using/RealBasic with XOJO.

I think you need to rethink your process…

the lines / objects you are drawing all have vectors… (x1,y1 - x2,y2) etc…

Don’t spend “time” searching for where things intersect… you have 100,000’s of pixels… but a finite number of lines etc…

Do the math instead. If you have 30 lines (for example), your WORST case to find if Line #1 intersects ANY other line is 29 calculations… there are easy algorithms for line intersections, rectangle overlaps, etc. etc…

But scanning the canvas pixel by pixel is not the right way to go about it…

Have you simply tried to load and run your RealBasic project in Xojo ?

Thanks! Xoxo does not do matrix math?

Carl

Not sure if this function will work for you, but the following returns true if the point x1,y1 is inside the polygon defined by xp(1…np),yp(1…np) where np is the number of points in the polygon.

Function numerical_point_in_polygon(x1 as integer, y1 as integer, xp() as integer, yp() as integer, np as integer) As boolean

// returns true if x1,y1 is inside the polygon

// the polygon is designated by xp(1…np),yp(1…np)

dim i,j,k as integer

dim oddnodes as boolean

oddnodes=false

j=np // starts out at the ending point

k=np

for i=1 to k

if (yp(i)<=y1 and y1<yp(j) ) or (yp(j)<=y1 and y1<yp(i)) then

if (x1<(xp(j)-xp(i))*(y1-yp(i))/(yp(j)-yp(i))+xp(i)) then

oddnodes = not oddnodes

end if

end if

j=i // j=i-1 during subsequent loop

next

return oddnodes

End Function

Forum for Xojo Programming Language and IDE. Copyright © 2024 Xojo, Inc.