-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
62 lines (53 loc) · 1.88 KB
/
test.js
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
const test = require("flug");
const { forward, inverse } = require("./index.js");
const wldNumbers = {
xScale: 2445.9849051249894,
ySkew: 0,
xSkew: 0,
yScale: -2445.98490512499,
xOrigin: 7699959.850241235,
yOrigin: 1323859.6754601842
};
const wldStrings = {
xScale: "2445.9849051249894",
ySkew: "0",
xSkew: "0",
yScale: "-2445.98490512499",
xOrigin: "7699959.850241235",
yOrigin: "1323859.6754601842"
};
const size = { height: 475, width: 968 };
test("imprecise calculation from World File numbers", ({ eq }) => {
const bbox = forward({ wld: wldNumbers, size, precise: false });
eq(bbox, [7698736.857788673, 163239.83797837654, 10066450.245949663, 1325082.6679127468]);
});
test("precise calculate from World File numbers", ({ eq }) => {
const bbox = forward({ wld: wldNumbers, size, precise: true });
eq(bbox, ["7698736.8577886725053", "163239.837978376445", "10066450.2459496622445", "1325082.667912746695"]);
});
test("precise calculate from World File strings", ({ eq }) => {
const bbox = forward({ wld: wldStrings, size, precise: true });
eq(bbox, ["7698736.8577886725053", "163239.837978376445", "10066450.2459496622445", "1325082.667912746695"]);
// round trip
eq(inverse({ bbox, size }), wldStrings);
});
test("example: inverse with precise arithmetic", ({ eq }) => {
const wld = inverse({
bbox: ["7698736.8577886725053", "163239.837978376445", "10066450.2459496622445", "1325082.667912746695"],
precise: true,
size
});
eq(wld, wldStrings);
});
test("example: inverse with floating-point arithmetic", ({ eq }) => {
const wld = inverse({
bbox: [7698736.857788673, 163239.83797837654, 10066450.245949663, 1325082.6679127468],
precise: false,
size
});
eq(Math.abs(wldNumbers.xScale - wld.xScale) < 0.000000001, true);
eq(wld.ySkew, 0);
eq(wld.xSkew, 0);
eq(wld.xOrigin, wldNumbers.xOrigin);
eq(wld.yOrigin, wldNumbers.yOrigin);
});