Skip to content

Commit 2f792c1

Browse files
committed
Fixed some errors, fixed publish script
1 parent 632c700 commit 2f792c1

File tree

7 files changed

+173
-116
lines changed

7 files changed

+173
-116
lines changed

.github/workflows/publish.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: Publish to npm
2+
13
on:
24
push:
35
tags:
@@ -6,15 +8,21 @@ on:
68
jobs:
79
publish:
810
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
914

1015
steps:
11-
- uses: actions/checkout@v1
12-
- uses: actions/setup-node@v1
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
1318
with:
1419
node-version: 20
20+
registry-url: 'https://registry.npmjs.org'
1521
- run: npm ci
22+
- run: npm run lint
23+
- run: npm run typecheck
24+
- run: npm run test:run
1625
- run: npm run build
17-
- run: npm test
18-
- uses: JS-DevTools/npm-publish@v1
19-
with:
20-
token: ${{ secrets.NPM_TOKEN }}
26+
- run: npm publish --provenance --access public
27+
env:
28+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

src/debug_utils.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,46 @@ export function renderPoints(possiblePoints: any[], prop: string): void {
99
possiblePoints.forEach(function (e) {
1010
var point = L.circleMarker([e.point[1], e.point[0]], {
1111
radius: Math.floor(5 + Math.random() * 10),
12-
color: e[prop] ? 'green' : 'gray',
12+
color: e[prop] ? "green" : "gray",
1313
opacity: e[prop] ? 0.5 : 0.1,
14-
weight: 1
14+
weight: 1,
1515
}).addTo(points);
1616
});
17-
};
17+
}
1818

1919
export function renderSweepLine(sweepLine: any[], pos: any, event: any): void {
2020
var map = window.map;
2121
if (!map) return;
22-
if (window.sws) window.sws.forEach(function (p) {
23-
map.removeLayer(p);
24-
});
22+
if (window.sws)
23+
window.sws.forEach(function (p) {
24+
map.removeLayer(p);
25+
});
2526
window.sws = [];
2627
sweepLine.forEach(function (e) {
27-
var poly = L.polyline([
28-
e.key.point.slice().reverse(),
29-
e.key.otherEvent.point.slice().reverse()
30-
], {color: 'green'}).addTo(map);
28+
var poly = L.polyline(
29+
[e.key.point.slice().reverse(), e.key.otherEvent.point.slice().reverse()],
30+
{ color: "green" }
31+
).addTo(map);
3132
window.sws.push(poly);
3233
});
3334

3435
if (window.vt) map.removeLayer(window.vt);
3536
var v = pos.slice();
3637
var b = map.getBounds();
37-
window.vt = L.polyline([
38-
[b.getNorth(), v[0]],
39-
[b.getSouth(), v[0]]
40-
], {color: 'green', weight: 1}).addTo(map);
38+
window.vt = L.polyline(
39+
[
40+
[b.getNorth(), v[0]],
41+
[b.getSouth(), v[0]],
42+
],
43+
{ color: "green", weight: 1 }
44+
).addTo(map);
4145

4246
if (window.ps) map.removeLayer(window.ps);
43-
window.ps = L.polyline([
44-
event.point.slice().reverse(),
45-
event.otherEvent.point.slice().reverse()
46-
], {color: 'black', weight: 9, opacity: 0.4}).addTo(map);
47+
window.ps = L.polyline(
48+
[event.point.slice().reverse(), event.otherEvent.point.slice().reverse()],
49+
{ color: "black", weight: 9, opacity: 0.4 }
50+
).addTo(map);
4751
debugger;
48-
};
52+
}
4953

5054
/* eslint-enable */

test/compare_events.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { describe, it, expect } from "vitest";
22
import Queue from "tinyqueue";
33
import sweepEventsComp from "../src/compare_events";
44
import SweepEvent from "../src/sweep_event";
5+
import { S } from "vitest/dist/reporters-w_64AS5f.js";
56

67
describe("queue", () => {
78
it("should process least(by x) sweep event first", () => {
89
const queue = new Queue(undefined, sweepEventsComp);
9-
const e1 = { point: [0.0, 0.0] };
10-
const e2 = { point: [0.5, 0.5] };
10+
const e1 = { point: [0.0, 0.0] } as SweepEvent;
11+
const e2 = { point: [0.5, 0.5] } as SweepEvent;
1112

1213
queue.push(e1);
1314
queue.push(e2);
@@ -18,8 +19,8 @@ describe("queue", () => {
1819

1920
it("should process least(by y) sweep event first", () => {
2021
const queue = new Queue(undefined, sweepEventsComp);
21-
const e1 = { point: [0.0, 0.0] };
22-
const e2 = { point: [0.0, 0.5] };
22+
const e1 = { point: [0.0, 0.0] } as SweepEvent;
23+
const e2 = { point: [0.0, 0.5] } as SweepEvent;
2324

2425
queue.push(e1);
2526
queue.push(e2);
@@ -30,8 +31,8 @@ describe("queue", () => {
3031

3132
it("should pop least(by left prop) sweep event first", () => {
3233
const queue = new Queue(undefined, sweepEventsComp);
33-
const e1 = { point: [0.0, 0.0], left: true };
34-
const e2 = { point: [0.0, 0.0], left: false };
34+
const e1 = { point: [0.0, 0.0], left: true } as SweepEvent;
35+
const e2 = { point: [0.0, 0.0], left: false } as SweepEvent;
3536

3637
queue.push(e1);
3738
queue.push(e2);
@@ -43,8 +44,8 @@ describe("queue", () => {
4344

4445
describe("sweep event comparison x coordinates", () => {
4546
it("should compare x coordinates correctly", () => {
46-
const e1 = { point: [0.0, 0.0] };
47-
const e2 = { point: [0.5, 0.5] };
47+
const e1 = { point: [0.0, 0.0] } as SweepEvent;
48+
const e2 = { point: [0.5, 0.5] } as SweepEvent;
4849

4950
expect(sweepEventsComp(e1, e2)).toBe(-1);
5051
expect(sweepEventsComp(e2, e1)).toBe(1);
@@ -53,8 +54,8 @@ describe("sweep event comparison x coordinates", () => {
5354

5455
describe("sweep event comparison y coordinates", () => {
5556
it("should compare y coordinates correctly", () => {
56-
const e1 = { point: [0.0, 0.0] };
57-
const e2 = { point: [0.0, 0.5] };
57+
const e1 = { point: [0.0, 0.0] } as SweepEvent;
58+
const e2 = { point: [0.0, 0.5] } as SweepEvent;
5859

5960
expect(sweepEventsComp(e1, e2)).toBe(-1);
6061
expect(sweepEventsComp(e2, e1)).toBe(1);
@@ -63,8 +64,8 @@ describe("sweep event comparison y coordinates", () => {
6364

6465
describe("sweep event comparison not left first", () => {
6566
it("should process not left events first", () => {
66-
const e1 = { point: [0.0, 0.0], left: true };
67-
const e2 = { point: [0.0, 0.0], left: false };
67+
const e1 = { point: [0.0, 0.0], left: true } as SweepEvent;
68+
const e2 = { point: [0.0, 0.0], left: false } as SweepEvent;
6869

6970
expect(sweepEventsComp(e1, e2)).toBe(1);
7071
expect(sweepEventsComp(e2, e1)).toBe(-1);

test/compare_segments.test.ts

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
2-
import { describe, it, expect } from 'vitest';
3-
import Tree from 'splaytree';
4-
import compareSegments from '../src/compare_segments';
5-
import compareEvents from '../src/compare_events';
6-
import SweepEvent from '../src/sweep_event';
7-
8-
describe('compare segments', () => {
9-
10-
describe('not collinear', () => {
11-
12-
it('should order by shared left point - right point first', () => {
1+
import { describe, it, expect } from "vitest";
2+
import Tree from "splaytree";
3+
import compareSegments from "../src/compare_segments";
4+
import compareEvents from "../src/compare_events";
5+
import SweepEvent from "../src/sweep_event";
6+
import { Position } from "../src/types";
7+
8+
describe("compare segments", () => {
9+
describe("not collinear", () => {
10+
it("should order by shared left point - right point first", () => {
1311
const tree = new Tree(compareSegments);
14-
const pt = [0.0, 0.0];
12+
const pt: Position = [0.0, 0.0];
1513
const se1 = new SweepEvent(pt, true, new SweepEvent([1, 1], false));
1614
const se2 = new SweepEvent(pt, true, new SweepEvent([2, 3], false));
1715

@@ -22,7 +20,7 @@ describe('compare segments', () => {
2220
expect(tree.minNode().key.otherEvent.point).toEqual([1, 1]);
2321
});
2422

25-
it('should sort by different left point - right point y coord', () => {
23+
it("should sort by different left point - right point y coord", () => {
2624
const tree = new Tree(compareSegments);
2725
const se1 = new SweepEvent([0, 1], true, new SweepEvent([1, 1], false));
2826
const se2 = new SweepEvent([0, 2], true, new SweepEvent([2, 3], false));
@@ -34,8 +32,8 @@ describe('compare segments', () => {
3432
expect(tree.maxNode().key.otherEvent.point).toEqual([2, 3]);
3533
});
3634

37-
it('should maintain events order in sweep line', () => {
38-
const se1 = new SweepEvent([0, 1], true, new SweepEvent([2, 1], false));
35+
it("should maintain events order in sweep line", () => {
36+
const se1 = new SweepEvent([0, 1], true, new SweepEvent([2, 1], false));
3937
const se2 = new SweepEvent([-1, 0], true, new SweepEvent([2, 3], false));
4038

4139
const se3 = new SweepEvent([0, 1], true, new SweepEvent([3, 4], false));
@@ -52,25 +50,35 @@ describe('compare segments', () => {
5250
expect(se4.isAbove(se3.point)).toBeFalsy();
5351
});
5452

55-
it('should handle when first point is below', () => {
56-
const se2 = new SweepEvent([0, 1], true, new SweepEvent([2, 1], false));
53+
it("should handle when first point is below", () => {
54+
const se2 = new SweepEvent([0, 1], true, new SweepEvent([2, 1], false));
5755
const se1 = new SweepEvent([-1, 0], true, new SweepEvent([2, 3], false));
5856

5957
expect(se1.isBelow(se2.point)).toBeFalsy();
6058
expect(compareSegments(se1, se2)).toBe(1);
6159
});
6260
});
6361

64-
it('should handle collinear segments', () => {
65-
const se1 = new SweepEvent([1, 1], true, new SweepEvent([5, 1], false), true);
66-
const se2 = new SweepEvent([2, 1], true, new SweepEvent([3, 1], false), false);
62+
it("should handle collinear segments", () => {
63+
const se1 = new SweepEvent(
64+
[1, 1],
65+
true,
66+
new SweepEvent([5, 1], false),
67+
true
68+
);
69+
const se2 = new SweepEvent(
70+
[2, 1],
71+
true,
72+
new SweepEvent([3, 1], false),
73+
false
74+
);
6775

6876
expect(se1.isSubject).not.toBe(se2.isSubject);
6977
expect(compareSegments(se1, se2)).toBe(-1);
7078
});
7179

72-
it('should handle collinear shared left point', () => {
73-
const pt = [0, 1];
80+
it("should handle collinear shared left point", () => {
81+
const pt = [0, 1] as Position;
7482

7583
const se1 = new SweepEvent(pt, true, new SweepEvent([5, 1], false), false);
7684
const se2 = new SweepEvent(pt, true, new SweepEvent([3, 1], false), false);
@@ -89,13 +97,23 @@ describe('compare segments', () => {
8997
expect(compareSegments(se1, se2)).toBe(1);
9098
});
9199

92-
it('should handle collinear same polygon different left points', () => {
93-
const se1 = new SweepEvent([1, 1], true, new SweepEvent([5, 1], false), true);
94-
const se2 = new SweepEvent([2, 1], true, new SweepEvent([3, 1], false), true);
100+
it("should handle collinear same polygon different left points", () => {
101+
const se1 = new SweepEvent(
102+
[1, 1],
103+
true,
104+
new SweepEvent([5, 1], false),
105+
true
106+
);
107+
const se2 = new SweepEvent(
108+
[2, 1],
109+
true,
110+
new SweepEvent([3, 1], false),
111+
true
112+
);
95113

96114
expect(se1.isSubject).toBe(se2.isSubject);
97115
expect(se1.point).not.toBe(se2.point);
98116
expect(compareSegments(se1, se2)).toBe(-1);
99117
expect(compareSegments(se2, se1)).toBe(1);
100118
});
101-
});
119+
});

test/divide_segment.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import possibleIntersection from "../src/possible_intersection";
1313
import Tree from "splaytree";
1414
import compareSegments from "../src/compare_segments";
1515
import { INTERSECTION } from "../src/operation";
16+
import { Position } from "../src/types";
1617

1718
// GeoJSON Data
1819
const shapes = JSON.parse(
@@ -106,9 +107,9 @@ describe("divide segments", () => {
106107
-Infinity,
107108
];
108109
const q = fillQueue(s, c, bbox, bbox, INTERSECTION);
109-
const p0 = [16, 282];
110-
const p1 = [298, 359];
111-
const p2 = [156, 203.5];
110+
const p0 = [16, 282] as Position;
111+
const p1 = [298, 359] as Position;
112+
const p2 = [156, 203.5] as Position;
112113

113114
const te = new SweepEvent(p0, true, null, true);
114115
const te2 = new SweepEvent(p1, false, te, false);

0 commit comments

Comments
 (0)