-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
81 lines (71 loc) · 3.45 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/flug"></script>
<script src="https://unpkg.com/geotiff/dist-browser/geotiff.js"></script>
<script src="https://unpkg.com/preciso"></script>
<script src="./geotiff-precise-bbox.min.js"></script>
</head>
<body>
<script>
// load test data
(async function() {
const tests = await fetch("./tests.json").then(r => r.json());
console.log({tests});
const log = console.log;
console.log = function () {
const args = Array.from(arguments);
log({args});
const container = document.createElement("H3");
container.className = "container";
const styled_strings = args.filter(arg => typeof arg === "string" && arg.includes("%c"));
log({styled_strings});
const css_strings = args.filter(arg => typeof arg === "string").slice(-1 * styled_strings.length);
log({css_strings});
args.filter(arg => !css_strings.includes(arg)).forEach(arg => {
const stylish = typeof arg === "string" && arg.includes("%c");
if (typeof arg !== "string") arg = JSON.stringify(arg);
const span = document.createElement("DIV");
if (stylish) {
arg = arg.replace("%c", "");
const css = css_strings.shift();
log({css});
span.style = css;
}
span.textContent = arg;
container.appendChild(span);
});
document.body.appendChild(container);
log(...arguments);
}
const { divide, subtract } = preciso;
tests.forEach(({ url, bbox: expected_bbox, precise_bbox: expected_precise_bbox }) => {
if (!url) return;
test(url, async ({ eq }) => {
const tif = await GeoTIFF.fromUrl(url);
const image = await tif.getImage();
const actual_bbox = image.getBoundingBox();
const actual_precise_bbox = getPreciseBoundingBox(image);
eq(actual_bbox, expected_bbox);
eq(actual_precise_bbox, expected_precise_bbox);
const [xScale, yScale, zScale] = image.getResolution();
const pixel_width = Math.abs(xScale);
const pixel_height = Math.abs(yScale);
// reverse and get pixel height and width from getPreciseBoundingBox(image)
const [precise_xmin, precise_ymin, precise_xmax, precise_ymax] = actual_precise_bbox;
const precise_pixel_width = Number(divide(subtract(precise_xmax, precise_xmin), image.getWidth().toString()));
const precise_pixel_height = Number(divide(subtract(precise_ymax, precise_ymin), image.getHeight().toString()));
eq(precise_pixel_height, pixel_height);
eq(precise_pixel_width, pixel_width);
// reverse engineer pixel width and height from image.getBoundingBox()
const [xmin, ymin, xmax, ymax] = actual_bbox;
const wpx = Number(divide(subtract(xmax.toString(), xmin.toString()), image.getWidth().toString()));
const hpx = Number(divide(subtract(ymax.toString(), ymin.toString()), image.getHeight().toString()));
if (hpx !== pixel_height) console.log(`[${url}] pixel height should be ${pixel_height} not ${hpx}`);
if (wpx !== pixel_width) console.log(`[${url}] pixel width should be ${pixel_width} not ${wpx}`);
});
});
})();
</script>
</body>
</html>