Project file: dropbox.com/s/iwy8ckiozyp604z/Raycast.c3p
Method 1: By Angle
Store angle and position of each corner of each solid object in an array.
Create a blue line from sprite, angled towards stored angle, width (length) of LOS.Range.
Cast ray towards each angle by x=origin+LOS.Range*cos(angle), y=origin+LOS.Range*sin(angle)
Subevent if ray intersected, set line width to LOS.HitDistance, change color to green (truncate the line if it hits a solid).
Result/Issues:
A and D - Rounding errors, line can either collide or not at corners. Expected behavior.
B - Works as expected
C - No collision/ray intersection detected (until trying to exit out the other edge). Can confirm when moving around the origin sprite, if the max range for that particular line terminates within the solid, the line stays blue. So the first corner does not trigger the ray intersected event at all (sometimes). Possible bug?
Method 2: By coordinates
Same as above, except casting the ray at each corner's stored coordinates. Normally I wouldn't do it this way, except by default there is no way to cast a ray by angle/range and I am experimenting anyways.
Result/Issues:
Some lines don't show up at all, some lines work, and some lines shoot all the way through the solid.
For the lines that don't show up, debug shows that the line is spawned, but with width 0 and set to green. So the intersection event fires, but LOS.HitDistance returns 0. No idea what is going on here.
For the lines that shoot through the solid, simply no collision was detected (I draw the lines at full length first, then resize if a collision occurs). Can be reasonable due to rounding errors. Either the ray doesn't completely reach the nearest corner to collided, or same as problem C above.
Further testing reveals that when putting the solids out of LOS range (300), the cast ray action still works. The farthest corner will trigger the intersection event and extend the line as expected, but the nearer 3 corners either don't trigger the intersection event, or they trigger it and LOS.HitDistance is 0.
There were a few issues and I wasn't sure if I was doing anything wrong/behaving as intended, so I figure I'd make a post and ask for input before making a bug report.
Also feature request: cast ray by angle, to LOS range? Not a huge deal and I'm out of suggestion votes. Workaround is simple enough, but "x=origin+LOS.Range*cos(angle), y=origin+LOS.Range*sin(angle)" might not be immediately obvious to some people. Also I don't know if there might be a performance benefit to not using sin and cos to calculate out the coordinates when casting a significant amount of rays.
PS: Thanks for developing this, it was a nice surprise! With canvas, all the tools are finally available to do visualizations for line of sight! redblobgames.com/articles/visibility (Edit: Also really fancy lights and shadows!)