@ac-kit/math-geodesy 0.0.0-stage → 0.1.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/CHANGELOG.md +113 -0
- package/LICENSE +57 -0
- package/README.md +89 -2
- package/dist/_brand.d.ts +14 -0
- package/dist/_brand.d.ts.map +1 -0
- package/dist/_brand.js +2 -0
- package/dist/_brand.js.map +1 -0
- package/dist/_ecef-forward-bound.d.ts +7 -0
- package/dist/_ecef-forward-bound.d.ts.map +1 -0
- package/dist/_ecef-forward-bound.js +7 -0
- package/dist/_ecef-forward-bound.js.map +1 -0
- package/dist/_ecef-height.d.ts +33 -0
- package/dist/_ecef-height.d.ts.map +1 -0
- package/dist/_ecef-height.js +173 -0
- package/dist/_ecef-height.js.map +1 -0
- package/dist/ellipsoid.d.ts +52 -0
- package/dist/ellipsoid.d.ts.map +1 -0
- package/dist/ellipsoid.js +75 -0
- package/dist/ellipsoid.js.map +1 -0
- package/dist/geodesic/_angle.d.ts +46 -0
- package/dist/geodesic/_angle.d.ts.map +1 -0
- package/dist/geodesic/_angle.js +144 -0
- package/dist/geodesic/_angle.js.map +1 -0
- package/dist/geodesic/_constants.d.ts +38 -0
- package/dist/geodesic/_constants.d.ts.map +1 -0
- package/dist/geodesic/_constants.js +142 -0
- package/dist/geodesic/_constants.js.map +1 -0
- package/dist/geodesic/_inverse.d.ts +22 -0
- package/dist/geodesic/_inverse.d.ts.map +1 -0
- package/dist/geodesic/_inverse.js +720 -0
- package/dist/geodesic/_inverse.js.map +1 -0
- package/dist/geodesic/_line.d.ts +37 -0
- package/dist/geodesic/_line.d.ts.map +1 -0
- package/dist/geodesic/_line.js +219 -0
- package/dist/geodesic/_line.js.map +1 -0
- package/dist/geodesic/_series.d.ts +69 -0
- package/dist/geodesic/_series.d.ts.map +1 -0
- package/dist/geodesic/_series.js +203 -0
- package/dist/geodesic/_series.js.map +1 -0
- package/dist/geodesic.d.ts +97 -0
- package/dist/geodesic.d.ts.map +1 -0
- package/dist/geodesic.js +245 -0
- package/dist/geodesic.js.map +1 -0
- package/dist/geodetic.d.ts +195 -0
- package/dist/geodetic.d.ts.map +1 -0
- package/dist/geodetic.js +456 -0
- package/dist/geodetic.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/local-frame.d.ts +19 -0
- package/dist/local-frame.d.ts.map +1 -0
- package/dist/local-frame.js +66 -0
- package/dist/local-frame.js.map +1 -0
- package/package.json +73 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Ellipsoid } from "./ellipsoid.js";
|
|
2
|
+
import { type Geodetic, type GeodesicInverse, type ReadonlyGeodetic } from "./geodetic.js";
|
|
3
|
+
declare const geodesicLineBrand_: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* A geodesic line on an ellipsoid: an opaque handle over the precomputed state
|
|
6
|
+
* (Karney's `GeodesicLine`). Make one with {@link geodesicLine} or
|
|
7
|
+
* {@link geodesicLineBetween}; read it with the `geodesicLine…` functions.
|
|
8
|
+
*/
|
|
9
|
+
export type GeodesicLine = {
|
|
10
|
+
readonly [geodesicLineBrand_]: true;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Solves the inverse geodesic problem on `ellipsoid`: the shortest path from
|
|
14
|
+
* `from` to `to`, writing its length in metres and its azimuths at both ends,
|
|
15
|
+
* degrees clockwise from north in `(−180, 180]`, into `out`. Heights are
|
|
16
|
+
* ignored.
|
|
17
|
+
*
|
|
18
|
+
* Coincident points give a distance of `0` and `NaN` azimuths; a non-finite
|
|
19
|
+
* longitude or latitude, or a latitude beyond ±90°, gives all `NaN`. Accurate
|
|
20
|
+
* to 15 nanometres on WGS 84, nearly antipodal points included. Allocates
|
|
21
|
+
* nothing, whether or not the engine inlines the solver's helpers. O(1).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const out = geodesicInverseCreate();
|
|
26
|
+
* const origin = geodeticOf(0, 0, 0);
|
|
27
|
+
* geodesicInverse(out, origin, geodeticOf(-1, 0, 0), ELLIPSOID_WGS84);
|
|
28
|
+
* // out[0] ≈ 111319.49 m, out[1] = out[2] = -90 (due west)
|
|
29
|
+
* ```;
|
|
30
|
+
*/
|
|
31
|
+
export declare function geodesicInverse(out: GeodesicInverse, from: ReadonlyGeodetic, to: ReadonlyGeodetic, ellipsoid: Ellipsoid): GeodesicInverse;
|
|
32
|
+
/**
|
|
33
|
+
* Solves the direct geodesic problem on `ellipsoid`: the end point, at height
|
|
34
|
+
* `0`, of the geodesic leaving `from` at `azimuthDeg` (degrees clockwise from
|
|
35
|
+
* north) and running `distanceM` metres (negative goes backwards). The
|
|
36
|
+
* longitude is in `[−180, 180]`. A non-finite input, or a latitude beyond ±90°,
|
|
37
|
+
* gives `NaN`s. Runs through a line held in a module-level buffer. O(1).
|
|
38
|
+
*
|
|
39
|
+
* The solver allocates nothing, whether or not the engine inlines its helpers.
|
|
40
|
+
* The only allocation a call can cost is the caller's: an engine that does not
|
|
41
|
+
* inline `geodesicDirect` into its caller boxes the two `number` arguments that
|
|
42
|
+
* are not small integers, two heap numbers per call.
|
|
43
|
+
*/
|
|
44
|
+
export declare function geodesicDirect(out: Geodetic, from: ReadonlyGeodetic, azimuthDeg: number, distanceM: number, ellipsoid: Ellipsoid): Geodetic;
|
|
45
|
+
/**
|
|
46
|
+
* Creates the geodesic line leaving `from` at `azimuthDeg`, to query with
|
|
47
|
+
* {@link geodesicLinePosition}, {@link geodesicLineAzimuth} and
|
|
48
|
+
* {@link geodesicLinePositions}. Its length is unknown:
|
|
49
|
+
* {@link geodesicLineDistance} gives `NaN`. Allocates the line's record (one
|
|
50
|
+
* `Float64Array`); build it once and query it many times.
|
|
51
|
+
*
|
|
52
|
+
* @throws {RangeError} For a non-finite start or azimuth, or a latitude beyond
|
|
53
|
+
* ±90°.
|
|
54
|
+
*/
|
|
55
|
+
export declare function geodesicLine(from: ReadonlyGeodetic, azimuthDeg: number, ellipsoid: Ellipsoid): GeodesicLine;
|
|
56
|
+
/**
|
|
57
|
+
* Creates the geodesic joining `from` to `to` (Karney's `InverseLine`), whose
|
|
58
|
+
* length {@link geodesicLineDistance} gives and whose position at that distance
|
|
59
|
+
* is `to`. Allocates the line's record (one `Float64Array`).
|
|
60
|
+
*
|
|
61
|
+
* @throws {RangeError} For a non-finite position, or a latitude beyond ±90°.
|
|
62
|
+
*/
|
|
63
|
+
export declare function geodesicLineBetween(from: ReadonlyGeodetic, to: ReadonlyGeodetic, ellipsoid: Ellipsoid): GeodesicLine;
|
|
64
|
+
/**
|
|
65
|
+
* The length in metres of a line made by {@link geodesicLineBetween}; `NaN` for
|
|
66
|
+
* one made by {@link geodesicLine}.
|
|
67
|
+
*/
|
|
68
|
+
export declare function geodesicLineDistance(line: GeodesicLine): number;
|
|
69
|
+
/**
|
|
70
|
+
* Writes the position, at height `0`, `distanceM` metres along `line` (negative
|
|
71
|
+
* goes backwards) into `out`. A non-finite distance gives `NaN`s. O(1).
|
|
72
|
+
*
|
|
73
|
+
* The solver allocates nothing, whether or not the engine inlines its helpers;
|
|
74
|
+
* an engine that does not inline `geodesicLinePosition` into its caller boxes
|
|
75
|
+
* `distanceM` unless it is a small integer, one heap number per call.
|
|
76
|
+
*/
|
|
77
|
+
export declare function geodesicLinePosition(out: Geodetic, line: GeodesicLine, distanceM: number): Geodetic;
|
|
78
|
+
/**
|
|
79
|
+
* The azimuth in degrees, clockwise from north in `(−180, 180]`, of `line`
|
|
80
|
+
* `distanceM` metres along it. A non-finite distance gives `NaN`. O(1). The
|
|
81
|
+
* solver allocates nothing; a caller that does not inline this function boxes a
|
|
82
|
+
* fractional `distanceM` and the returned azimuth, a heap number each.
|
|
83
|
+
*/
|
|
84
|
+
export declare function geodesicLineAzimuth(line: GeodesicLine, distanceM: number): number;
|
|
85
|
+
/**
|
|
86
|
+
* Writes the position at each distance of `distancesM` along `line` into `out`
|
|
87
|
+
* as geodetic triples `[longitudeDeg, latitudeDeg, 0, …]`: ready for the
|
|
88
|
+
* caller's heights and `ecefArrayFromGeodetic`, with no copy. O(n).
|
|
89
|
+
*
|
|
90
|
+
* `distancesM` may share memory with `out` (a view into it, say), whatever its
|
|
91
|
+
* class. Allocates nothing, whatever the engine inlines.
|
|
92
|
+
*
|
|
93
|
+
* @throws {RangeError} Unless `out` holds three numbers per distance.
|
|
94
|
+
*/
|
|
95
|
+
export declare function geodesicLinePositions<T extends Float64Array>(out: T, line: GeodesicLine, distancesM: Float64Array): T;
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=geodesic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geodesic.d.ts","sourceRoot":"","sources":["../src/geodesic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAgChD,OAAO,EACN,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,MAAM,eAAe,CAAC;AAMvB,OAAO,CAAC,MAAM,kBAAkB,EAAE,OAAO,MAAM,CAAC;AAEhD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AA2BnE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAC9B,GAAG,EAAE,eAAe,EACpB,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE,gBAAgB,EACpB,SAAS,EAAE,SAAS,GAClB,eAAe,CAmCjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,SAAS,GAClB,QAAQ,CA4BV;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,SAAS,GAClB,YAAY,CAsBd;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE,gBAAgB,EACpB,SAAS,EAAE,SAAS,GAClB,YAAY,CA+Bd;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,MAAM,GACf,QAAQ,CAUV;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,MAAM,GACf,MAAM,CAIR;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,YAAY,EAC3D,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,YAAY,EAClB,UAAU,EAAE,YAAY,GACtB,CAAC,CAwBH"}
|
package/dist/geodesic.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { atan2DegInPlace } from "@ac-kit/math-scalar";
|
|
2
|
+
import { scratchCreate_ } from "./geodesic/_angle.js";
|
|
3
|
+
import { constantsOf_ } from "./geodesic/_constants.js";
|
|
4
|
+
import { INVERSE_COS_ALPHA1_, INVERSE_DISTANCE_, INVERSE_LATITUDE1_, INVERSE_LATITUDE2_, INVERSE_LENGTH_, INVERSE_LONGITUDE1_, INVERSE_LONGITUDE2_, INVERSE_SIN_ALPHA1_, INVERSE_SIN_ALPHA2_, inverse_, } from "./geodesic/_inverse.js";
|
|
5
|
+
import { LINE_DISTANCE_, lineInitialize_, linePosition_, lineRecordCreate_, POSITION_AZIMUTH_, POSITION_DISTANCE_, POSITION_LATITUDE_, POSITION_LENGTH_, POSITION_LONGITUDE_, START_AZIMUTH_, START_COS_ALPHA_, START_LATITUDE_, START_LENGTH_, START_LONGITUDE_, START_SIN_ALPHA_, } from "./geodesic/_line.js";
|
|
6
|
+
const inverseScratch_ = scratchCreate_(INVERSE_LENGTH_);
|
|
7
|
+
const positionScratch_ = scratchCreate_(POSITION_LENGTH_);
|
|
8
|
+
const startScratch_ = scratchCreate_(START_LENGTH_);
|
|
9
|
+
const directLineScratch_ = lineRecordCreate_();
|
|
10
|
+
// The intrinsic `%TypedArray%.prototype` methods, captured once: a subclass can
|
|
11
|
+
// override `length` or `set` on its instances, but not these.
|
|
12
|
+
const TYPED_ARRAY_PROTOTYPE_ = Object.getPrototypeOf(Float64Array.prototype);
|
|
13
|
+
const typedArraySet_ = TYPED_ARRAY_PROTOTYPE_
|
|
14
|
+
.set;
|
|
15
|
+
const typedArrayLength_ = Object.getOwnPropertyDescriptor(TYPED_ARRAY_PROTOTYPE_, "length").get;
|
|
16
|
+
// Re-entrancy: the solvers share the module-level buffers above, and a
|
|
17
|
+
// caller's record may run code on access (a getter on an input, a setter on
|
|
18
|
+
// `out`) that calls a solver again. So every public function reads all its
|
|
19
|
+
// inputs into locals before writing a buffer, and reads all its results out of
|
|
20
|
+
// the buffers into locals before writing `out`. The positions are validated
|
|
21
|
+
// inline: a helper taking the coordinates as doubles would box them whenever
|
|
22
|
+
// it was not inlined.
|
|
23
|
+
/**
|
|
24
|
+
* Solves the inverse geodesic problem on `ellipsoid`: the shortest path from
|
|
25
|
+
* `from` to `to`, writing its length in metres and its azimuths at both ends,
|
|
26
|
+
* degrees clockwise from north in `(−180, 180]`, into `out`. Heights are
|
|
27
|
+
* ignored.
|
|
28
|
+
*
|
|
29
|
+
* Coincident points give a distance of `0` and `NaN` azimuths; a non-finite
|
|
30
|
+
* longitude or latitude, or a latitude beyond ±90°, gives all `NaN`. Accurate
|
|
31
|
+
* to 15 nanometres on WGS 84, nearly antipodal points included. Allocates
|
|
32
|
+
* nothing, whether or not the engine inlines the solver's helpers. O(1).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const out = geodesicInverseCreate();
|
|
37
|
+
* const origin = geodeticOf(0, 0, 0);
|
|
38
|
+
* geodesicInverse(out, origin, geodeticOf(-1, 0, 0), ELLIPSOID_WGS84);
|
|
39
|
+
* // out[0] ≈ 111319.49 m, out[1] = out[2] = -90 (due west)
|
|
40
|
+
* ```;
|
|
41
|
+
*/
|
|
42
|
+
export function geodesicInverse(out, from, to, ellipsoid) {
|
|
43
|
+
const longitude1 = from[0];
|
|
44
|
+
const latitude1 = from[1];
|
|
45
|
+
const longitude2 = to[0];
|
|
46
|
+
const latitude2 = to[1];
|
|
47
|
+
let distance = Number.NaN;
|
|
48
|
+
let azimuth1 = Number.NaN;
|
|
49
|
+
let azimuth2 = Number.NaN;
|
|
50
|
+
if (Number.isFinite(longitude1) &&
|
|
51
|
+
Math.abs(latitude1) <= 90 &&
|
|
52
|
+
Number.isFinite(longitude2) &&
|
|
53
|
+
Math.abs(latitude2) <= 90) {
|
|
54
|
+
const constants = constantsOf_(ellipsoid);
|
|
55
|
+
inverseScratch_[INVERSE_LATITUDE1_] = latitude1;
|
|
56
|
+
inverseScratch_[INVERSE_LONGITUDE1_] = longitude1;
|
|
57
|
+
inverseScratch_[INVERSE_LATITUDE2_] = latitude2;
|
|
58
|
+
inverseScratch_[INVERSE_LONGITUDE2_] = longitude2;
|
|
59
|
+
inverse_(constants, inverseScratch_);
|
|
60
|
+
distance = inverseScratch_[INVERSE_DISTANCE_];
|
|
61
|
+
if (distance !== 0) {
|
|
62
|
+
// Each azimuth's sine is followed by its cosine, the layout
|
|
63
|
+
// atan2DegInPlace reads; `+ 0` turns a −0 azimuth (due north from a
|
|
64
|
+
// west-going frame) into 0.
|
|
65
|
+
atan2DegInPlace(inverseScratch_, INVERSE_SIN_ALPHA1_);
|
|
66
|
+
atan2DegInPlace(inverseScratch_, INVERSE_SIN_ALPHA2_);
|
|
67
|
+
azimuth1 = inverseScratch_[INVERSE_SIN_ALPHA1_] + 0;
|
|
68
|
+
azimuth2 = inverseScratch_[INVERSE_SIN_ALPHA2_] + 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
out[0] = distance;
|
|
72
|
+
out[1] = azimuth1;
|
|
73
|
+
out[2] = azimuth2;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Solves the direct geodesic problem on `ellipsoid`: the end point, at height
|
|
78
|
+
* `0`, of the geodesic leaving `from` at `azimuthDeg` (degrees clockwise from
|
|
79
|
+
* north) and running `distanceM` metres (negative goes backwards). The
|
|
80
|
+
* longitude is in `[−180, 180]`. A non-finite input, or a latitude beyond ±90°,
|
|
81
|
+
* gives `NaN`s. Runs through a line held in a module-level buffer. O(1).
|
|
82
|
+
*
|
|
83
|
+
* The solver allocates nothing, whether or not the engine inlines its helpers.
|
|
84
|
+
* The only allocation a call can cost is the caller's: an engine that does not
|
|
85
|
+
* inline `geodesicDirect` into its caller boxes the two `number` arguments that
|
|
86
|
+
* are not small integers, two heap numbers per call.
|
|
87
|
+
*/
|
|
88
|
+
export function geodesicDirect(out, from, azimuthDeg, distanceM, ellipsoid) {
|
|
89
|
+
const longitude1 = from[0];
|
|
90
|
+
const latitude1 = from[1];
|
|
91
|
+
let longitude = Number.NaN;
|
|
92
|
+
let latitude = Number.NaN;
|
|
93
|
+
let height = Number.NaN;
|
|
94
|
+
if (Number.isFinite(longitude1) &&
|
|
95
|
+
Math.abs(latitude1) <= 90 &&
|
|
96
|
+
Number.isFinite(azimuthDeg) &&
|
|
97
|
+
Number.isFinite(distanceM)) {
|
|
98
|
+
const constants = constantsOf_(ellipsoid);
|
|
99
|
+
startScratch_[START_LATITUDE_] = latitude1;
|
|
100
|
+
startScratch_[START_LONGITUDE_] = longitude1;
|
|
101
|
+
startScratch_[START_AZIMUTH_] = azimuthDeg;
|
|
102
|
+
startScratch_[START_SIN_ALPHA_] = Number.NaN;
|
|
103
|
+
lineInitialize_(directLineScratch_, constants, startScratch_);
|
|
104
|
+
positionScratch_[POSITION_DISTANCE_] = distanceM;
|
|
105
|
+
linePosition_(directLineScratch_, positionScratch_);
|
|
106
|
+
longitude = positionScratch_[POSITION_LONGITUDE_];
|
|
107
|
+
latitude = positionScratch_[POSITION_LATITUDE_];
|
|
108
|
+
height = 0;
|
|
109
|
+
}
|
|
110
|
+
out[0] = longitude;
|
|
111
|
+
out[1] = latitude;
|
|
112
|
+
out[2] = height;
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates the geodesic line leaving `from` at `azimuthDeg`, to query with
|
|
117
|
+
* {@link geodesicLinePosition}, {@link geodesicLineAzimuth} and
|
|
118
|
+
* {@link geodesicLinePositions}. Its length is unknown:
|
|
119
|
+
* {@link geodesicLineDistance} gives `NaN`. Allocates the line's record (one
|
|
120
|
+
* `Float64Array`); build it once and query it many times.
|
|
121
|
+
*
|
|
122
|
+
* @throws {RangeError} For a non-finite start or azimuth, or a latitude beyond
|
|
123
|
+
* ±90°.
|
|
124
|
+
*/
|
|
125
|
+
export function geodesicLine(from, azimuthDeg, ellipsoid) {
|
|
126
|
+
const longitude1 = from[0];
|
|
127
|
+
const latitude1 = from[1];
|
|
128
|
+
if (!(Number.isFinite(longitude1) &&
|
|
129
|
+
Math.abs(latitude1) <= 90 &&
|
|
130
|
+
Number.isFinite(azimuthDeg))) {
|
|
131
|
+
throw new RangeError(`geodesicLine: the start (${longitude1}, ${latitude1}) and the azimuth ${azimuthDeg} must be finite, with a latitude within ±90°.`);
|
|
132
|
+
}
|
|
133
|
+
const constants = constantsOf_(ellipsoid);
|
|
134
|
+
const line = lineRecordCreate_();
|
|
135
|
+
startScratch_[START_LATITUDE_] = latitude1;
|
|
136
|
+
startScratch_[START_LONGITUDE_] = longitude1;
|
|
137
|
+
startScratch_[START_AZIMUTH_] = azimuthDeg;
|
|
138
|
+
startScratch_[START_SIN_ALPHA_] = Number.NaN;
|
|
139
|
+
lineInitialize_(line, constants, startScratch_);
|
|
140
|
+
return line; // a GeodesicLine is the scratch record itself, branded for the public type
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Creates the geodesic joining `from` to `to` (Karney's `InverseLine`), whose
|
|
144
|
+
* length {@link geodesicLineDistance} gives and whose position at that distance
|
|
145
|
+
* is `to`. Allocates the line's record (one `Float64Array`).
|
|
146
|
+
*
|
|
147
|
+
* @throws {RangeError} For a non-finite position, or a latitude beyond ±90°.
|
|
148
|
+
*/
|
|
149
|
+
export function geodesicLineBetween(from, to, ellipsoid) {
|
|
150
|
+
const longitude1 = from[0];
|
|
151
|
+
const latitude1 = from[1];
|
|
152
|
+
const longitude2 = to[0];
|
|
153
|
+
const latitude2 = to[1];
|
|
154
|
+
if (!(Number.isFinite(longitude1) &&
|
|
155
|
+
Math.abs(latitude1) <= 90 &&
|
|
156
|
+
Number.isFinite(longitude2) &&
|
|
157
|
+
Math.abs(latitude2) <= 90)) {
|
|
158
|
+
throw new RangeError(`geodesicLineBetween: both positions must be finite, with a latitude within ±90° (got (${longitude1}, ${latitude1}) and (${longitude2}, ${latitude2})).`);
|
|
159
|
+
}
|
|
160
|
+
const constants = constantsOf_(ellipsoid);
|
|
161
|
+
const line = lineRecordCreate_();
|
|
162
|
+
inverseScratch_[INVERSE_LATITUDE1_] = latitude1;
|
|
163
|
+
inverseScratch_[INVERSE_LONGITUDE1_] = longitude1;
|
|
164
|
+
inverseScratch_[INVERSE_LATITUDE2_] = latitude2;
|
|
165
|
+
inverseScratch_[INVERSE_LONGITUDE2_] = longitude2;
|
|
166
|
+
inverse_(constants, inverseScratch_);
|
|
167
|
+
startScratch_[START_LATITUDE_] = latitude1;
|
|
168
|
+
startScratch_[START_LONGITUDE_] = longitude1;
|
|
169
|
+
startScratch_[START_SIN_ALPHA_] = inverseScratch_[INVERSE_SIN_ALPHA1_];
|
|
170
|
+
startScratch_[START_COS_ALPHA_] = inverseScratch_[INVERSE_COS_ALPHA1_];
|
|
171
|
+
lineInitialize_(line, constants, startScratch_);
|
|
172
|
+
line[LINE_DISTANCE_] = inverseScratch_[INVERSE_DISTANCE_];
|
|
173
|
+
return line; // a GeodesicLine is the scratch record itself, branded for the public type
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The length in metres of a line made by {@link geodesicLineBetween}; `NaN` for
|
|
177
|
+
* one made by {@link geodesicLine}.
|
|
178
|
+
*/
|
|
179
|
+
export function geodesicLineDistance(line) {
|
|
180
|
+
return line[LINE_DISTANCE_]; // a GeodesicLine is the scratch record itself, branded for the public type
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Writes the position, at height `0`, `distanceM` metres along `line` (negative
|
|
184
|
+
* goes backwards) into `out`. A non-finite distance gives `NaN`s. O(1).
|
|
185
|
+
*
|
|
186
|
+
* The solver allocates nothing, whether or not the engine inlines its helpers;
|
|
187
|
+
* an engine that does not inline `geodesicLinePosition` into its caller boxes
|
|
188
|
+
* `distanceM` unless it is a small integer, one heap number per call.
|
|
189
|
+
*/
|
|
190
|
+
export function geodesicLinePosition(out, line, distanceM) {
|
|
191
|
+
positionScratch_[POSITION_DISTANCE_] = distanceM;
|
|
192
|
+
linePosition_(line, positionScratch_); // a GeodesicLine is the scratch record itself, branded for the public type
|
|
193
|
+
const longitude = positionScratch_[POSITION_LONGITUDE_];
|
|
194
|
+
const latitude = positionScratch_[POSITION_LATITUDE_];
|
|
195
|
+
out[0] = longitude;
|
|
196
|
+
out[1] = latitude;
|
|
197
|
+
// Height 0, or NaN with the rest when the distance was not finite.
|
|
198
|
+
out[2] = Number.isFinite(longitude + latitude) ? 0 : Number.NaN;
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The azimuth in degrees, clockwise from north in `(−180, 180]`, of `line`
|
|
203
|
+
* `distanceM` metres along it. A non-finite distance gives `NaN`. O(1). The
|
|
204
|
+
* solver allocates nothing; a caller that does not inline this function boxes a
|
|
205
|
+
* fractional `distanceM` and the returned azimuth, a heap number each.
|
|
206
|
+
*/
|
|
207
|
+
export function geodesicLineAzimuth(line, distanceM) {
|
|
208
|
+
positionScratch_[POSITION_DISTANCE_] = distanceM;
|
|
209
|
+
linePosition_(line, positionScratch_); // a GeodesicLine is the scratch record itself, branded for the public type
|
|
210
|
+
return positionScratch_[POSITION_AZIMUTH_];
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Writes the position at each distance of `distancesM` along `line` into `out`
|
|
214
|
+
* as geodetic triples `[longitudeDeg, latitudeDeg, 0, …]`: ready for the
|
|
215
|
+
* caller's heights and `ecefArrayFromGeodetic`, with no copy. O(n).
|
|
216
|
+
*
|
|
217
|
+
* `distancesM` may share memory with `out` (a view into it, say), whatever its
|
|
218
|
+
* class. Allocates nothing, whatever the engine inlines.
|
|
219
|
+
*
|
|
220
|
+
* @throws {RangeError} Unless `out` holds three numbers per distance.
|
|
221
|
+
*/
|
|
222
|
+
export function geodesicLinePositions(out, line, distancesM) {
|
|
223
|
+
const count = typedArrayLength_.call(distancesM);
|
|
224
|
+
if (typedArrayLength_.call(out) !== count * 3) {
|
|
225
|
+
throw new RangeError(`geodesicLinePositions: out must hold 3 numbers per distance (expected ${count * 3}, got ${typedArrayLength_.call(out)}).`);
|
|
226
|
+
}
|
|
227
|
+
// The distances are staged at the start of `out` by the intrinsic `set`,
|
|
228
|
+
// which copies correctly whatever the two views share and which no
|
|
229
|
+
// subclass or species can redirect; the positions are then written from the
|
|
230
|
+
// last, each over its own distance and later ones already read.
|
|
231
|
+
typedArraySet_.call(out, distancesM, 0);
|
|
232
|
+
const record = line; // a GeodesicLine is the scratch record itself, branded for the public type
|
|
233
|
+
for (let index = count - 1; index >= 0; index--) {
|
|
234
|
+
positionScratch_[POSITION_DISTANCE_] = out[index];
|
|
235
|
+
linePosition_(record, positionScratch_);
|
|
236
|
+
const longitude = positionScratch_[POSITION_LONGITUDE_];
|
|
237
|
+
const latitude = positionScratch_[POSITION_LATITUDE_];
|
|
238
|
+
const base = index * 3;
|
|
239
|
+
out[base] = longitude;
|
|
240
|
+
out[base + 1] = latitude;
|
|
241
|
+
out[base + 2] = Number.isFinite(longitude + latitude) ? 0 : Number.NaN;
|
|
242
|
+
}
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=geodesic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geodesic.js","sourceRoot":"","sources":["../src/geodesic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAiB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EACN,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,QAAQ,GACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,cAAc,EACd,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,qBAAqB,CAAC;AAoB7B,MAAM,eAAe,GAAG,cAAc,CAAC,eAAe,CAAC,CAAC;AACxD,MAAM,gBAAgB,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAAC;AAC1D,MAAM,aAAa,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC;AACpD,MAAM,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAE/C,gFAAgF;AAChF,8DAA8D;AAC9D,MAAM,sBAAsB,GAAG,MAAM,CAAC,cAAc,CACnD,YAAY,CAAC,SAAS,CACZ,CAAC;AACZ,M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,KAAK,GAAG,CAAC,CAAC;QACvB,GAAG,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;QACtB,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;QACzB,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IACxE,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { ReadonlyVec3, Vec3 } from "@ac-kit/math-linear";
|
|
2
|
+
import type { Brand_ } from "./_brand.js";
|
|
3
|
+
import type { Ellipsoid } from "./ellipsoid.js";
|
|
4
|
+
/**
|
|
5
|
+
* A position on the Earth in degrees and metres: `[longitudeDeg, latitudeDeg,
|
|
6
|
+
* heightM]`, the height above the ellipsoid along its normal. Longitude first,
|
|
7
|
+
* like a GeoJSON position, so a buffer of GeoJSON positions is already a buffer
|
|
8
|
+
* of these.
|
|
9
|
+
*
|
|
10
|
+
* A plain array of 3 binary64 numbers carrying a type-level brand, holding
|
|
11
|
+
* exactly the numbers one element of a geodetic buffer holds. Only
|
|
12
|
+
* {@link geodeticCreate}, {@link geodeticOf}, {@link geodeticClone},
|
|
13
|
+
* {@link geodeticFromArray} and the functions that write an `out` make one; see
|
|
14
|
+
* `Vec3` in `@ac-kit/math-linear` for the rules that bind callers who bypass
|
|
15
|
+
* the types.
|
|
16
|
+
*/
|
|
17
|
+
export type Geodetic = [
|
|
18
|
+
longitudeDeg: number,
|
|
19
|
+
latitudeDeg: number,
|
|
20
|
+
heightM: number
|
|
21
|
+
] & Brand_<"Geodetic">;
|
|
22
|
+
/** A {@link Geodetic} that is only read. */
|
|
23
|
+
export type ReadonlyGeodetic = readonly [
|
|
24
|
+
longitudeDeg: number,
|
|
25
|
+
latitudeDeg: number,
|
|
26
|
+
heightM: number
|
|
27
|
+
] & Brand_<"Geodetic">;
|
|
28
|
+
/**
|
|
29
|
+
* The solution of an inverse geodesic problem: the distance in metres, then the
|
|
30
|
+
* azimuths at both ends in degrees clockwise from north, in `(−180, 180]`.
|
|
31
|
+
*/
|
|
32
|
+
export type GeodesicInverse = [
|
|
33
|
+
distanceM: number,
|
|
34
|
+
azimuth1Deg: number,
|
|
35
|
+
azimuth2Deg: number
|
|
36
|
+
] & Brand_<"GeodesicInverse">;
|
|
37
|
+
/** A {@link GeodesicInverse} that is only read. */
|
|
38
|
+
export type ReadonlyGeodesicInverse = readonly [
|
|
39
|
+
distanceM: number,
|
|
40
|
+
azimuth1Deg: number,
|
|
41
|
+
azimuth2Deg: number
|
|
42
|
+
] & Brand_<"GeodesicInverse">;
|
|
43
|
+
/**
|
|
44
|
+
* Creates the position `[0, 0, 0]`.
|
|
45
|
+
*
|
|
46
|
+
* Allocates; keep it out of hot loops.
|
|
47
|
+
*/
|
|
48
|
+
export declare function geodeticCreate(): Geodetic;
|
|
49
|
+
/**
|
|
50
|
+
* Creates the position `longitudeDeg, latitudeDeg, heightM`.
|
|
51
|
+
*
|
|
52
|
+
* Allocates; keep it out of hot loops.
|
|
53
|
+
*/
|
|
54
|
+
export declare function geodeticOf(longitudeDeg: number, latitudeDeg: number, heightM: number): Geodetic;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a copy of `a`. Like every creator it starts from a clean array.
|
|
57
|
+
*
|
|
58
|
+
* Allocates; keep it out of hot loops.
|
|
59
|
+
*/
|
|
60
|
+
export declare function geodeticClone(a: ReadonlyGeodetic): Geodetic;
|
|
61
|
+
/** Writes the components, in storage order, into `out`. */
|
|
62
|
+
export declare function geodeticSet(out: Geodetic, longitudeDeg: number, latitudeDeg: number, heightM: number): Geodetic;
|
|
63
|
+
/** Writes a copy of `a` into `out`. `out` may be `a`. */
|
|
64
|
+
export declare function geodeticCopy(out: Geodetic, a: ReadonlyGeodetic): Geodetic;
|
|
65
|
+
/**
|
|
66
|
+
* Exact component-wise equality: `−0` equals `+0`, `NaN` equals nothing, itself
|
|
67
|
+
* included. A longitude of 180° and one of −180° are different numbers. See
|
|
68
|
+
* {@link geodeticIsClose} for a tolerant test.
|
|
69
|
+
*/
|
|
70
|
+
export declare function geodeticEquals(a: ReadonlyGeodetic, b: ReadonlyGeodetic): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Component-wise approximate equality: every pair differs by at most
|
|
73
|
+
* `tolerance`, the same absolute bound for degrees and metres (pass one that
|
|
74
|
+
* suits both, or compare the parts yourself). Longitudes are compared as
|
|
75
|
+
* numbers, not around the antimeridian.
|
|
76
|
+
*
|
|
77
|
+
* @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function geodeticIsClose(a: ReadonlyGeodetic, b: ReadonlyGeodetic, tolerance?: number): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The checked way in from untyped data: `source[offset … offset + 3)` copied
|
|
82
|
+
* into `out`, each element that is not a number written as `NaN`, an index past
|
|
83
|
+
* the end too. A cold path: buffers use {@link geodeticLoad}. `source` may be
|
|
84
|
+
* `out`. O(1).
|
|
85
|
+
*/
|
|
86
|
+
export declare function geodeticFromArray(out: Geodetic, source: ArrayLike<number>, offset?: number): Geodetic;
|
|
87
|
+
/**
|
|
88
|
+
* Whether every component is a finite number: the check after parsing untrusted
|
|
89
|
+
* data.
|
|
90
|
+
*/
|
|
91
|
+
export declare function geodeticIsFinite(value: ReadonlyGeodetic): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Writes element `index` of `array`, the numbers at `[index·3, index·3 + 3)`,
|
|
94
|
+
* into `out`. Each component is written as `+array[i]`, so an index past the
|
|
95
|
+
* end gives `NaN`, never `undefined`. O(1).
|
|
96
|
+
*/
|
|
97
|
+
export declare function geodeticLoad(out: Geodetic, array: Float64Array, index: number): Geodetic;
|
|
98
|
+
/**
|
|
99
|
+
* Writes `value` into `array` as element `index`. An element past the end of
|
|
100
|
+
* `array` writes nothing. O(1).
|
|
101
|
+
*/
|
|
102
|
+
export declare function geodeticStore(array: Float64Array, index: number, value: ReadonlyGeodetic): void;
|
|
103
|
+
/**
|
|
104
|
+
* Like {@link geodeticLoad} for interleaved data: element `index` starts at
|
|
105
|
+
* `offset + index·stride`, both counted in numbers. O(1).
|
|
106
|
+
*/
|
|
107
|
+
export declare function geodeticLoadStrided(out: Geodetic, array: Float64Array, offset: number, stride: number, index: number): Geodetic;
|
|
108
|
+
/**
|
|
109
|
+
* Like {@link geodeticStore} for interleaved data: element `index` starts at
|
|
110
|
+
* `offset + index·stride`, both counted in numbers. O(1).
|
|
111
|
+
*/
|
|
112
|
+
export declare function geodeticStoreStrided(array: Float64Array, offset: number, stride: number, index: number, value: ReadonlyGeodetic): void;
|
|
113
|
+
/**
|
|
114
|
+
* Whether every number of `array` is finite (`vec3ArrayIsFinite`: a buffer of
|
|
115
|
+
* triples). O(n).
|
|
116
|
+
*/
|
|
117
|
+
export declare function geodeticArrayIsFinite(array: Float64Array): boolean;
|
|
118
|
+
/** Creates the result `[0, 0, 0]`. Allocates; keep it out of hot loops. */
|
|
119
|
+
export declare function geodesicInverseCreate(): GeodesicInverse;
|
|
120
|
+
/** Creates the result `distanceM, azimuth1Deg, azimuth2Deg`. Allocates. */
|
|
121
|
+
export declare function geodesicInverseOf(distanceM: number, azimuth1Deg: number, azimuth2Deg: number): GeodesicInverse;
|
|
122
|
+
/** Creates a copy of `a`. Allocates. */
|
|
123
|
+
export declare function geodesicInverseClone(a: ReadonlyGeodesicInverse): GeodesicInverse;
|
|
124
|
+
/** Writes the components into `out`. */
|
|
125
|
+
export declare function geodesicInverseSet(out: GeodesicInverse, distanceM: number, azimuth1Deg: number, azimuth2Deg: number): GeodesicInverse;
|
|
126
|
+
/** Writes a copy of `a` into `out`. `out` may be `a`. */
|
|
127
|
+
export declare function geodesicInverseCopy(out: GeodesicInverse, a: ReadonlyGeodesicInverse): GeodesicInverse;
|
|
128
|
+
/** Exact component-wise equality: `NaN` equals nothing, itself included. */
|
|
129
|
+
export declare function geodesicInverseEquals(a: ReadonlyGeodesicInverse, b: ReadonlyGeodesicInverse): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Component-wise approximate equality with one absolute `tolerance` for the
|
|
132
|
+
* metres and the degrees. Azimuths are compared as numbers, not around ±180°.
|
|
133
|
+
*
|
|
134
|
+
* @param tolerance Defaults to `geometryConfig.defaultLinearTolerance`.
|
|
135
|
+
*/
|
|
136
|
+
export declare function geodesicInverseIsClose(a: ReadonlyGeodesicInverse, b: ReadonlyGeodesicInverse, tolerance?: number): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Whether every component is a finite number: `false` for the `NaN` result of
|
|
139
|
+
* an undefined problem.
|
|
140
|
+
*/
|
|
141
|
+
export declare function geodesicInverseIsFinite(value: ReadonlyGeodesicInverse): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Writes the Earth-centred, Earth-fixed coordinates, metres, of the geodetic
|
|
144
|
+
* `position` on `ellipsoid` into `out`: x through the equator at longitude 0, z
|
|
145
|
+
* through the north pole.
|
|
146
|
+
*
|
|
147
|
+
* The closed form `x = (N + h)·cosφ·cosλ`, `y = (N + h)·cosφ·sinλ`, `z = (N(1 −
|
|
148
|
+
* e²) + h)·sinφ` with the prime-vertical radius `N = a / √(cos²φ + (1 −
|
|
149
|
+
* f)²·sin²φ)`, using the polar ratio `1 − f` itself so that an extreme
|
|
150
|
+
* flattening (whose `e²` rounds to 1) still works. Each angle is reduced
|
|
151
|
+
* exactly in degrees to within 45° of a multiple of 90°, as `sinDeg` does; the
|
|
152
|
+
* remainder's sine comes from `Math.sin` and its cosine from `√(1 − sin²)`, so
|
|
153
|
+
* the poles and the cardinal meridians are exact. Each coordinate is within
|
|
154
|
+
* `5·2⁻⁵³·(a + |h|)` of the exact value, 3.5 nm at sea level (see the README).
|
|
155
|
+
* A component that is not finite gives `NaN` in all three; any finite height
|
|
156
|
+
* works. O(1).
|
|
157
|
+
*/
|
|
158
|
+
export declare function ecefFromGeodetic(out: Vec3, position: ReadonlyGeodetic, ellipsoid: Ellipsoid): Vec3;
|
|
159
|
+
/**
|
|
160
|
+
* Writes the geodetic position of the Earth-centred point `point`, metres, on
|
|
161
|
+
* `ellipsoid` into `out`: longitude in `(−180, 180]`, latitude in `[−90, 90]`,
|
|
162
|
+
* and the height along the ellipsoid normal.
|
|
163
|
+
*
|
|
164
|
+
* Vermeille's closed form (J. Geodesy 76 (2002) 451–454, which solves a quartic
|
|
165
|
+
* for the latitude without iteration) gives the latitude, to 1e−13°. The height
|
|
166
|
+
* is the offset of the point from its foot on the ellipsoid along the normal,
|
|
167
|
+
* which is stationary in the latitude, evaluated in double-double arithmetic
|
|
168
|
+
* (`_ecef-height.ts`): the rounding of 6 400 km terms, 1 to 3 nm in plain
|
|
169
|
+
* doubles, costs nothing. Against 80-digit references of the exact point, for
|
|
170
|
+
* heights from −6 000 km to 10 000 km: see the README. The centre of the Earth
|
|
171
|
+
* has no geodetic position, and a component that is not finite gives `NaN` in
|
|
172
|
+
* all three. Valid for coordinates within `[1e−150, 1e150]`: the squares stay
|
|
173
|
+
* finite, and far from the Earth the quartic, which depends only on `p/e⁴` and
|
|
174
|
+
* `q/e⁴`, is scaled by a power of two so its cubes do not overflow. Allocates
|
|
175
|
+
* nothing, whatever the engine inlines: no double crosses a call. O(1).
|
|
176
|
+
*/
|
|
177
|
+
export declare function geodeticFromEcef(out: Geodetic, point: ReadonlyVec3, ellipsoid: Ellipsoid): Geodetic;
|
|
178
|
+
/**
|
|
179
|
+
* Writes the Earth-centred coordinates of every geodetic triple of `input`
|
|
180
|
+
* (`[longitudeDeg, latitudeDeg, heightM, …]`) into `out` (as
|
|
181
|
+
* {@link ecefFromGeodetic}), the count taken from the length. `out` may be
|
|
182
|
+
* `input` (in place). O(n).
|
|
183
|
+
*
|
|
184
|
+
* @throws {RangeError} Unless both have the same length, a multiple of 3.
|
|
185
|
+
*/
|
|
186
|
+
export declare function ecefArrayFromGeodetic<T extends Float64Array>(out: T, input: Float64Array, ellipsoid: Ellipsoid): T;
|
|
187
|
+
/**
|
|
188
|
+
* Writes the geodetic triple of every Earth-centred point of `input` into `out`
|
|
189
|
+
* (as {@link geodeticFromEcef}), the count taken from the length. `out` may be
|
|
190
|
+
* `input` (in place). O(n).
|
|
191
|
+
*
|
|
192
|
+
* @throws {RangeError} Unless both have the same length, a multiple of 3.
|
|
193
|
+
*/
|
|
194
|
+
export declare function geodeticArrayFromEcef<T extends Float64Array>(out: T, input: Float64Array, ellipsoid: Ellipsoid): T;
|
|
195
|
+
//# sourceMappingURL=geodetic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geodetic.d.ts","sourceRoot":"","sources":["../src/geodetic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAQ9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAY1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQhD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,QAAQ,GAAG;IACtB,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,MAAM;IACnB,OAAO,EAAE,MAAM;CACf,GACA,MAAM,CAAC,UAAU,CAAC,CAAC;AAEpB,4CAA4C;AAC5C,MAAM,MAAM,gBAAgB,GAAG,SAAS;IACvC,YAAY,EAAE,MAAM;IACpB,WAAW,EAAE,MAAM;IACnB,OAAO,EAAE,MAAM;CACf,GACA,MAAM,CAAC,UAAU,CAAC,CAAC;AAEpB;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,SAAS,EAAE,MAAM;IACjB,WAAW,EAAE,MAAM;IACnB,WAAW,EAAE,MAAM;CACnB,GACA,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAE3B,mDAAmD;AACnD,MAAM,MAAM,uBAAuB,GAAG,S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