{"ScriptPreparationCode":"/* var polygon = [{x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}];\r\n px = Math.random();\r\n py = Math.random();\r\nvar v0x = polygon[1].x-polygon[0].x;\r\nvar v0y = polygon[1].y-polygon[0].y;\r\nvar v1x = polygon[2].x-polygon[0].x;\r\nvar v1y = polygon[2].y-polygon[0].y;\r\n\r\n// if v0 cross v1 is positive, triangle is counter clockwise when viewed from above.\r\nvar normal = v0x*v1y - v1x*v0y;\r\n\r\npoint {x: 47.87142596679951, y: -6.500680708968048}\r\ntriangle\r\n\u0022{\u0022a\u0022:{\u0022x\u0022:-40.49496078491211,\u0022y\u0022:-8.738582611083984},\r\n \u0022b\u0022:{\u0022x\u0022:-41.94913723574891,\u0022y\u0022:-6.313193949870829},\r\n \u0022c\u0022:{\u0022x\u0022:-41.94775545887751,\u0022y\u0022:-6.315498584878696}\r\n*/\r\n1;","TestCases":[{"Name":"winding","Code":" var polygon = [{x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}];\r\n px = Math.random();\r\n py = Math.random();\r\nvar v0x = polygon[1].x-polygon[0].x;\r\nvar v0y = polygon[1].y-polygon[0].y;\r\nvar v1x = polygon[2].x-polygon[0].x;\r\nvar v1y = polygon[2].y-polygon[0].y;\r\n\r\n// if v0 cross v1 is positive, triangle is counter clockwise when viewed from above.\r\nvar normal = v0x*v1y - v1x*v0y;\r\n\r\nvar length = polygon.length;\r\n\r\n var windingNumber = 0;\r\n\r\n var i = 0;\r\n var l = polygon.length - 1;\r\n var edgePoint1 = polygon[l];\r\n var edgePoint2;\r\n for (; i \u003C= l; i\u002B\u002B) {\r\n edgePoint2 = polygon[i];\r\n\r\n var edgePoint1x = edgePoint1.x;\r\n var edgePoint1y = edgePoint1.y;\r\n var edgePoint2x = edgePoint2.x;\r\n var edgePoint2y = edgePoint2.y;\r\n\r\n // if it passes the point going upward\r\n if ( edgePoint1y \u003C= py \u0026\u0026 edgePoint2y \u003E py) {\r\n\r\n // and the point is to the left\r\n // EQUATION COPIED FROM GeometryUtils.isLeft for performance reasons\r\n if ((edgePoint2x - edgePoint1x) * (py - edgePoint1y) - (px - edgePoint1x) * (edgePoint2y - edgePoint1y) \u003E 0 ) {\r\n // increment windingNumber\r\n windingNumber\u002B\u002B;\r\n }\r\n }\r\n // else if it passes the point going down\r\n else if ( edgePoint1y \u003E py \u0026\u0026 edgePoint2y \u003C= py) {\r\n // and the point is to the right\r\n if ((edgePoint2x - edgePoint1x) * (py - edgePoint1y) - (px - edgePoint1x) * (edgePoint2y - edgePoint1y) \u003C 0) {\r\n // decrement windingNumber\r\n windingNumber--;\r\n }\r\n }\r\n \r\n edgePoint1 = edgePoint2;\r\n }\r\n\r\n // the point is inside the polygon as long as the winding number isn\u0027t zero.\r\n return windingNumber !== 0;","IsDeferred":false},{"Name":"bary","Code":" var polygon = [{x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}];\r\n px = Math.random();\r\n py = Math.random();\r\nvar v0x = polygon[1].x-polygon[0].x;\r\nvar v0y = polygon[1].y-polygon[0].y;\r\nvar v1x = polygon[2].x-polygon[0].x;\r\nvar v1y = polygon[2].y-polygon[0].y;\r\n\r\n// if v0 cross v1 is positive, triangle is counter clockwise when viewed from above.\r\nvar normal = v0x*v1y - v1x*v0y;\r\n\r\nvar a = polygon[0];\r\n var b = polygon[1];\r\n var c = polygon[2];\r\n\r\n // Compute vectors\r\n var v0x = c.x - a.x;\r\n var v0y = c.y - a.y;\r\n var v1x = b.x - a.x;\r\n var v1y = b.y - a.y;\r\n var v2x = px - a.x;\r\n var v2y = py - a.y;\r\n\r\n var dot00 = v0x * v0x \u002B v0y * v0y;\r\n var dot01 = v0x * v1x \u002B v0y * v1y;\r\n var dot02 = v0x * v2x \u002B v0y * v2y;\r\n var dot11 = v1x * v1x \u002B v1y * v1y;\r\n var dot12 = v1x * v2x \u002B v1y * v2y;\r\n\r\n var denom = dot00 * dot11 - dot01 * dot01;\r\n var u = (dot11 * dot02 - dot01 * dot12) / denom;\r\n var v = (dot00 * dot12 - dot01 * dot02) /denom;\r\n\r\n // Check if point is in triangle\r\n return (u \u003E= 0) \u0026\u0026 (v \u003E= 0) \u0026\u0026 (u \u002B v \u003C 1);","IsDeferred":false},{"Name":"bary2","Code":" var polygon = [{x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}];\r\n px = Math.random();\r\n py = Math.random();\r\nvar v0x = polygon[1].x-polygon[0].x;\r\nvar v0y = polygon[1].y-polygon[0].y;\r\nvar v1x = polygon[2].x-polygon[0].x;\r\nvar v1y = polygon[2].y-polygon[0].y;\r\n\r\n// if v0 cross v1 is positive, triangle is counter clockwise when viewed from above.\r\nvar normal = v0x*v1y - v1x*v0y;\r\n\r\n\r\nvar a = polygon[0];\r\n var b = polygon[1];\r\n var c = polygon[2];\r\n \r\n var ax = a.x;\r\n var ay = a.y;\r\n\r\n // Compute vectors\r\n var v0x = c.x - ax;\r\n var v0y = c.y - ay;\r\n var v1x = b.x - ax;\r\n var v1y = b.y - ay;\r\n var v2x = px - ax;\r\n var v2y = py - ay;\r\n\r\n var dot00 = v0x * v0x \u002B v0y * v0y;\r\n var dot01 = v0x * v1x \u002B v0y * v1y;\r\n var dot02 = v0x * v2x \u002B v0y * v2y;\r\n var dot11 = v1x * v1x \u002B v1y * v1y;\r\n var dot12 = v1x * v2x \u002B v1y * v2y;\r\n\r\n var denom = dot00 * dot11 - dot01 * dot01;\r\n var u = (dot11 * dot02 - dot01 * dot12) / denom;\r\n var v = (dot00 * dot12 - dot01 * dot02) /denom;\r\n\r\n // Check if point is in triangle\r\n return (u \u003E= 0) \u0026\u0026 (v \u003E= 0) \u0026\u0026 (u \u002B v \u003C 1) \u0026\u0026 (normal \u003E 0);","IsDeferred":false},{"Name":"half planes","Code":" var polygon = [{x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}];\r\n px = Math.random();\r\n py = Math.random();\r\nvar v0x = polygon[1].x-polygon[0].x;\r\nvar v0y = polygon[1].y-polygon[0].y;\r\nvar v1x = polygon[2].x-polygon[0].x;\r\nvar v1y = polygon[2].y-polygon[0].y;\r\n\r\n// if v0 cross v1 is positive, triangle is counter clockwise when viewed from above.\r\nvar normal = v0x*v1y - v1x*v0y;\r\n\r\nvar ax = polygon[0].x;\r\n var bx = polygon[1].x;\r\n var cx = polygon[2].x;\r\nvar ay = polygon[0].y;\r\n var by = polygon[1].y;\r\n var cy = polygon[2].y;\r\n\r\nvar b1 = (px - bx) * (ay - by) - (ax - bx) * (py - by);\r\n\r\nvar b2 = (px - cx) * (by - cy) - (bx - cx) * (py - cy);\r\n\r\nvar b3 = (px - ax) * (cy - ay) - (cx - ax) * (py - ay);\r\n\r\nreturn (b1==b2) \u0026\u0026 (b2==b3);\r\n","IsDeferred":false},{"Name":"half planes with normal","Code":" var polygon = [{x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}];\r\n px = Math.random();\r\n py = Math.random();\r\nvar v0x = polygon[1].x-polygon[0].x;\r\nvar v0y = polygon[1].y-polygon[0].y;\r\nvar v1x = polygon[2].x-polygon[0].x;\r\nvar v1y = polygon[2].y-polygon[0].y;\r\n\r\n// if v0 cross v1 is positive, triangle is counter clockwise when viewed from above.\r\nvar normal = v0x*v1y - v1x*v0y;\r\n\r\nvar ax = polygon[0].x;\r\nvar bx = polygon[1].x;\r\nvar cx = polygon[2].x;\r\nvar ay = polygon[0].y;\r\nvar by = polygon[1].y;\r\nvar cy = polygon[2].y;\r\n\r\nif (((px - ax) * (by - ay) - (bx - ax) * (py - ay)) \u003E 0 == normal \u003E 0)\r\n return true;\r\nif (((px - bx) * (cy - by) - (cx - bx) * (py - by)) \u003E 0 == normal \u003E 0) {\r\n return true;\r\n}\r\nreturn ((px - cx) * (ay - cy) - (ax - cx) * (py - cy)) \u003E 0 == normal \u003E 0;","IsDeferred":false},{"Name":"half planes with normal and vars","Code":" var polygon = [{x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}, {x:Math.random(), y:Math.random()}];\r\n px = Math.random();\r\n py = Math.random();\r\nvar v0x = polygon[1].x-polygon[0].x;\r\nvar v0y = polygon[1].y-polygon[0].y;\r\nvar v1x = polygon[2].x-polygon[0].x;\r\nvar v1y = polygon[2].y-polygon[0].y;\r\n\r\n// if v0 cross v1 is positive, triangle is counter clockwise when viewed from above.\r\nvar normal = v0x*v1y - v1x*v0y;\r\n\r\nvar a = polygon[0];\r\n var b = polygon[1];\r\n var c = polygon[2];\r\n\r\n\r\nvar ax = a.x;\r\nvar bx = b.x;\r\nvar ay = a.y;\r\nvar by = b.y;\r\n\r\nvar pxax = px-ax;\r\nvar byay = by-ay;\r\nvar bxax = bx-ax;\r\nvar pyay = py-ay;\r\nif ((pxax * byay - bxax * pyay) * normal \u003E 0)\r\n return true;\r\n\r\nvar cx = c.x;\r\nvar cy = c.y;\r\n\r\nvar pxbx = px-bx;\r\nvar cyby = cy-by;\r\nvar cxbx = cx-bx;\r\nvar pyby = py-by;\r\nif ((pxbx * cyby - cxbx * pyby) * normal \u003E 0)\r\n return true;\r\n\r\nvar pxcx = px-cx;\r\nvar aycy = ay-cy;\r\nvar axcx = ax-cx;\r\nvar pycy = py-cy;\r\nreturn ((pxcx * aycy - axcx * pycy) * normal) \u003E 0;","IsDeferred":false}]}