forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EllipsoidTangentPlaneSpec.js
192 lines (163 loc) · 8.5 KB
/
EllipsoidTangentPlaneSpec.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*global defineSuite*/
defineSuite([
'Core/EllipsoidTangentPlane',
'Core/Cartesian2',
'Core/Cartesian3',
'Core/Cartographic',
'Core/Ellipsoid'
], function(
EllipsoidTangentPlane,
Cartesian2,
Cartesian3,
Cartographic,
Ellipsoid) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/
it('constructor defaults to WGS84', function() {
var origin = new Cartesian3(Ellipsoid.WGS84.radii.x, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin);
expect(tangentPlane.ellipsoid).toBe(Ellipsoid.WGS84);
expect(tangentPlane.origin).toEqual(origin);
});
it('constructor sets expected values', function() {
var tangentPlane = new EllipsoidTangentPlane(Cartesian3.UNIT_X, Ellipsoid.UNIT_SPHERE);
expect(tangentPlane.ellipsoid).toBe(Ellipsoid.UNIT_SPHERE);
expect(tangentPlane.origin).toEqual(Cartesian3.UNIT_X);
});
it('fromPoints sets expected values', function() {
var points = [new Cartesian3(2, 0, 0), new Cartesian3(0, 0, 0)];
var tangentPlane = EllipsoidTangentPlane.fromPoints(points, Ellipsoid.UNIT_SPHERE);
expect(tangentPlane.ellipsoid).toBe(Ellipsoid.UNIT_SPHERE);
expect(tangentPlane.origin).toEqual(Cartesian3.UNIT_X);
});
it('projectPointOntoPlane returns undefined for points not on the plane', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = new Cartesian3(0, 0, 1);
var returnedResult = tangentPlane.projectPointOntoPlane(positions);
expect(returnedResult).toBeUndefined();
});
it('projectPointOntoPlane works without a result parameter', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = new Cartesian3(1, 0, 1);
var expectedResult = new Cartesian2(0, 1);
var returnedResult = tangentPlane.projectPointOntoPlane(positions);
expect(returnedResult).toEqual(expectedResult);
});
it('projectPointOntoPlane works with a result parameter', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = new Cartesian3(1, 0, 1);
var expectedResult = new Cartesian2(0, 1);
var result = new Cartesian2();
var returnedResult = tangentPlane.projectPointOntoPlane(positions, result);
expect(result).toBe(returnedResult);
expect(returnedResult).toEqual(expectedResult);
});
it('projectPointsOntoPlane works without a result parameter', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = [new Cartesian3(1, 0, 1), new Cartesian3(1, 0, 0), new Cartesian3(1, 1, 0)];
var expectedResults = [new Cartesian2(0, 1), new Cartesian2(0, 0), new Cartesian2(1, 0)];
var returnedResults = tangentPlane.projectPointsOntoPlane(positions);
expect(returnedResults).toEqual(expectedResults);
});
it('projectPointsOntoPlane works with a result parameter', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = [new Cartesian3(1, 0, 1), new Cartesian3(1, 0, 0), new Cartesian3(1, 1, 0)];
var expectedResults = [new Cartesian2(0, 1), new Cartesian2(0, 0), new Cartesian2(1, 0)];
var index0 = new Cartesian2();
var result = [index0];
var returnedResults = tangentPlane.projectPointsOntoPlane(positions, result);
expect(result).toBe(returnedResults);
expect(result[0]).toBe(index0);
expect(returnedResults).toEqual(expectedResults);
});
it('projectPointsOntoPlane works when some points not on plane', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = [new Cartesian3(1, 0, 1), new Cartesian3(1, 0, 0), new Cartesian3(0, 0, 1), new Cartesian3(1, 1, 0), new Cartesian3(0, 1, 0)];
var expectedResults = [new Cartesian2(0, 1), new Cartesian2(0, 0), new Cartesian2(1, 0)];
var returnedResults = tangentPlane.projectPointsOntoPlane(positions);
expect(returnedResults).toEqual(expectedResults);
});
it('projectPointsOntoEllipsoid works without a result parameter', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = [new Cartesian3(2, -2, 0), new Cartesian3(2, 2, 0)];
var expectedResults = [new Cartesian3(1/3, 2/3, -2/3), new Cartesian3(1/3, 2/3, 2/3)];
var returnedResults = tangentPlane.projectPointsOntoEllipsoid(positions);
expect(returnedResults).toEqual(expectedResults);
});
it('projectPointsOntoEllipsoid works with a result parameter', function () {
var ellipsoid = Ellipsoid.UNIT_SPHERE;
var origin = new Cartesian3(1, 0, 0);
var tangentPlane = new EllipsoidTangentPlane(origin, ellipsoid);
var positions = [new Cartesian3(2, -2, 0), new Cartesian3(2, 2, 0)];
var expectedResults = [new Cartesian3(1/3, 2/3, -2/3), new Cartesian3(1/3, 2/3, 2/3)];
var index0 = new Cartesian3();
var result = [index0];
var returnedResults = tangentPlane.projectPointsOntoEllipsoid(positions, result);
expect(result).toBe(returnedResults);
expect(result[0]).toBe(index0);
expect(returnedResults).toEqual(expectedResults);
});
it('constructor throws without origin', function() {
expect(function() {
return new EllipsoidTangentPlane(undefined, Ellipsoid.WGS84);
}).toThrowDeveloperError();
});
it('constructor throws if origin is at the center of the ellipsoid', function() {
expect(function() {
return new EllipsoidTangentPlane(Cartesian3.ZERO, Ellipsoid.WGS84);
}).toThrowDeveloperError();
});
it('fromPoints throws without cartesians', function() {
expect(function() {
return EllipsoidTangentPlane.fromPoints(undefined, Ellipsoid.WGS84);
}).toThrowDeveloperError();
});
it('projectPointOntoPlane throws without cartesian', function() {
var tangentPlane = new EllipsoidTangentPlane(Cartesian3.UNIT_X, Ellipsoid.UNIT_SPHERE);
expect(function() {
return tangentPlane.projectPointOntoPlane(undefined);
}).toThrowDeveloperError();
});
it('projectPointsOntoPlane throws without cartesians', function() {
var tangentPlane = new EllipsoidTangentPlane(Cartesian3.UNIT_X, Ellipsoid.UNIT_SPHERE);
expect(function() {
return tangentPlane.projectPointsOntoPlane(undefined);
}).toThrowDeveloperError();
});
it('projectPointsOntoEllipsoid throws without cartesians', function() {
var tangentPlane = new EllipsoidTangentPlane(Cartesian3.UNIT_X, Ellipsoid.UNIT_SPHERE);
expect(function() {
return tangentPlane.projectPointsOntoEllipsoid(undefined);
}).toThrowDeveloperError();
});
it('projectPointsOntoEllipsoid works with an arbitrary ellipsoid using fromPoints', function () {
var ellipsoid = Ellipsoid.WGS84;
var points = ellipsoid.cartographicArrayToCartesianArray([
Cartographic.fromDegrees(-72.0, 40.0),
Cartographic.fromDegrees(-68.0, 35.0),
Cartographic.fromDegrees(-75.0, 30.0),
Cartographic.fromDegrees(-70.0, 30.0),
Cartographic.fromDegrees(-68.0, 40.0)
]);
var tangentPlane = EllipsoidTangentPlane.fromPoints(points, ellipsoid);
var points2D = tangentPlane.projectPointsOntoPlane(points);
var positionsBack = tangentPlane.projectPointsOntoEllipsoid(points2D);
expect(positionsBack[0].x).toBeCloseTo(points[0].x);
expect(positionsBack[0].y).toBeCloseTo(points[0].y);
expect(positionsBack[0].z).toBeCloseTo(points[0].z);
});
});