Page 1 of 1

intersect with thin line - bug?

Posted: Thu Nov 14, 2013 12:08 am
by dhurtt
I am using the intersect function to calculate when one graphic crosses another and I have noticed that the function returns false if one of the graphics is a line with a lineSize of 1. Setting it to 2 will cause everything to work fine, so I have a workaround, but I was wondering if this is a known issue. So, this is really a two-part question: does anyone know if this is a known issue and does anyone know if there is an online database where I can look up known issues myself. I am using the 6.x community edition, if that makes a difference.

Thanks in advance,

Dale

Re: intersect with thin line - bug?

Posted: Thu Nov 14, 2013 12:33 am
by dunbarx
Hi.

I see a one-pixel line acting just fine when just intersecting a one-pixel graphic. Works as advertised,

Craig Newman

Re: intersect with thin line - bug?

Posted: Thu Nov 14, 2013 12:47 am
by dhurtt
Thanks for that. This caused me to double-check and I find it only occurs if the line is sloped (i.e. neither perfectly horizontal or vertical). Do you see it work in that case?

Thanks again in advance,

Dale

Re: intersect with thin line - bug?

Posted: Thu Nov 14, 2013 1:17 am
by dunbarx
Hmmm.

With a sloped line graphic, you know that the actual extent of that object is the rectangle that encloses it. In other words it is larger than the line itself. The intersect function will use that larger extent.

There were a bunch of threads over the last few years that spoke of ways to detect only the visible line itself, and not its enclosing object. I did this by checking whether points along the line, derived from the equation of that line, corresponded with points on the other graphic. But I seem to recall that much simpler and cleverer solutions were offered by others.

Anyone?

Craig

Re: intersect with thin line - bug?

Posted: Thu Nov 14, 2013 2:26 am
by dhurtt
dunbarx wrote:Hmmm. With a sloped line graphic, you know that the actual extent of that object is the rectangle that encloses it. In other words it is larger than the line itself. The intersect function will use that larger extent.
Ah, sorry. I should have said with the option "opaque pixels". That way it only looks at the actual pixels Then it only uses the actual pixels of the line rather than the entire rectangle.

The more I think about it, the more I think that the line's "alpha" is not 255; maybe it is dithering and therefore semi-translucent? :) :?: I should try using a lower alpha value ...

I do appreciate you taking the time to double-check. I hate making a bug report and being told: "well we have it documented here ..."

Dale

Re: intersect with thin line - bug?

Posted: Thu Nov 14, 2013 3:32 pm
by dhurtt
I continued looking through the documentation and by replacing the threshold parameter from "opaque pixels" to "pixels" the intersect function works. As "opaque pixels" checks those pixels that have an alpha of 255, while "pixels" checks for an alpha of 1-255, this seems to indicate that a line on a slope > 0 uses some dithering algorithm which lowers the pixel's alpha to less than 255 (i.e. a "soft line" instead of a "hard line").

So, for now, I am using that as a workaround. Nonetheless, I have submitted a bug report, Bug 11443. I would post the link, but apparently I do not have the permissions to post links on the forum.

Thanks for the help.

Dale

Re: intersect with thin line - bug?

Posted: Thu Nov 14, 2013 4:59 pm
by dunbarx
Dhurtt.

Interesting observation you had.

I made two freehand lines, about 45° or so, but mirror images of each other so they kind of oppose, and put this in the card script:

Code: Select all

on mouseMove
   set the left of grc 1 to (the left of grc 1) + 1
   if intersect(grc 1, grc 2,205) then put random(999)
end mouseMove
So that one line passes through the other when I move the mouse around. The value in msg changes quickly with an alpha value of around 200, spottily with a value of around 220 or so, and not at all above about 230. A value of 1 would do what you originally intended, I think, which seems to think that the lines are "solid".

Craig

Re: intersect with thin line - bug?

Posted: Thu Nov 14, 2013 6:55 pm
by dhurtt
This is not a bug, as your testing and mine has now shown. It turns out that there is an "antialiased" property, which defaults to true, that causes the line to go "soft", thus lowering its alpha. One I set that property to false, everything worked as expected. So, in the end, it is a feature, not a bug. :D And I learned that graphics have a LOT of properties.

UPDATE: Just received an email from Mark Waddington and he confirmed my suspicions.
Mark Waddington wrote:Hi Dale,

Yes - that would cause what you are seeing. Anti-aliased lines of width 1 pixel
will rarely have fully opaque pixels in them *unless* they are vertical or
horizontal since the area the line covers for each pixel will always be less
than 100% (mapping to an alpha value of < 255).

Warmest Regards,

Mark.