Skip to content

Commit 123a741

Browse files
🤖 Merge PR DefinitelyTyped#74654 refactor: update lineclip types and tests for improved clarity and functionality by @SheepFromHeaven
1 parent 6102b6a commit 123a741

3 files changed

Lines changed: 38 additions & 17 deletions

File tree

‎types/lineclip/index.d.ts‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
declare namespace Lineclip {
2-
type Point = [number, number];
3-
type BoundingBox = [number, number, number, number];
4-
type LineClipResult = Point[];
1+
export type Point = [number, number];
2+
export type BoundingBox = [number, number, number, number];
3+
export type LineClipResult = Point[][];
4+
export type PolygonClipResult = Point[];
55

6-
function polyline(points: Point[], bbox: BoundingBox, result?: LineClipResult[]): LineClipResult;
7-
function polygon(points: Point[], bbox: BoundingBox): LineClipResult;
8-
}
9-
10-
declare function Lineclip(
11-
points: Lineclip.Point[],
12-
bbox: Lineclip.BoundingBox,
13-
result?: Lineclip.LineClipResult[],
14-
): Lineclip.LineClipResult;
15-
export = Lineclip;
6+
export function clipPolyline(points: Point[], bbox: BoundingBox, result?: LineClipResult): LineClipResult;
7+
export function clipPolygon(points: Point[], bbox: BoundingBox): PolygonClipResult;

‎types/lineclip/lineclip-tests.ts‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { type BoundingBox, type Point, polyline } from "lineclip";
1+
import {
2+
type BoundingBox,
3+
clipPolygon,
4+
clipPolyline,
5+
type LineClipResult,
6+
type Point,
7+
type PolygonClipResult,
8+
} from "lineclip";
29

310
const line: Point[] = [
411
[-10, 10],
@@ -19,6 +26,23 @@ const line: Point[] = [
1926
[-10, 20],
2027
];
2128

29+
const polygon: Point[] = [
30+
[-10, 10],
31+
[0, 10],
32+
[10, 10],
33+
[10, 5],
34+
[10, -5],
35+
[10, -10],
36+
[20, -10],
37+
[-10, 10],
38+
];
39+
2240
const bbox: BoundingBox = [0, 0, 30, 30];
2341

24-
polyline(line, bbox);
42+
const result: LineClipResult = clipPolyline(line, bbox);
43+
const withOptionalResult: LineClipResult = clipPolyline(line, bbox, [[[0, 1], [2, 3]]]);
44+
45+
const polygonResult: PolygonClipResult = clipPolygon(polygon, bbox);
46+
47+
const onePoint: Point = result[0][0];
48+
const onePolygonPoint: Point = polygonResult[0];

‎types/lineclip/package.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"private": true,
33
"name": "@types/lineclip",
4-
"version": "1.1.9999",
4+
"version": "2.0.9999",
5+
"type": "module",
56
"projects": [
67
"https://github.com/mapbox/lineclip#readme"
78
],
@@ -12,6 +13,10 @@
1213
{
1314
"name": "Sikriti Dakua",
1415
"githubUsername": "devloop01"
16+
},
17+
{
18+
"name": "Marc Emmanuel",
19+
"githubUsername": "SheepFromHeaven"
1520
}
1621
]
1722
}

0 commit comments

Comments
 (0)