From 1d150a0c241f9bb3b25737786ad484cf4fad5d04 Mon Sep 17 00:00:00 2001 From: Alexander Milevski Date: Tue, 19 Jul 2022 00:23:37 +0200 Subject: [PATCH] Main test --- test/index.test.js | 198 --------------------------------------------- test/index.test.ts | 173 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 198 deletions(-) delete mode 100644 test/index.test.js create mode 100644 test/index.test.ts diff --git a/test/index.test.js b/test/index.test.js deleted file mode 100644 index 1d5e11f..0000000 --- a/test/index.test.js +++ /dev/null @@ -1,198 +0,0 @@ -import tap from 'tape'; -import path from 'path'; -import load from 'load-json-file'; -import fillQueue from '../dist/fill_queue'; - -// GeoJSON Data -const data = load.sync( - path.join(__dirname, 'fixtures', 'two_triangles.geojson') -); - -const subject = data.features[0]; -const clipping = data.features[1]; - -tap.test('fill event queue', (main) => { - const s = [subject.geometry.coordinates]; - const c = [clipping.geometry.coordinates]; - - const sbbox = [Infinity, Infinity, -Infinity, -Infinity]; - const cbbox = [Infinity, Infinity, -Infinity, -Infinity]; - const q = fillQueue(s, c, sbbox, cbbox); - let currentPoint; - - main.test('bboxes', (t) => { - t.deepEqual(sbbox, [20, -113.5, 226.5, 74], 'subject bbox'); - t.deepEqual(cbbox, [54.5, -198, 239.5, 33.5], 'clipping bbox'); - t.end(); - }); - - main.test('point 0', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [20, -23.5]); /* s[0][0] */ - t.ok(currentPoint.left, 'is left'); - t.deepEqual( - currentPoint.otherEvent.point, - [226.5, -113.5], - 'other event' - ); /* s[0][2] */ - t.notOk(currentPoint.otherEvent.left, 'other event is right'); - - t.end(); - }); - - main.test('point 1', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [20, -23.5]); /* s[0][0] */ - t.ok(currentPoint.left, 'is left'); - t.deepEqual( - currentPoint.otherEvent.point, - [170, 74], - 'other event' - ); /* s[0][1] */ - t.notOk(currentPoint.otherEvent.left, 'other event is right'); - - t.end(); - }); - - main.test('point 2', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [54.5, -170.5]); /* c[0][0] */ - t.ok(currentPoint.left, 'is left'); - t.deepEqual( - currentPoint.otherEvent.point, - [239.5, -198], - 'other event' - ); /* c[0][2] */ - t.notOk(currentPoint.otherEvent.left, 'other event is right'); - - t.end(); - }); - - main.test('point 3', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [54.5, -170.5]); /* c[0][0] */ - t.ok(currentPoint.left, 'is left'); - t.deepEqual( - currentPoint.otherEvent.point, - [140.5, 33.5], - 'other event' - ); /* c[0][1] */ - t.notOk(currentPoint.otherEvent.left, 'other event is right'); - - t.end(); - }); - - main.test('point 4', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [140.5, 33.5]); /* c[0][0] */ - t.notOk(currentPoint.left, 'is right'); - t.deepEqual( - currentPoint.otherEvent.point, - [54.5, -170.5], - 'other event' - ); /* c[0][1] */ - t.ok(currentPoint.otherEvent.left, 'other event is left'); - - t.end(); - }); - - main.test('point 5', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [140.5, 33.5]); /* c[0][0] */ - t.ok(currentPoint.left, 'is left'); - t.deepEqual( - currentPoint.otherEvent.point, - [239.5, -198], - 'other event' - ); /* c[0][1] */ - t.notOk(currentPoint.otherEvent.left, 'other event is right'); - - t.end(); - }); - - main.test('point 6', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [170, 74]); /* s[0][1] */ - t.notOk(currentPoint.left, 'is right'); - t.deepEqual( - currentPoint.otherEvent.point, - [20, -23.5], - 'other event' - ); /* s[0][0] */ - t.ok(currentPoint.otherEvent.left, 'other event is left'); - - t.end(); - }); - - main.test('point 7', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [170, 74]); /* s[0][1] */ - t.ok(currentPoint.left, 'is left'); - t.deepEqual( - currentPoint.otherEvent.point, - [226.5, -113.5], - 'other event' - ); /* s[0][3] */ - t.notOk(currentPoint.otherEvent.left, 'other event is right'); - - t.end(); - }); - - main.test('point 8', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [226.5, -113.5]); /* s[0][1] */ - t.notOk(currentPoint.left, 'is right'); - t.deepEqual( - currentPoint.otherEvent.point, - [20, -23.5], - 'other event' - ); /* s[0][0] */ - t.ok(currentPoint.otherEvent.left, 'other event is left'); - - t.end(); - }); - - main.test('point 9', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [226.5, -113.5]); /* s[0][1] */ - t.notOk(currentPoint.left, 'is right'); - t.deepEqual( - currentPoint.otherEvent.point, - [170, 74], - 'other event' - ); /* s[0][0] */ - t.ok(currentPoint.otherEvent.left, 'other event is left'); - - t.end(); - }); - - main.test('point 10', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [239.5, -198]); /* c[0][2] */ - t.notOk(currentPoint.left, 'is right'); - t.deepEqual( - currentPoint.otherEvent.point, - [54.5, -170.5], - 'other event' - ); /* c[0][0] */ - t.ok(currentPoint.otherEvent.left, 'other event is left'); - - t.end(); - }); - - main.test('point 11', (t) => { - currentPoint = q.pop(); - t.deepEqual(currentPoint.point, [239.5, -198]); /* c[0][2] */ - t.notOk(currentPoint.left, 'is right'); - t.deepEqual( - currentPoint.otherEvent.point, - [140.5, 33.5], - 'other event' - ); /* s[0][1] */ - t.ok(currentPoint.otherEvent.left, 'other event is left'); - - t.end(); - }); - - main.end(); -}); diff --git a/test/index.test.ts b/test/index.test.ts new file mode 100644 index 0000000..e629d9e --- /dev/null +++ b/test/index.test.ts @@ -0,0 +1,173 @@ +import { describe, it, assert } from 'vitest'; +import path from 'path'; +import load from 'load-json-file'; +import fillQueue from '../src/fill_queue'; +import { BoundingBox, MultiPolygon, Polygon } from '../src/types'; +import { FeatureCollection, Polygon as GeoPolygon } from 'geojson'; + +// GeoJSON Data +const data: FeatureCollection = load.sync( + path.join(__dirname, 'fixtures', 'two_triangles.geojson') +); + +const subject = data.features[0]; +const clipping = data.features[1]; + +describe('fill event queue', () => { + const s = [subject.geometry.coordinates] as MultiPolygon; + const c = [clipping.geometry.coordinates] as MultiPolygon; + + const sbbox: BoundingBox = [Infinity, Infinity, -Infinity, -Infinity]; + const cbbox: BoundingBox = [Infinity, Infinity, -Infinity, -Infinity]; + const q = fillQueue(s, c, sbbox, cbbox, 0); + let currentPoint; + + it('bboxes', () => { + assert.deepEqual(sbbox, [20, -113.5, 226.5, 74], 'subject bbox'); + assert.deepEqual(cbbox, [54.5, -198, 239.5, 33.5], 'clipping bbox'); + }); + + it('point 0', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [20, -23.5]); /* s[0][0] */ + assert.ok(currentPoint.left, 'is left'); + assert.deepEqual( + currentPoint.otherEvent.point, + [226.5, -113.5], + 'other event' + ); /* s[0][2] */ + assert.notOk(currentPoint.otherEvent.left, 'other event is right'); + }); + + it('point 1', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [20, -23.5]); /* s[0][0] */ + assert.ok(currentPoint.left, 'is left'); + assert.deepEqual( + currentPoint.otherEvent.point, + [170, 74], + 'other event' + ); /* s[0][1] */ + assert.notOk(currentPoint.otherEvent.left, 'other event is right'); + }); + + it('point 2', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [54.5, -170.5]); /* c[0][0] */ + assert.ok(currentPoint.left, 'is left'); + assert.deepEqual( + currentPoint.otherEvent.point, + [239.5, -198], + 'other event' + ); /* c[0][2] */ + assert.notOk(currentPoint.otherEvent.left, 'other event is right'); + }); + + it('point 3', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [54.5, -170.5]); /* c[0][0] */ + assert.ok(currentPoint.left, 'is left'); + assert.deepEqual( + currentPoint.otherEvent.point, + [140.5, 33.5], + 'other event' + ); /* c[0][1] */ + assert.notOk(currentPoint.otherEvent.left, 'other event is right'); + }); + + it('point 4', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [140.5, 33.5]); /* c[0][0] */ + assert.notOk(currentPoint.left, 'is right'); + assert.deepEqual( + currentPoint.otherEvent.point, + [54.5, -170.5], + 'other event' + ); /* c[0][1] */ + assert.ok(currentPoint.otherEvent.left, 'other event is left'); + }); + + it('point 5', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [140.5, 33.5]); /* c[0][0] */ + assert.ok(currentPoint.left, 'is left'); + assert.deepEqual( + currentPoint.otherEvent.point, + [239.5, -198], + 'other event' + ); /* c[0][1] */ + assert.notOk(currentPoint.otherEvent.left, 'other event is right'); + }); + + it('point 6', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [170, 74]); /* s[0][1] */ + assert.notOk(currentPoint.left, 'is right'); + assert.deepEqual( + currentPoint.otherEvent.point, + [20, -23.5], + 'other event' + ); /* s[0][0] */ + assert.ok(currentPoint.otherEvent.left, 'other event is left'); + }); + + it('point 7', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [170, 74]); /* s[0][1] */ + assert.ok(currentPoint.left, 'is left'); + assert.deepEqual( + currentPoint.otherEvent.point, + [226.5, -113.5], + 'other event' + ); /* s[0][3] */ + assert.notOk(currentPoint.otherEvent.left, 'other event is right'); + }); + + it('point 8', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [226.5, -113.5]); /* s[0][1] */ + assert.notOk(currentPoint.left, 'is right'); + assert.deepEqual( + currentPoint.otherEvent.point, + [20, -23.5], + 'other event' + ); /* s[0][0] */ + assert.ok(currentPoint.otherEvent.left, 'other event is left'); + }); + + it('point 9', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [226.5, -113.5]); /* s[0][1] */ + assert.notOk(currentPoint.left, 'is right'); + assert.deepEqual( + currentPoint.otherEvent.point, + [170, 74], + 'other event' + ); /* s[0][0] */ + assert.ok(currentPoint.otherEvent.left, 'other event is left'); + }); + + it('point 10', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [239.5, -198]); /* c[0][2] */ + assert.notOk(currentPoint.left, 'is right'); + assert.deepEqual( + currentPoint.otherEvent.point, + [54.5, -170.5], + 'other event' + ); /* c[0][0] */ + assert.ok(currentPoint.otherEvent.left, 'other event is left'); + }); + + it('point 11', () => { + currentPoint = q.pop(); + assert.deepEqual(currentPoint.point, [239.5, -198]); /* c[0][2] */ + assert.notOk(currentPoint.left, 'is right'); + assert.deepEqual( + currentPoint.otherEvent.point, + [140.5, 33.5], + 'other event' + ); /* s[0][1] */ + assert.ok(currentPoint.otherEvent.left, 'other event is left'); + }); +});