Find if a point is within a triangle: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: minor details) |
(→{{header|Wren}}: Now uses new core library method.) |
||
Line 1,997: | Line 1,997: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-math}} |
|||
This is a translation of the ActionScript code for the 'accurate' method in the first referenced article above. |
This is a translation of the ActionScript code for the 'accurate' method in the first referenced article above. |
||
<lang ecmascript> |
<lang ecmascript>var EPS = 0.001 |
||
var EPS = 0.001 |
|||
var EPS_SQUARE = EPS * EPS |
var EPS_SQUARE = EPS * EPS |
||
Line 2,016: | Line 2,013: | ||
var pointInTriangleBoundingBox = Fn.new { |x1, y1, x2, y2, x3, y3, x, y| |
var pointInTriangleBoundingBox = Fn.new { |x1, y1, x2, y2, x3, y3, x, y| |
||
var xMin = |
var xMin = x1.min(x2.min(x3)) - EPS |
||
var xMax = |
var xMax = x1.max(x2.max(x3)) + EPS |
||
var yMin = |
var yMin = y1.min(y2.min(y3)) - EPS |
||
var yMax = |
var yMax = y1.max(y2.max(y3)) + EPS |
||
return !(x < xMin || xMax < x || y < yMin || yMax < y) |
return !(x < xMin || xMax < x || y < yMin || yMax < y) |
||
} |
} |