@seasketch/geoprocessing
Version:
Geoprocessing and reporting framework for SeaSketch 2.0
178 lines (166 loc) • 4.15 kB
text/typescript
import { describe, test, expect } from "vitest";
import { booleanOverlap } from "./booleanOverlap.js";
import { genSampleSketch } from "../helpers/index.js";
import { Polygon } from "../types/geojson.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<Polygon>({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const polySketchB = genSampleSketch<Polygon>({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const polySketchC = genSampleSketch<Polygon>({
type: "Polygon",
coordinates: [
[
[],
[],
[],
[],
[],
],
],
});
const polySketchD = genSampleSketch<Polygon>({
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(
[],
[],
);
expect(result.length).toBe(1);
});
test("A and C poly geometry do not overlap", async () => {
const result = await booleanOverlap(
[],
[],
);
expect(result.length).toBe(0);
});
test("A and B together overlap with C", async () => {
const result = await booleanOverlap(
[],
polySketchC,
);
expect(result.length).toBe(1);
});
test.skip("A and B together overlap with C and D", async () => {
const result = await booleanOverlap(
[],
[],
);
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,
[],
"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(
[],
[],
);
expect(result.length).toBe(1);
});
test("idProperty of name should return just one line", async () => {
const result = await booleanOverlap(
[],
[],
"name",
);
// All test sketches get the same name so it should only return the first that overlaps
expect(result.length).toBe(1);
});
});