warpvas
Version:
This JavaScript library enables fast and efficient image distortion transformations using Canvas 2D.
29 lines (28 loc) • 991 B
TypeScript
/**
* Determines if a point is inside/on a triangle using area comparison method
*
* @param p - Target point coordinates {x: number, y: number}
* @param a - Triangle vertex A coordinates
* @param b - Triangle vertex B coordinates
* @param c - Triangle vertex C coordinates
* @param tolerate - Tolerance for floating-point precision (default: 0.1)
*
* @returns True if point is inside or on triangle edges
*
* @example
* ```typescript
* // Check point in equilateral triangle
* const a = { x: 0, y: 0 };
* const b = { x: 1, y: 0 };
* const c = { x: 0.5, y: 0.866 };
*
* console.log(isTriangleContainsPoint({x: 0.5, y: 0.289}, a, b, c)); // true
* console.log(isTriangleContainsPoint({x: 2, y: 2}, a, b, c)); // false
* ```
*
* @remarks
* - Uses determinant for area calculation
* - Edge points are considered inside
* - Vertex order insensitive
*/
export declare const isTriangleContainsPoint: (p: Coord, a: Coord, b: Coord, c: Coord, tolerate?: number) => boolean;