FWIW, I decided to write my own hit test using dot products for concave polygons. I will need to do something a bit more involved for convex polygons, but I don't need that immediately. I would still be interested to answer to my original question, if anyone knows the answer. Alternatively, a pointer to some discussion of this issue would be most helpful. (I googled for several hours before posting original question - without any good hits.)
--- In [email protected], "Eric Cooper" <[EMAIL PROTECTED]> wrote: > > I am writing a simple geometry editor (i.e., user can create, move and deform > circles and > polygons). I am *not* adding geometric shapes to display list. Instead, I am > managing > them myself. (This may be a bad idea, but doesn't really affect my overall > question.) > > Here is a method that is defined on my Polygon class. I would like to know > why it returns > true when (x, y) is on top of a polygon and shapeFlag is false -- but returns > false when (x, > y) is on top of a polygon and shapeFlag is true. > > override public function containsPoint(x:Number, > y:Number):Boolean > { > var shapeFlag:Boolean = false; > var testShape:Shape = new Shape(); > testShape.graphics.beginFill(0x0000FF, 1.0); > testShape.graphics.lineStyle(1.0, 0x0000FF, 1.0); > this.renderInteractionShape(testShape.graphics); > testShape.graphics.endFill(); > return ((testShape == null) ? false : > testShape.hitTestPoint(x, y, shapeFlag)); > } > > With shapeFlag = false, any points in the polygon's bounding rectangle will > cuse > containsPoint() to return true. I need to deal with non-rectangular shapes > and rotated > rectangles. > > Performance is important, so generating and regenerating bitmaps would be suboptimal. > Then again, if that is part of the solution, then I could cache bitmaps of > unmoved shapes. > > Here's Polygon.renderInteractionShape() for completeness. The MPPoint class > wraps a > point and provides some UI. > > override public function > renderInteractionShape(graphics:Graphics):void > { > var scale:Number = drawing.getScale(); > var pt:MPPoint = _vertices[0]; > graphics.moveTo(pt.x * scale, pt.y * scale); > for (var i:int = 1; i < _numSides; i++) > { > pt = _vertices[i]; > graphics.lineTo(pt.x * scale, pt.y * scale); > } > // close up the polygon. > pt = _vertices[0]; > graphics.lineTo(pt.x * scale, pt.y * scale); > } > > Thanks in advance, > -ec >

