phaser/v3/src/geom/intersects/TriangleToCircle.js
Peter Achberger edb8d39ae1 Fixes #3033
2017-07-18 10:26:43 +02:00

41 lines
780 B
JavaScript

var LineToCircle = require('./LineToCircle');
var Contains = require('../triangle/Contains');
var TriangleToCircle = function (triangle, circle)
{
// First the cheapest ones:
if (
triangle.left > circle.right ||
triangle.right < circle.left ||
triangle.top > circle.bottom ||
triangle.bottom < circle.top)
{
return false;
}
if (Contains(triangle, circle.x, circle.y))
{
return true;
}
if (LineToCircle(triangle.getLineA(), circle))
{
return true;
}
if (LineToCircle(triangle.getLineB(), circle))
{
return true;
}
if (LineToCircle(triangle.getLineC(), circle))
{
return true;
}
return false;
};
module.exports = TriangleToCircle;