Skip to content

Commit

Permalink
Fix bitmapData.hitTest against another BitmapData point
Browse files Browse the repository at this point in the history
  • Loading branch information
jgranick committed Jun 8, 2018
1 parent 76f6adb commit 64b00f0
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions src/openfl/display/BitmapData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1264,43 +1264,66 @@ class BitmapData implements IBitmapDrawable {

} else {

x = Std.int (secondBitmapDataPoint.x - firstPoint.x);
y = Std.int (secondBitmapDataPoint.y - firstPoint.y);
x = Math.round (secondBitmapDataPoint.x - firstPoint.x);
y = Math.round (secondBitmapDataPoint.y - firstPoint.y);

}

if (rect.contains (x, y)) {
var hitRect = Rectangle.__pool.get ();
hitRect.setTo (x, y, secondBitmapData.width, secondBitmapData.height);

if (rect.intersects (hitRect)) {

var hitRect = Rectangle.__pool.get ();
hitRect.setTo (x, y, Math.min (secondBitmapData.width, width - x), Math.min (secondBitmapData.height, height - y));
if (x < 0) {

hitRect.x = 0;
hitRect.width = Math.min (secondBitmapData.width + x, width);

} else {

hitRect.width = Math.min (secondBitmapData.width, width - x);

}

if (y < 0) {

hitRect.y = 0;
hitRect.height = Math.min (secondBitmapData.height + y, height);

} else {

hitRect.height = Math.min (secondBitmapData.height, height - y);

}

var pixels = getPixels (hitRect);

hitRect.offset (-x, -y);
hitRect.x = (x < 0) ? -x : 0;
hitRect.y = (y < 0) ? -y : 0;

var testPixels = secondBitmapData.getPixels (hitRect);

var length = Std.int (hitRect.width * hitRect.height);
var pixel, testPixel;

Rectangle.__pool.release (hitRect);

for (i in 0...length) {

pixel = pixels.readUnsignedInt ();
testPixel = testPixels.readUnsignedInt ();

if ((pixel >> 24) & 0xFF > firstAlphaThreshold && (testPixel >> 24) & 0xFF > secondAlphaThreshold) {

Rectangle.__pool.release (hitRect);
return true;

}

}

return false;

}

Rectangle.__pool.release (hitRect);

} else if (Std.is (secondObject, Rectangle)) {

var secondRectangle = Rectangle.__pool.get ();
Expand Down

0 comments on commit 64b00f0

Please sign in to comment.