import { computeErasureIntervals, combineErasureIntervals, spreadErasureIntervals, flattenErasureIntervals, } from "../src/erasure.js" describe("erasure intervals", () => { it("computes simple erasure intervals", () => { const points = [ [0, 0], [100, 100], ] const erasureCenter = [50, 50] const erasureRadius = 25 * Math.SQRT2 const erasureIntervals = computeErasureIntervals( points, erasureCenter, erasureRadius, ) expect(erasureIntervals).toStrictEqual({ 0: [[0.25, 0.75]] }) }) it("computes complex erasure intervals", () => { const points = [ [0, 0], [100, 100], [0, 200], ] const erasureCenter = [100, 100] const erasureRadius = 25 * Math.SQRT2 const erasureIntervals = computeErasureIntervals( points, erasureCenter, erasureRadius, ) expect(erasureIntervals).toStrictEqual({ 0: [[0.75, 1]], 1: [[0, 0.25]] }) }) it("computes erasure intervals when point projection is not on the segment", () => { const points = [ [800, 400], [800, 450], [800, 500], ] const erasureCenter = [800, 432] const erasureRadius = 20 //* Math.SQRT2 const erasureIntervals = computeErasureIntervals( points, erasureCenter, erasureRadius, ) expect(erasureIntervals).toStrictEqual({ 0: [[0.24, 1]], 1: [[0, 0.04]] }) }) it("computes erasure intervals ???", () => { const points = [ [100, 100], [1100, 100], ] const erasureCenter = [448, 86] const erasureRadius = 100 const erasureIntervals = computeErasureIntervals( points, erasureCenter, erasureRadius, ) expect(erasureIntervals).toStrictEqual({ 0: [[0.2489848496441075, 0.4470151503558925]], }) }) it("combines distinct intervals", () => { const i1 = { 0: [[0.1, 0.6]] } const i2 = { 0: [[0.7, 0.8]] } const combined = combineErasureIntervals(i1, i2) const expected = { 0: [ [0.1, 0.6], [0.7, 0.8], ], } expect(combined).toStrictEqual(expected) }) it("combines overlapping intervals", () => { const i1 = { 0: [[0.1, 0.6]] } const i2 = { 0: [[0.5, 0.8]] } const combined = combineErasureIntervals(i1, i2) const expected = { 0: [[0.1, 0.8]] } expect(combined).toStrictEqual(expected) }) it("combines overlapping inside intervals", () => { const i1 = { 0: [[0.1, 0.6]] } const i2 = { 0: [[0.2, 0.3]] } const combined = combineErasureIntervals(i1, i2) const expected = { 0: [[0.1, 0.6]] } expect(combined).toStrictEqual(expected) }) it("spreads flattened intervals", () => { const il = [ [0.1, 1.25], [1.5, 2.0], [7.5, 7.75], ] const spread = spreadErasureIntervals(il) const expected = { 0: [[0.1, 1.0]], 1: [ [0.0, 0.25], [0.5, 1.0], ], 7: [[0.5, 0.75]], } expect(spread).toStrictEqual(expected) }) it("spreads singulatity intervals", () => { const il = [ [0.0, 0.0], [3.5, 3.5], [99.0, 99.0], ] const spread = spreadErasureIntervals(il) const expected = { 0: [[0.0, 0.0]], 3: [[0.5, 0.5]], 99: [[0.0, 0.0]] } expect(spread).toStrictEqual(expected) }) it("flattens spread intervals", () => { const is = { 0: [[0.1, 1.0]], 1: [ [0.0, 0.3], [0.4, 1.0], ], 7: [[0.35, 0.75]], } const flattened = flattenErasureIntervals(is) const expected = [ [0.1, 1.0], [1.0, 1.3], [1.4, 2.0], [7.35, 7.75], ] expect(flattened).toStrictEqual(expected) }) })