@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
143 lines • 4.38 kB
JavaScript
import { describe, test, expect } from "vitest";
import { booleanOverlap } from "./booleanOverlap.js";
import { genSampleSketch } from "../helpers/index.js";
const lineSketchA = genSampleSketch({
type: "LineString",
coordinates: [
[],
[],
[],
],
});
const lineSketchB = genSampleSketch({
type: "LineString",
coordinates: [
[],
[],
[],
],
});
const lineSketchC = genSampleSketch({
type: "LineString",
coordinates: [
[],
[],
],
});
const lineSketchD = genSampleSketch({
type: "LineString",
coordinates: [
[],
[],
],
});
const polySketchA = genSampleSketch({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const polySketchB = genSampleSketch({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const polySketchC = genSampleSketch({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const polySketchD = genSampleSketch({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
describe("Overlap unit tests", () => {
test("sketches cannot be equal", async () => {
const result = await booleanOverlap(polySketchA, polySketchA);
expect(result.length).toBe(0);
});
// Polygons
test("A and B poly feature overlap", async () => {
const result = await booleanOverlap(polySketchA, polySketchB);
expect(result.length).toBe(1);
});
test("A and C poly feature do not overlap", async () => {
const result = await booleanOverlap(polySketchA, polySketchC);
expect(result.length).toBe(0);
});
test("A and B poly geometry overlap", async () => {
const result = await booleanOverlap([polySketchA.geometry], [polySketchB.geometry]);
expect(result.length).toBe(1);
});
test("A and C poly geometry do not overlap", async () => {
const result = await booleanOverlap([polySketchA.geometry], [polySketchC.geometry]);
expect(result.length).toBe(0);
});
test("A and B together overlap with C", async () => {
const result = await booleanOverlap([polySketchA, polySketchB], polySketchC);
expect(result.length).toBe(1);
});
test.skip("A and B together overlap with C and D", async () => {
const result = await booleanOverlap([polySketchA, polySketchB], [polySketchC, polySketchD]);
expect(result.length).toBe(2);
});
test("A overlaps with B but not C", async () => {
const result = await booleanOverlap(polySketchA, [
polySketchB,
polySketchC,
]);
expect(result.length).toBe(1);
});
test("idProperty of name should return just one poly", async () => {
const result = await booleanOverlap(polySketchB, [polySketchA, polySketchC, polySketchD], "name");
// All test sketches get the same name so it should only return the first that overlaps
expect(result.length).toBe(1);
});
// Lines
test("A and B line overlap", async () => {
const result = await booleanOverlap([lineSketchA], [lineSketchB]);
expect(result.length).toBe(1);
});
test("A and C line do not overlap", async () => {
const result = await booleanOverlap([lineSketchA], [lineSketchC]);
expect(result.length).toBe(0);
});
test("A overlaps with B but not C", async () => {
const result = await booleanOverlap([lineSketchA], [lineSketchB, lineSketchC]);
expect(result.length).toBe(1);
});
test("idProperty of name should return just one line", async () => {
const result = await booleanOverlap([lineSketchB], [lineSketchA, lineSketchC, lineSketchD], "name");
// All test sketches get the same name so it should only return the first that overlaps
expect(result.length).toBe(1);
});
});
//# sourceMappingURL=booleanOverlap.test.js.map