mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
poly2tri type definitions
This commit is contained in:
92
poly2tri/poly2tri-tests.ts
Normal file
92
poly2tri/poly2tri-tests.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
/// <reference path="../../dist/poly2tri.d.ts" />
|
||||
|
||||
function initializeCDT(): poly2tri.SweepContext {
|
||||
var contour = [
|
||||
new poly2tri.Point(100, 100),
|
||||
new poly2tri.Point(100, 300),
|
||||
new poly2tri.Point(300, 300),
|
||||
new poly2tri.Point(300, 100)
|
||||
];
|
||||
|
||||
var swctx = new poly2tri.SweepContext(contour);
|
||||
return swctx;
|
||||
}
|
||||
|
||||
function addHole() {
|
||||
var swctx = initializeCDT();
|
||||
var hole = [
|
||||
new poly2tri.Point(200, 200),
|
||||
new poly2tri.Point(200, 250),
|
||||
new poly2tri.Point(250, 250)
|
||||
];
|
||||
swctx.addHole(hole);
|
||||
}
|
||||
|
||||
function addHoles() {
|
||||
var swctx = initializeCDT();
|
||||
var hole1 = [
|
||||
new poly2tri.Point(200, 200),
|
||||
new poly2tri.Point(200, 250),
|
||||
new poly2tri.Point(250, 250)
|
||||
];
|
||||
|
||||
var hole2 = [
|
||||
new poly2tri.Point(110, 110),
|
||||
new poly2tri.Point(110, 120),
|
||||
new poly2tri.Point(120, 120)
|
||||
];
|
||||
|
||||
swctx.addHoles([hole1, hole2]);
|
||||
}
|
||||
|
||||
function addPoint() {
|
||||
var swctx = initializeCDT();
|
||||
var point = new poly2tri.Point(150, 150);
|
||||
swctx.addPoint(point);
|
||||
}
|
||||
|
||||
function addPoints() {
|
||||
var swctx = initializeCDT();
|
||||
var point1 = new poly2tri.Point(150, 150);
|
||||
var point2 = new poly2tri.Point(155, 155);
|
||||
swctx.addPoints([point1, point2]);
|
||||
swctx.addPoints([{x: 110, y: 120}]);
|
||||
}
|
||||
|
||||
function triangulate() {
|
||||
var swctx = initializeCDT();
|
||||
swctx.triangulate();
|
||||
var triangles = swctx.getTriangles();
|
||||
|
||||
triangles.forEach(t => {
|
||||
t.getPoints().forEach(p => {
|
||||
console.log(p.x, p.y);
|
||||
});
|
||||
var p1 = t.getPoint(0);
|
||||
var p2 = t.getPoint(1);
|
||||
var p3 = t.getPoint(2);
|
||||
});
|
||||
}
|
||||
|
||||
function chaining() {
|
||||
var swctx = initializeCDT();
|
||||
|
||||
var hole1 = [
|
||||
new poly2tri.Point(200, 200),
|
||||
new poly2tri.Point(200, 250),
|
||||
new poly2tri.Point(250, 250)
|
||||
];
|
||||
|
||||
var hole2 = [
|
||||
new poly2tri.Point(110, 110),
|
||||
new poly2tri.Point(110, 120),
|
||||
new poly2tri.Point(120, 120)
|
||||
];
|
||||
|
||||
var holes = [hole1, hole2];
|
||||
var point1 = new poly2tri.Point(150, 150);
|
||||
var point2 = new poly2tri.Point(155, 155);
|
||||
var points = [point1, point2, { x: 153, y: 153 }];
|
||||
|
||||
var triangles = swctx.addHoles(holes).addPoints(points).triangulate().getTriangles();
|
||||
}
|
||||
113
poly2tri/poly2tri.d.ts
vendored
Normal file
113
poly2tri/poly2tri.d.ts
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
// Type definitions for poly2tri v0.9.10
|
||||
// Project: http://github.com/r3mi/poly2tri.js/
|
||||
// Definitions by: Elemar Junior <https://github.com/elemarjr/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module poly2tri {
|
||||
|
||||
interface IPointLike {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
class Point implements IPointLike {
|
||||
|
||||
x: number;
|
||||
y: number;
|
||||
|
||||
constructor(x: number, y: number);
|
||||
|
||||
toString(): string;
|
||||
|
||||
toJSON(): JSON;
|
||||
|
||||
clone(): Point;
|
||||
|
||||
set_zero(): Point;
|
||||
|
||||
set(x: number, y: number): Point;
|
||||
|
||||
negate(): Point;
|
||||
|
||||
add(n: IPointLike): Point;
|
||||
|
||||
sub(n: IPointLike): Point;
|
||||
|
||||
mul(s: number): Point;
|
||||
|
||||
length(): number;
|
||||
|
||||
normalize(): number;
|
||||
|
||||
equals(p: IPointLike): boolean;
|
||||
|
||||
static negate(p: IPointLike): Point;
|
||||
|
||||
static add(a: IPointLike, b: IPointLike): Point;
|
||||
|
||||
static sub(a: IPointLike, b: IPointLike): Point;
|
||||
|
||||
static mul(s: number, p: IPointLike): Point;
|
||||
|
||||
static cross(a: number, b: number);
|
||||
|
||||
static cross(a: IPointLike, b: number);
|
||||
|
||||
static cross(a: IPointLike, b: IPointLike);
|
||||
|
||||
static cross(a: number, b: IPointLike);
|
||||
|
||||
static toStringBase(p: IPointLike): string;
|
||||
|
||||
static toString(p: IPointLike): string;
|
||||
|
||||
static compare(a: IPointLike, b: IPointLike): number;
|
||||
|
||||
static equals(a: IPointLike, b: IPointLike): boolean;
|
||||
|
||||
static dot(a: IPointLike, b: IPointLike): number;
|
||||
}
|
||||
|
||||
|
||||
class SweepContext {
|
||||
constructor(contour: Array<IPointLike>);
|
||||
|
||||
constructor(contour: Array<IPointLike>, options: JSON);
|
||||
|
||||
addHole(polyline: Array<IPointLike>): SweepContext;
|
||||
|
||||
addHoles(holes: Array<Array<IPointLike>>): SweepContext;
|
||||
|
||||
addPoint(point: IPointLike): SweepContext;
|
||||
|
||||
addPoints(point: Array<IPointLike>): SweepContext;
|
||||
|
||||
triangulate(): SweepContext;
|
||||
|
||||
getBoundingBox(): { min: IPointLike; max: IPointLike; };
|
||||
|
||||
getTriangles(): Array<Triangle>;
|
||||
}
|
||||
|
||||
class Triangle {
|
||||
constructor(a: IPointLike, b: IPointLike, c: IPointLike);
|
||||
|
||||
toString(): string;
|
||||
|
||||
getPoint(index: number): IPointLike;
|
||||
|
||||
getPoints(): Array<IPointLike>;
|
||||
|
||||
containsPoint(point: IPointLike): boolean;
|
||||
|
||||
containsPoints(p1: IPointLike, p2: IPointLike): boolean;
|
||||
|
||||
isInterior(): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user