Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"boolean"
],
"main": "lib/index.js",
"types": "types",
"dependencies": {
"libtess": "^1.2.2"
},
Expand Down Expand Up @@ -45,7 +46,8 @@
"test": "mocha -c",
"build": "gulp build",
"deploy": "gulp deploy",
"docs": "jsdoc --readme README.md -r src -d docs -c jsdoc/jsdoc.conf"
"docs": "jsdoc --readme README.md -r src -d docs -c jsdoc/jsdoc.conf",
"types": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir types"
},
"license": "MIT"
}
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const polygon: typeof p;
export const tesselator: typeof tess;
import * as p from "./polygon";
import * as tess from "./tesselator";
137 changes: 137 additions & 0 deletions types/polygon.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
export function ccw(a: any, b: any, c: any): number;
/**
* Polygon normal (2d / 3d)
*
* @param {Array} pts Points of the polygon
* @param {Boolean} [forceNewell=false] Whether to force Newell's method
*
* @return {Array} Polygon normal or null if the polygon is degenerate
*/
export function normal(pts: any[], forceNewell?: boolean): any[];
/**
* Signed area of a polygon.
* For 3d polygons a signed area can only be computed when the optional
* polygon normal ```n``` is passed in.
* @see http://stackoverflow.com/questions/12642256/python-find-area-of-polygon-from-xyz-coordinates
*
* @param {Array} pts Polygon points
* @param {Array} [n=null] Optional polygon normal, needed to compute the signed area for 3d polygons
*
* @return {Number}
*/
export function area(pts: any[], n?: any[]): number;
/**
* Polygon centroid (2d)
*
* @param {Array} pts
*
* @return {Array}
*/
export function centroid(pts: any[]): any[];
/**
* Tests wether the polygon winding is counter clockwise
*
* @param {Array} pts
* @param {Array} [n=null] Optional polygon normal, needed for 3d polygons
*
* @return {Boolean}
*/
export function is_ccw(pts: any[], n?: any[]): boolean;
/**
* Tests wether the polygon winding is clockwise
*
* @param {Array} pts
* @param {Array} [n=null] Optional polygon normal, needed for 3d polygons
*
* @return {Boolean}
*/
export function is_cw(pts: any[], n?: any[]): boolean;
/**
* Polygon winding (2d only)
*
* @param {Array} pts
* @param {Array} [n=null] Optional polygon normal, needed for 3d polygons
*
* @return {Number}
*/
export function winding(pts: any[], n?: any[]): number;
/**
* Polygon bounds.
* @typedef {Object} PolygonBounds
* @property {Number} xMin
* @property {Number} yMin
* @property {Number} xMax
* @property {Number} yMax
*/
/**
* Polygon bounds
*
* @param {Array} pts
*
* @return {PolygonBounds}
*/
export function bounds(pts: any[]): PolygonBounds;
/**
* Ensures CW winding
*
* @param {Array} pts
* @param {Array} [n=null] Optional polygon normal, needed for 3d polygons
*
* @return {Array}
*/
export function ensure_cw(pts: any[], n?: any[]): any[];
/**
* Ensures CCW winding
*
* @param {Array} pts
* @param {Array} [n=null] Optional polygon normal, needed for 3d polygons
*
* @return {Array}
*/
export function ensure_ccw(pts: any[], n?: any[]): any[];
/**
* Triangulates a polygon
*
* @param {Array} polygon
* @param {Array.<Array>} holes
*
* @return triangles
*/
export function triangulate(polygon: any[], holes: Array<any[]>): any;
/**
* Subtract polygons
*
* @param {Array} polygons
*
* @return {Array}
*/
export function subtract(...polygons: any[]): any[];
/**
* Union of a set of polygons
*
* @param {Array} polygons
*
* @return {Array}
*/
export function union(...polygons: any[]): any[];
/**
* Intersection of a set of polygons
*
* @param {Array} a First polygon
* @param {Array} b Second polygon
*
* @return {Array}
*/
export function intersection(a: any[], b: any[]): any[];
export const WINDING_UNKNOWN: 0;
export const WINDING_CCW: 1;
export const WINDING_CW: 2;
/**
* Polygon bounds.
*/
export type PolygonBounds = {
xMin: number;
yMin: number;
xMax: number;
yMax: number;
};
83 changes: 83 additions & 0 deletions types/tesselator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Runs the tesselator
* @see http://www.glprogramming.com/red/chapter11.html
*
* @param {TesselatorOptions} [options=TesselatorOptions] Options
*
* @returns {Array}
*/
export function run(options?: TesselatorOptions): any[];
export const GL_LINE_LOOP: any;
export const GL_TRIANGLES: any;
export const GL_TRIANGLE_STRIP: any;
export const GL_TRIANGLE_FAN: any;
export const GLU_TESS_WINDING_ODD: any;
export const GLU_TESS_WINDING_NONZERO: any;
export const GLU_TESS_WINDING_POSITIVE: any;
export const GLU_TESS_WINDING_NEGATIVE: any;
export const GLU_TESS_WINDING_ABS_GEQ_TWO: any;
export namespace DEFAULT_OPTIONS {
export const polygons: any[];
export const holes: any[];
export { GLU_TESS_WINDING_POSITIVE as windingRule };
export const boundaryOnly: boolean;
export const normal: any;
export const autoWinding: boolean;
}
export class Tesselator {
constructor(vsize?: number);
_vsize: number;
_current: any[];
_out: any[];
_primitiveType: number;
start(polygons: any, holes: any): void;
run(options?: {
polygons: any[];
holes: any[];
windingRule: any;
boundaryOnly: boolean;
normal: any;
autoWinding: boolean;
}): any[];
_begin(type: any): void;
_end_fan(): void;
_end_strip(): void;
_end(): void;
_vertex(v: any): void;
_edge(): void;
_error(errno: any): void;
_combine(v: any, data: any, w: any): any[];
}
/**
* Tesselator options.
*/
export type TesselatorOptions = {
/**
* Array of polygons
*/
polygons?: any[];
/**
* Array of holes
*/
holes?: any[];
/**
* Vertex size to use
*/
vertexSize?: number;
/**
* Winding rule
*/
windingRule?: number;
/**
* Whether to output boundaries only
*/
boundaryOnly?: boolean;
/**
* Normal
*/
normal?: any[];
/**
* Whether to automatically set the correct winding on polygons
*/
autoWinding?: boolean;
};
64 changes: 64 additions & 0 deletions types/vec.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @module vec
*/
/**
* Cross product
*
* @param {Array} a First vector
* @param {Array} b Second vector
*
* @return {Array}
*/
export function cross(a: any[], b: any[]): any[];
/**
* Length of vector
*
* @param {Array} v Vector
*
* @return {Number}
*/
export function length(v: any[]): number;
/**
* Dot product
*
* @param {Array} a Vector
* @param {Array} b Vector
*
* @return {Number}
*/
export function dot(a: any[], b: any[]): number;
/**
* Normalize a vector
*
* @param {Array} v Vector
*
* @return {Array}
*/
export function normalize(v: any[]): any[];
/**
* Add
*
* @param {Array} a First vector
* @param {Array} b Second vector
*
* @return {Array}
*/
export function add(a: any[], b: any[]): any[];
/**
* Subtract
*
* @param {Array} a First vector
* @param {Array} b Second vector
*
* @return {Array}
*/
export function subtract(a: any[], b: any[]): any[];
/**
* Subtract
*
* @param {Array} a First vector
* @param {Array} b Second vector
*
* @return {Array}
*/
export function sub(a: any[], b: any[]): any[];