Hi Hiroyuki,
This looks like a worthwhile and useful extension. I have not yet
tried the code (I presume it works as you describe, of course). A
couple comments:
Because this code can be useful to call within a drawing loop, its
important for it to be as efficient as possible. So I would write the
last part like this (code not tested, but you'll see the idea):
if self.ori:
oriRadians = numpy.radians(self.ori)
sinOri = numpy.sin(oriRadians)
cosOri = numpy.cos(oriRadians)
x = x0 * cosOri - y0 * sinOri
y = x0 * sinOri + y0 * cosOri
else:
x, y = x0, y0
To extend your fix to .overlaps(), I think you'll want to do the same
thing conceptually, but transforming a whole vector of points at once.
The above code might work for that (as part of a solution). I put x0 *
cosOri (in that order), hoping that a vector, x0, might work. Then
pass the lists of re-oriented points to polygonsOverlap().
Finally, I like your tests a lot. It would be great if these could be
automated, and added to the test suite. So in addition to having a
param list for units, you could have another list of points, chosen to
cover all the possibilities (outside both shapes, inside one, inside
the other, inside both). Then test whether each shape contains each
point. If any of the points gives the wrong answer, raise an error.
--Jeremy