Skip to content

Commit

Permalink
testing for TS done
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Martian committed Sep 1, 2024
1 parent 5949f8d commit c6b1171
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ jobs:
shell: bash

- name: Run Rust tests
run: cargo test
run: cargo test --lib
shell: bash
2 changes: 1 addition & 1 deletion src/tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Tile {
* @param tolerance - tolerance
* @param maxzoom - max zoom at which to simplify
*/
simplify(tolerance = 1, maxzoom = 16) {
simplify(tolerance: number, maxzoom?: number) {
const zoom = level(this.projection, this.id);

for (const layer of Object.values(this.layers)) {
Expand Down
127 changes: 0 additions & 127 deletions test.ts

This file was deleted.

208 changes: 207 additions & 1 deletion test/simplify.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { buildSqDists, simplify } from '../src/simplify';
import { expect, test } from 'bun:test';

import type { VectorLineStringGeometry } from '../src';
import type {
VectorLineStringGeometry,
VectorMultiLineStringGeometry,
VectorMultiPolygonGeometry,
VectorPolygonGeometry,
} from '../src';

const SIMPLIFY_MAXZOOM = 16;

Expand Down Expand Up @@ -42,3 +47,204 @@ test('LineString', () => {
vecBBox: [0.25, 0.25, 0.75, 0.75],
});
});

test('MultiLineString', () => {
const multiLineString: VectorMultiLineStringGeometry = {
type: 'MultiLineString',
coordinates: [
[
{ x: 0.25, y: 0.25 },
{ x: 0.75, y: 0.25 },
{ x: 0.75, y: 0.75 },
{ x: 0.25, y: 0.75 },
],
[
{ x: 0.5, y: 0.5 },
{ x: 0.5, y: 0.25 },
{ x: 0.75, y: 0.25 },
{ x: 0.75, y: 0.5 },
{ x: 0.5, y: 0.5 },
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
};

buildSqDists(multiLineString, 3, SIMPLIFY_MAXZOOM);

expect(multiLineString).toEqual({
type: 'MultiLineString',
coordinates: [
[
{ x: 0.25, y: 0.25, t: 1 },
{ x: 0.75, y: 0.25, t: 0.125 },
{ x: 0.75, y: 0.75, t: 0.25 },
{ x: 0.25, y: 0.75, t: 1 },
],
[
{ t: 1, x: 0.5, y: 0.5 },
{ t: 0.03125, x: 0.5, y: 0.25 },
{ t: 1, x: 0.75, y: 0.25 },
{ t: 0.03125, x: 0.75, y: 0.5 },
{ t: 1, x: 0.5, y: 0.5 },
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
});

simplify(multiLineString, 3, 0, SIMPLIFY_MAXZOOM);
expect(multiLineString).toEqual({
type: 'MultiLineString',
coordinates: [
[
{ x: 0.25, y: 0.25, t: 1 },
{ x: 0.75, y: 0.25, t: 0.125 },
{ x: 0.75, y: 0.75, t: 0.25 },
{ x: 0.25, y: 0.75, t: 1 },
],
[
{ t: 1, x: 0.5, y: 0.5 },
{ t: 0.03125, x: 0.5, y: 0.25 },
{ t: 1, x: 0.75, y: 0.25 },
{ t: 0.03125, x: 0.75, y: 0.5 },
{ t: 1, x: 0.5, y: 0.5 },
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
});
});

test('Polygon', () => {
const polygon: VectorPolygonGeometry = {
type: 'Polygon',
coordinates: [
[
{ x: 0.25, y: 0.25 },
{ x: 0.75, y: 0.25 },
{ x: 0.75, y: 0.75 },
{ x: 0.25, y: 0.75 },
],
[
{ x: 0.5, y: 0.5 },
{ x: 0.5, y: 0.25 },
{ x: 0.75, y: 0.25 },
{ x: 0.75, y: 0.5 },
{ x: 0.5, y: 0.5 },
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
};

buildSqDists(polygon, 3, SIMPLIFY_MAXZOOM);

expect(polygon).toEqual({
type: 'Polygon',
coordinates: [
[
{ x: 0.25, y: 0.25, t: 1 },
{ x: 0.75, y: 0.25, t: 0.125 },
{ x: 0.75, y: 0.75, t: 0.25 },
{ x: 0.25, y: 0.75, t: 1 },
],
[
{ t: 1, x: 0.5, y: 0.5 },
{ t: 0.03125, x: 0.5, y: 0.25 },
{ t: 1, x: 0.75, y: 0.25 },
{ t: 0.03125, x: 0.75, y: 0.5 },
{ t: 1, x: 0.5, y: 0.5 },
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
});

simplify(polygon, 3, 0, SIMPLIFY_MAXZOOM);
expect(polygon).toEqual({
type: 'Polygon',
coordinates: [
[
{ x: 0.25, y: 0.25, t: 1 },
{ x: 0.75, y: 0.25, t: 0.125 },
{ x: 0.75, y: 0.75, t: 0.25 },
{ x: 0.25, y: 0.75, t: 1 },
],
[
{ t: 1, x: 0.5, y: 0.5 },
{ t: 0.03125, x: 0.5, y: 0.25 },
{ t: 1, x: 0.75, y: 0.25 },
{ t: 0.03125, x: 0.75, y: 0.5 },
{ t: 1, x: 0.5, y: 0.5 },
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
});
});

test('MultiPolygon', () => {
const multiPolygon: VectorMultiPolygonGeometry = {
type: 'MultiPolygon',
coordinates: [
[
[
{ x: 0.25, y: 0.25 },
{ x: 0.75, y: 0.25 },
{ x: 0.75, y: 0.75 },
{ x: 0.25, y: 0.75 },
],
[
{ x: 0.5, y: 0.5 },
{ x: 0.5, y: 0.25 },
{ x: 0.75, y: 0.25 },
{ x: 0.75, y: 0.5 },
{ x: 0.5, y: 0.5 },
],
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
};

buildSqDists(multiPolygon, 3, SIMPLIFY_MAXZOOM);

expect(multiPolygon).toEqual({
type: 'MultiPolygon',
coordinates: [
[
[
{ x: 0.25, y: 0.25, t: 1 },
{ x: 0.75, y: 0.25, t: 0.125 },
{ x: 0.75, y: 0.75, t: 0.25 },
{ x: 0.25, y: 0.75, t: 1 },
],
[
{ t: 1, x: 0.5, y: 0.5 },
{ t: 0.03125, x: 0.5, y: 0.25 },
{ t: 1, x: 0.75, y: 0.25 },
{ t: 0.03125, x: 0.75, y: 0.5 },
{ t: 1, x: 0.5, y: 0.5 },
],
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
});

simplify(multiPolygon, 3, 0, SIMPLIFY_MAXZOOM);
expect(multiPolygon).toEqual({
type: 'MultiPolygon',
coordinates: [
[
[
{ x: 0.25, y: 0.25, t: 1 },
{ x: 0.75, y: 0.25, t: 0.125 },
{ x: 0.75, y: 0.75, t: 0.25 },
{ x: 0.25, y: 0.75, t: 1 },
],
[
{ t: 1, x: 0.5, y: 0.5 },
{ t: 0.03125, x: 0.5, y: 0.25 },
{ t: 1, x: 0.75, y: 0.25 },
{ t: 0.03125, x: 0.75, y: 0.5 },
{ t: 1, x: 0.5, y: 0.5 },
],
],
],
vecBBox: [0.25, 0.25, 0.75, 0.75],
});
});
Loading

0 comments on commit c6b1171

Please sign in to comment.