(a, b, c, thresholdAngle)
| 29738 | } |
| 29739 | |
| 29740 | function collinear(a, b, c, thresholdAngle) { |
| 29741 | |
| 29742 | if (!thresholdAngle) { |
| 29743 | return areaTriangle(a, b, c) === 0; |
| 29744 | } |
| 29745 | |
| 29746 | if (typeof collinear.tmpPoint1 === 'undefined') { |
| 29747 | collinear.tmpPoint1 = []; |
| 29748 | collinear.tmpPoint2 = []; |
| 29749 | } |
| 29750 | |
| 29751 | var ab = collinear.tmpPoint1, bc = collinear.tmpPoint2; |
| 29752 | ab.x = b.x - a.x; |
| 29753 | ab.y = b.y - a.y; |
| 29754 | bc.x = c.x - b.x; |
| 29755 | bc.y = c.y - b.y; |
| 29756 | |
| 29757 | var dot = ab.x * bc.x + ab.y * bc.y, |
| 29758 | magA = Math.sqrt(ab.x * ab.x + ab.y * ab.y), |
| 29759 | magB = Math.sqrt(bc.x * bc.x + bc.y * bc.y), |
| 29760 | angle = Math.acos(dot / (magA * magB)); |
| 29761 | |
| 29762 | return angle < thresholdAngle; |
| 29763 | } |
| 29764 | |
| 29765 | function areaTriangle(a, b, c) { |
| 29766 | return (((b[0] - a[0]) * (c[1] - a[1])) - ((c[0] - a[0]) * (b[1] - a[1]))); |
no test coverage detected