|
| 1 | +import { |
| 2 | + Rectangle, |
| 3 | + ImageryCoverage, |
| 4 | + CartesianRectangle, |
| 5 | + Math as CesiumMath, |
| 6 | +} from "../../../index.js"; |
| 7 | + |
| 8 | +describe("Scene/Model/ImageryCoverage", function () { |
| 9 | + it("_localizeCartographicRectanglesToCartesianRectangle returns unit rectangle for equal inputs", async function () { |
| 10 | + const ra = Rectangle.fromDegrees(10, 10, 20, 20); |
| 11 | + const rb = Rectangle.fromDegrees(10, 10, 20, 20); |
| 12 | + const actual = new CartesianRectangle(); |
| 13 | + const expected = new CartesianRectangle(0, 0, 1, 1); |
| 14 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 15 | + ra, |
| 16 | + rb, |
| 17 | + actual, |
| 18 | + ); |
| 19 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 20 | + }); |
| 21 | + |
| 22 | + it("_localizeCartographicRectanglesToCartesianRectangle computes offset for overlapping inputs", async function () { |
| 23 | + const ra = Rectangle.fromDegrees(15, 15, 25, 25); |
| 24 | + const rb = Rectangle.fromDegrees(10, 10, 20, 20); |
| 25 | + const actual = new CartesianRectangle(); |
| 26 | + const expected = new CartesianRectangle(0.5, 0.5, 1.5, 1.5); |
| 27 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 28 | + ra, |
| 29 | + rb, |
| 30 | + actual, |
| 31 | + ); |
| 32 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 33 | + }); |
| 34 | + |
| 35 | + it("_localizeCartographicRectanglesToCartesianRectangle computes offset for non-overlapping inputs", async function () { |
| 36 | + const ra = Rectangle.fromDegrees(30, 30, 50, 50); |
| 37 | + const rb = Rectangle.fromDegrees(10, 10, 20, 20); |
| 38 | + const actual = new CartesianRectangle(); |
| 39 | + const expected = new CartesianRectangle(2, 2, 4, 4); |
| 40 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 41 | + ra, |
| 42 | + rb, |
| 43 | + actual, |
| 44 | + ); |
| 45 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 46 | + }); |
| 47 | + |
| 48 | + it("_localizeCartographicRectanglesToCartesianRectangle works when inner rectangle is left of antimeridian", async function () { |
| 49 | + const ra = Rectangle.fromDegrees(160, 10, 170, 50); |
| 50 | + const rb = Rectangle.fromDegrees(155, 10, -155, 50); |
| 51 | + const actual = new CartesianRectangle(); |
| 52 | + const expected = new CartesianRectangle(0.1, 0, 0.3, 1); |
| 53 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 54 | + ra, |
| 55 | + rb, |
| 56 | + actual, |
| 57 | + ); |
| 58 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 59 | + }); |
| 60 | + |
| 61 | + it("_localizeCartographicRectanglesToCartesianRectangle works when inner rectangle is right of antimeridian", async function () { |
| 62 | + const ra = Rectangle.fromDegrees(-175, 10, -165, 50); |
| 63 | + const rb = Rectangle.fromDegrees(155, 10, -155, 50); |
| 64 | + const actual = new CartesianRectangle(); |
| 65 | + const expected = new CartesianRectangle(0.6, 0, 0.8, 1); |
| 66 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 67 | + ra, |
| 68 | + rb, |
| 69 | + actual, |
| 70 | + ); |
| 71 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 72 | + }); |
| 73 | + |
| 74 | + it("_localizeCartographicRectanglesToCartesianRectangle works when inner rectangle crosses antimeridian", async function () { |
| 75 | + const ra = Rectangle.fromDegrees(175, 10, -175, 50); |
| 76 | + const rb = Rectangle.fromDegrees(155, 10, -155, 50); |
| 77 | + const actual = new CartesianRectangle(); |
| 78 | + const expected = new CartesianRectangle(0.4, 0, 0.6, 1); |
| 79 | + |
| 80 | + console.log(actual); |
| 81 | + |
| 82 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 83 | + ra, |
| 84 | + rb, |
| 85 | + actual, |
| 86 | + ); |
| 87 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 88 | + }); |
| 89 | + |
| 90 | + it("_localizeCartographicRectanglesToCartesianRectangle works when inner is left and outer is right of antimeridian", async function () { |
| 91 | + const ra = Rectangle.fromDegrees(-175, 10, -165, 50); |
| 92 | + const rb = Rectangle.fromDegrees(165, 10, 175, 50); |
| 93 | + const actual = new CartesianRectangle(); |
| 94 | + const expected = new CartesianRectangle(2, 0, 3, 1); |
| 95 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 96 | + ra, |
| 97 | + rb, |
| 98 | + actual, |
| 99 | + ); |
| 100 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 101 | + }); |
| 102 | + |
| 103 | + it("_localizeCartographicRectanglesToCartesianRectangle works when inner is right and outer is left or antimeridian", async function () { |
| 104 | + const ra = Rectangle.fromDegrees(165, 10, 175, 50); |
| 105 | + const rb = Rectangle.fromDegrees(-175, 10, -165, 50); |
| 106 | + const actual = new CartesianRectangle(); |
| 107 | + const expected = new CartesianRectangle(-2, 0, -1, 1); |
| 108 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 109 | + ra, |
| 110 | + rb, |
| 111 | + actual, |
| 112 | + ); |
| 113 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 114 | + }); |
| 115 | + |
| 116 | + it("_localizeCartographicRectanglesToCartesianRectangle works when inner is left or meridian and outer is right of meridian", async function () { |
| 117 | + const ra = Rectangle.fromDegrees(-20, 10, -10, 20); |
| 118 | + const rb = Rectangle.fromDegrees(10, 10, 20, 20); |
| 119 | + const actual = new CartesianRectangle(); |
| 120 | + const expected = new CartesianRectangle(-3, 0, -2, 1); |
| 121 | + ImageryCoverage._localizeCartographicRectanglesToCartesianRectangle( |
| 122 | + ra, |
| 123 | + rb, |
| 124 | + actual, |
| 125 | + ); |
| 126 | + expect(actual).toEqualEpsilon(expected, CesiumMath.EPSILON8); |
| 127 | + }); |
| 128 | +}); |
0 commit comments