astraeus-data-constellations 0.9.5 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/finder.js +43 -7
- package/src/index.js +18 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astraeus-data-constellations",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "The 88 IAU constellations for the Astraeus engine: stick figures, boundary outlines in J2000 and names. Optional data; the engine draws without it.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"iau"
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"astraeus": ">=0.
|
|
19
|
+
"astraeus": ">=0.10.0 <0.11.0"
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
".": {
|
package/src/finder.js
CHANGED
|
@@ -5,7 +5,11 @@ const unit = (raDeg, decDeg) => {
|
|
|
5
5
|
return [cosDec * Math.cos(raDeg * RAD), cosDec * Math.sin(raDeg * RAD), Math.sin(decDeg * RAD)];
|
|
6
6
|
};
|
|
7
7
|
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
8
|
-
const cross = (a, b) => [
|
|
8
|
+
const cross = (a, b) => [
|
|
9
|
+
a[1] * b[2] - a[2] * b[1],
|
|
10
|
+
a[2] * b[0] - a[0] * b[2],
|
|
11
|
+
a[0] * b[1] - a[1] * b[0],
|
|
12
|
+
];
|
|
9
13
|
const normalize = (a) => {
|
|
10
14
|
const length = Math.hypot(a[0], a[1], a[2]);
|
|
11
15
|
return length === 0 ? a : [a[0] / length, a[1] / length, a[2] / length];
|
|
@@ -30,8 +34,27 @@ const buildLoop = (abbr, flat) => {
|
|
|
30
34
|
}
|
|
31
35
|
const circles = Math.abs(wind) > 180;
|
|
32
36
|
const normals = points.map((a, i) => normalize(cross(a, points[(i + 1) % points.length])));
|
|
33
|
-
|
|
37
|
+
const pole = !circles ? "none" : decSum > 0 ? "north" : "south";
|
|
38
|
+
let minZ = pole === "south" ? -1 : Infinity;
|
|
39
|
+
let maxZ = pole === "north" ? 1 : -Infinity;
|
|
40
|
+
points.forEach((a, i) => {
|
|
41
|
+
const b = points[(i + 1) % points.length];
|
|
42
|
+
const normal = normals[i];
|
|
43
|
+
minZ = Math.min(minZ, a[2]);
|
|
44
|
+
maxZ = Math.max(maxZ, a[2]);
|
|
45
|
+
const top = normalize([-normal[2] * normal[0], -normal[2] * normal[1], 1 - normal[2] * normal[2]]);
|
|
46
|
+
if (top[2] === 0 && top[0] === 0 && top[1] === 0)
|
|
47
|
+
return;
|
|
48
|
+
for (const extreme of [top, [-top[0], -top[1], -top[2]]]) {
|
|
49
|
+
if (dot(cross(a, extreme), normal) >= 0 && dot(cross(extreme, b), normal) >= 0) {
|
|
50
|
+
minZ = Math.min(minZ, extreme[2]);
|
|
51
|
+
maxZ = Math.max(maxZ, extreme[2]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return { abbr, points, normals, pole, minZ, maxZ };
|
|
34
56
|
};
|
|
57
|
+
const inBand = (loop, z) => z >= loop.minZ - 2 * EDGE_EPS && z <= loop.maxZ + 2 * EDGE_EPS;
|
|
35
58
|
const contains = (loop, p, raDeg) => {
|
|
36
59
|
const c = Math.cos(raDeg * RAD);
|
|
37
60
|
const s = Math.sin(raDeg * RAD);
|
|
@@ -45,7 +68,11 @@ const contains = (loop, p, raDeg) => {
|
|
|
45
68
|
const db = dot(b, plane);
|
|
46
69
|
if (da >= 0 === db >= 0)
|
|
47
70
|
continue;
|
|
48
|
-
const x = [
|
|
71
|
+
const x = [
|
|
72
|
+
a[0] * Math.abs(db) + b[0] * Math.abs(da),
|
|
73
|
+
a[1] * Math.abs(db) + b[1] * Math.abs(da),
|
|
74
|
+
a[2] * Math.abs(db) + b[2] * Math.abs(da),
|
|
75
|
+
];
|
|
49
76
|
if (x[0] * c + x[1] * s > 0 && x[2] / Math.hypot(x[0], x[1], x[2]) > p[2])
|
|
50
77
|
crossings++;
|
|
51
78
|
}
|
|
@@ -59,7 +86,9 @@ const edgeDistance = (loop, p) => {
|
|
|
59
86
|
const b = loop.points[(i + 1) % n];
|
|
60
87
|
const normal = loop.normals[i];
|
|
61
88
|
const within = dot(cross(a, p), normal) >= 0 && dot(cross(p, b), normal) >= 0;
|
|
62
|
-
const d = within
|
|
89
|
+
const d = within
|
|
90
|
+
? Math.asin(Math.min(1, Math.abs(dot(p, normal))))
|
|
91
|
+
: Math.acos(Math.min(1, Math.max(dot(p, a), dot(p, b))));
|
|
63
92
|
if (d < best)
|
|
64
93
|
best = d;
|
|
65
94
|
}
|
|
@@ -70,11 +99,16 @@ const checked = (direction) => {
|
|
|
70
99
|
throw new RangeError("constellationFinder: the direction must be an object { raDeg, decDeg }");
|
|
71
100
|
if (typeof direction.raDeg !== "number" || !Number.isFinite(direction.raDeg))
|
|
72
101
|
throw new RangeError(`constellationFinder: raDeg must be a finite number, got ${String(direction.raDeg)}`);
|
|
73
|
-
if (typeof direction.decDeg !== "number" ||
|
|
102
|
+
if (typeof direction.decDeg !== "number" ||
|
|
103
|
+
!Number.isFinite(direction.decDeg) ||
|
|
104
|
+
direction.decDeg < -90 ||
|
|
105
|
+
direction.decDeg > 90)
|
|
74
106
|
throw new RangeError(`constellationFinder: decDeg must be a number from -90 to 90, got ${String(direction.decDeg)}`);
|
|
75
107
|
};
|
|
76
108
|
export const buildMatcher = (boundaries) => {
|
|
77
|
-
const loops = Object.keys(boundaries)
|
|
109
|
+
const loops = Object.keys(boundaries)
|
|
110
|
+
.sort()
|
|
111
|
+
.flatMap((abbr) => (boundaries[abbr] ?? []).map((flat) => buildLoop(abbr, flat)));
|
|
78
112
|
const prepare = (direction) => {
|
|
79
113
|
checked(direction);
|
|
80
114
|
const raDeg = ((direction.raDeg % 360) + 360) % 360;
|
|
@@ -84,6 +118,8 @@ export const buildMatcher = (boundaries) => {
|
|
|
84
118
|
const { p, raDeg } = prepare(direction);
|
|
85
119
|
let inside;
|
|
86
120
|
for (const loop of loops) {
|
|
121
|
+
if (!inBand(loop, p[2]))
|
|
122
|
+
continue;
|
|
87
123
|
if (edgeDistance(loop, p) <= EDGE_EPS)
|
|
88
124
|
return loop.abbr;
|
|
89
125
|
if (inside === undefined && contains(loop, p, raDeg))
|
|
@@ -104,7 +140,7 @@ export const buildMatcher = (boundaries) => {
|
|
|
104
140
|
};
|
|
105
141
|
const enclosing = (direction) => {
|
|
106
142
|
const { p, raDeg } = prepare(direction);
|
|
107
|
-
return loops.filter((loop) => contains(loop, p, raDeg)).map((loop) => loop.abbr);
|
|
143
|
+
return loops.filter((loop) => inBand(loop, p[2]) && contains(loop, p, raDeg)).map((loop) => loop.abbr);
|
|
108
144
|
};
|
|
109
145
|
return { find, enclosing };
|
|
110
146
|
};
|
package/src/index.js
CHANGED
|
@@ -9,7 +9,10 @@ export const loadNames = () => read(() => import("../data/names.json", { with: {
|
|
|
9
9
|
export const loadProvenance = () => read(() => import("../data/provenance.json", { with: { type: "json" } }));
|
|
10
10
|
let finder;
|
|
11
11
|
export const constellationFinder = () => {
|
|
12
|
-
finder ??= loadBoundaries().then(buildFinder, (error) => {
|
|
12
|
+
finder ??= loadBoundaries().then(buildFinder, (error) => {
|
|
13
|
+
finder = undefined;
|
|
14
|
+
throw error;
|
|
15
|
+
});
|
|
13
16
|
return finder;
|
|
14
17
|
};
|
|
15
18
|
const provenance = (what, sources) => ({
|
|
@@ -18,12 +21,22 @@ const provenance = (what, sources) => ({
|
|
|
18
21
|
accuracy: `${what} are conventional drawings, not measurements.`,
|
|
19
22
|
notes: "From the astraeus-data-constellations package; see its NOTICE for licences.",
|
|
20
23
|
});
|
|
21
|
-
const FIGURE_SOURCES = [
|
|
22
|
-
|
|
24
|
+
const FIGURE_SOURCES = [
|
|
25
|
+
"IAU constellation figures (drawn by Sky & Telescope), via Stellarium skycultures/modern_iau, CC BY-SA 4.0",
|
|
26
|
+
"Names: IAU, CC BY 4.0",
|
|
27
|
+
];
|
|
28
|
+
const BOUNDARY_SOURCES = [
|
|
29
|
+
"Constellation boundaries: Delporte (1930), via Stellarium skycultures/modern_iau, CC BY-SA 4.0, precessed to J2000",
|
|
30
|
+
"Names: IAU, CC BY 4.0",
|
|
31
|
+
];
|
|
23
32
|
const SERPENS_PARTS = ["Caput", "Cauda"];
|
|
24
|
-
const endOf = (end) =>
|
|
33
|
+
const endOf = (end) => typeof end === "number" ? { star: end } : { raDeg: end[0], decDeg: end[1] };
|
|
25
34
|
export const constellations = async (which, options = {}) => {
|
|
26
|
-
const [figures, boundaries, names] = await Promise.all([
|
|
35
|
+
const [figures, boundaries, names] = await Promise.all([
|
|
36
|
+
loadFigures(),
|
|
37
|
+
options.outlines === true ? loadBoundaries() : Promise.resolve({}),
|
|
38
|
+
loadNames(),
|
|
39
|
+
]);
|
|
27
40
|
const abbrs = which === "all" ? Object.keys(names).sort() : which;
|
|
28
41
|
const seen = new Set();
|
|
29
42
|
const unknown = [];
|