Problem with SimplePolygon and inside? function

edited November 2013 in Ruby Scripting
I am trying to make some simple Ruby scripts and don't seem to get how the inside? function of a SimplePolygon work. I have made a simple test script (see futher down) and my problem is that the function returns TRUE for all points. The only points it returns FALSE for are those on the edge of the polygon. As an example, the script below returns true even though the point (20,20) should be outside of the polygon. What am I doing wrong?

Test script used:

module MyMacro

include RBA

# Define a polygon
a = RBA::Point::new(0,0)
b = RBA::Point::new(0,10)
c = RBA::Point::new(10,10)
d = RBA::Point::new(10,0)
myPolygon = RBA::SimplePolygon::new([d,a,b,c])

x0 = 20
y0 = 20
myPoint = RBA::Point::new(x0,y0)

# Test if point is inside polygon
if myPolygon.inside(myPoint)
print "TRUE\n"
else
print "FALSE\n"
end

end

Comments

  • edited November -1

    Hi,

    I'm afraid that is a bug. Thanks for reporting that.

    The problem is that the underlying function returns -1 for outside, 0 for on the polygon and 1 for inside. That does not map well to a boolean return value. -1 becomes true for outside as well.

    By coincidence I have just released 0.23 and that fix did not make it into that release. But I guess there will be a minor release soon and that bug will be fixed.

    Matthias

Sign In or Register to comment.