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>import "/math" for Math
<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 = Math.min(x1, Math.min(x2, x3)) - EPS
var xMin = x1.min(x2.min(x3)) - EPS
var xMax = Math.max(x1, Math.max(x2, x3)) + EPS
var xMax = x1.max(x2.max(x3)) + EPS
var yMin = Math.min(y1, Math.min(y2, y3)) - EPS
var yMin = y1.min(y2.min(y3)) - EPS
var yMax = Math.max(y1, Math.max(y2, y3)) + EPS
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)
}
}