protected override DisplayObject HitTest()
{
if (_type != 3)
return base.HitTest();
else
{
Vector2 localPoint = WorldToLocal(HitTestContext.worldPoint, HitTestContext.direction);
if (!_contentRect.Contains(localPoint))
return null;
// Algorithm & implementation thankfully taken from:
// -> http://alienryderflex.com/polygon/
// inspired by Starling
int len = _polygonPoints.Length;
int i;
int j = len - 1;
bool oddNodes = false;
for (i = 0; i < len; ++i)
{
float ix = _polygonPoints[i].x;
float iy = _polygonPoints[i].y;
float jx = _polygonPoints[j].x;
float jy = _polygonPoints[j].y;
if ((iy < localPoint.y && jy >= localPoint.y || jy < localPoint.y && iy >= localPoint.y) && (ix <= localPoint.x || jx <= localPoint.x))
{
if (ix + (localPoint.y - iy) / (jy - iy) * (jx - ix) < localPoint.x)
oddNodes = !oddNodes;
}
j = i;
}
return oddNodes ? this : null;
}
}