/
AdditionalTransform.ts
138 lines (121 loc) · 5.08 KB
/
AdditionalTransform.ts
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Geometry
*/
// cspell:ignore Helmert
import { Geometry } from "@itwin/core-geometry";
/** An affine transformation with an additional Z Offset.
* The equations are:
* given a = scale * cos(rotation) and b = scale * sin(rotation)
* X = a * x - b * y + translationX
* Y = b * x + a * y + translationY
* Z = z + translationZ
* @public
* @extensions
*/
export interface Helmert2DWithZOffsetProps {
/** The X post translation */
translationX: number;
/** The Y post-translation */
translationY: number;
/** The Z post-translation or Z offset*/
translationZ: number;
/** The rotation in the trigonometric (CCW) direction in degrees. */
rotDeg: number;
/** The scale. This scale applies to both X and Y axises. Does not apply to Z. */
scale: number;
}
/** An affine transformation with an additional Z Offset.
* The equations are:
* given a = scale * cos(rotation) and b = scale * sin(rotation)
* X = a * x - b * y + translationX
* Y = b * x + a * y + translationY
* Z = z + translationZ
*
* Note that the class only implements the definition and not the operation.
* @public
*/
export class Helmert2DWithZOffset implements Helmert2DWithZOffsetProps {
/** The X post translation */
public translationX!: number;
/** The Y post-translation */
public translationY!: number;
/** The Z post-translation or Z offset*/
public translationZ!: number;
/** The rotation in the trigonometric (CCW) direction in degrees. */
public rotDeg!: number;
/** The scale. This scale applies to both X and Y axises. Does not apply to Z. */
public scale!: number;
constructor(data?: Helmert2DWithZOffsetProps) {
if (data) {
this.translationX = data.translationX;
this.translationY = data.translationY;
this.translationZ = data.translationZ;
this.rotDeg = data.rotDeg;
this.scale = data.scale;
}
}
/** Creates an Helmert Transform from JSON representation.
* @public */
public static fromJSON(data: Helmert2DWithZOffsetProps): Helmert2DWithZOffset {
return new Helmert2DWithZOffset(data);
}
/** Creates a JSON from the Helmert Transform definition
* @public */
public toJSON(): Helmert2DWithZOffsetProps {
return { translationX: this.translationX, translationY: this.translationY, translationZ: this.translationZ, rotDeg: this.rotDeg, scale: this.scale };
}
/** Compares two Helmert2DWithZOffset objects applying a minuscule tolerance.
* @public */
public equals(other: Helmert2DWithZOffset): boolean {
return (Math.abs(this.translationX - other.translationX) < Geometry.smallMetricDistance &&
Math.abs(this.translationY - other.translationY) < Geometry.smallMetricDistance &&
Math.abs(this.translationZ - other.translationZ) < Geometry.smallMetricDistance &&
Math.abs(this.rotDeg - other.rotDeg) < Geometry.smallAngleDegrees &&
Math.abs(this.scale - other.scale) < Geometry.smallFraction);
}
}
/** Additional Transform definition
* @public
* @extensions
*/
export interface AdditionalTransformProps {
/** The properties of a 2D Helmert transform with Z offset if one is defined. */
helmert2DWithZOffset?: Helmert2DWithZOffsetProps;
}
/** Additional Transform implementation.
* An additional transform is a transformation that can apply to either the horizontal or vertical coordinates of a
* geographic CRS. The transformation is applied after the latitude/longitude have been projected thus the process
* is applied to the result Cartesian coordinates of the projection process.
* @public
*/
export class AdditionalTransform implements AdditionalTransformProps {
/** The properties of a 2D Helmert transform with Z offset if one is defined. */
public readonly helmert2DWithZOffset?: Helmert2DWithZOffset;
public constructor(data?: AdditionalTransformProps) {
if (data)
this.helmert2DWithZOffset = data.helmert2DWithZOffset ? Helmert2DWithZOffset.fromJSON(data.helmert2DWithZOffset) : undefined;
}
/** Creates an Additional Transform from JSON representation.
* @public */
public static fromJSON(data: AdditionalTransformProps): AdditionalTransform {
return new AdditionalTransform(data);
}
/** Creates a JSON from the Additional Transform definition
* @public */
public toJSON(): AdditionalTransformProps {
return { helmert2DWithZOffset: this.helmert2DWithZOffset };
}
/** Compares two additional transforms applying a minuscule tolerance to comparing numbers.
* @public */
public equals(other: AdditionalTransform): boolean {
if ((this.helmert2DWithZOffset === undefined) !== (other.helmert2DWithZOffset === undefined))
return false;
if (this.helmert2DWithZOffset && !this.helmert2DWithZOffset.equals(other.helmert2DWithZOffset!))
return false;
return true;
}
}