27 lines
765 B
JavaScript
27 lines
765 B
JavaScript
'use strict';
|
|
|
|
const assert = require('assert/strict');
|
|
const { difference, intersection, union, intersectsOrTouches } = require('../src/compile/junction-polygon-ops');
|
|
|
|
const square = (x, y, size) => [
|
|
[
|
|
[x, y],
|
|
[x + size, y],
|
|
[x + size, y + size],
|
|
[x, y + size],
|
|
[x, y],
|
|
],
|
|
];
|
|
const shell = square(0, 0, 10);
|
|
const hole = square(2, 2, 6);
|
|
assert.equal(difference(shell, hole)[0].length, 2);
|
|
assert.equal(intersection(shell, hole).length, 1);
|
|
assert.equal(union(shell, square(10, 0, 5)).length, 1);
|
|
assert.deepEqual(difference(shell), [shell]);
|
|
assert.equal(intersectsOrTouches(shell, hole), true);
|
|
assert.equal(
|
|
intersectsOrTouches(shell, square(20, 0, 2), () => true),
|
|
true,
|
|
);
|
|
console.log('junction polygon operation tests passed');
|