Jump to content

Find if a point is within a triangle: Difference between revisions

→‎{{header|Wren}}: Now uses new core library method.
m (→‎{{header|Haskell}}: minor details)
(→‎{{header|Wren}}: Now uses new core library method.)
Line 1,997:
 
=={{header|Wren}}==
{{libheader|Wren-math}}
This is a translation of the ActionScript code for the 'accurate' method in the first referenced article above.
<lang ecmascript>importvar "/math"EPS for= Math0.001
 
var EPS = 0.001
var EPS_SQUARE = EPS * EPS
 
Line 2,016 ⟶ 2,013:
 
var pointInTriangleBoundingBox = Fn.new { |x1, y1, x2, y2, x3, y3, x, y|
var xMin = Mathx1.min(x1, Mathx2.min(x2, x3)) - EPS
var xMax = Mathx1.max(x1, Mathx2.max(x2, x3)) + EPS
var yMin = Mathy1.min(y1, Mathy2.min(y2, y3)) - EPS
var yMax = Mathy1.max(y1, Mathy2.max(y2, y3)) + EPS
return !(x < xMin || xMax < x || y < yMin || yMax < y)
}
9,483

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.