forked from CesiumGS/cesium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NearFarScalar.js
182 lines (165 loc) · 6.05 KB
/
NearFarScalar.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
/*global define*/
define([
'./defaultValue',
'./defined',
'./DeveloperError'
], function(
defaultValue,
defined,
DeveloperError) {
"use strict";
/**
* Represents a scalar value's lower and upper bound at a near distance and far distance in eye space.
* @alias NearFarScalar
* @constructor
*
* @param {Number} [near=0.0] The lower bound of the camera range.
* @param {Number} [nearValue=0.0] The value at the lower bound of the camera range.
* @param {Number} [far=1.0] The upper bound of the camera range.
* @param {Number} [farValue=0.0] The value at the upper bound of the camera range.
*
* @see Packable
*/
var NearFarScalar = function(near, nearValue, far, farValue) {
/**
* The lower bound of the camera range.
* @type {Number}
* @default 0.0
*/
this.near = defaultValue(near, 0.0);
/**
* The value at the lower bound of the camera range.
* @type {Number}
* @default 0.0
*/
this.nearValue = defaultValue(nearValue, 0.0);
/**
* The upper bound of the camera range.
* @type {Number}
* @default 1.0
*/
this.far = defaultValue(far, 1.0);
/**
* The value at the upper bound of the camera range.
* @type {Number}
* @default 0.0
*/
this.farValue = defaultValue(farValue, 0.0);
};
/**
* Duplicates a NearFarScalar instance.
* @memberof NearFarScalar
*
* @param {NearFarScalar} nearFarScalar The NearFarScalar to duplicate.
* @param {NearFarScalar} [result] The object onto which to store the result.
* @returns {NearFarScalar} The modified result parameter or a new NearFarScalar instance if one was not provided. (Returns undefined if nearFarScalar is undefined)
*/
NearFarScalar.clone = function(nearFarScalar, result) {
if (!defined(nearFarScalar)) {
return undefined;
}
if (!defined(result)) {
return new NearFarScalar(nearFarScalar.near, nearFarScalar.nearValue, nearFarScalar.far, nearFarScalar.farValue);
}
result.near = nearFarScalar.near;
result.nearValue = nearFarScalar.nearValue;
result.far = nearFarScalar.far;
result.farValue = nearFarScalar.farValue;
return result;
};
/**
* The number of elements used to pack the object into an array.
* @Type {Number}
*/
NearFarScalar.packedLength = 4;
/**
* Stores the provided instance into the provided array.
* @memberof NearFarScalar
*
* @param {NearFarScalar} value The value to pack.
* @param {Array} array The array to pack into.
* @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
*
* @exception {DeveloperError} value is required.
* @exception {DeveloperError} array is required.
*/
NearFarScalar.pack = function(value, array, startingIndex) {
if (!defined(value)) {
throw new DeveloperError('value is required');
}
if (!defined(array)) {
throw new DeveloperError('array is required');
}
startingIndex = defaultValue(startingIndex, 0);
array[startingIndex++] = value.near;
array[startingIndex++] = value.nearValue;
array[startingIndex++] = value.far;
array[startingIndex] = value.farValue;
};
/**
* Retrieves an instance from a packed array.
* @memberof NearFarScalar
*
* @param {Array} array The packed array.
* @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
* @param {NearFarScalar} [result] The object into which to store the result.
*
* @exception {DeveloperError} array is required.
*/
NearFarScalar.unpack = function(array, startingIndex, result) {
if (!defined(array)) {
throw new DeveloperError('array is required');
}
startingIndex = defaultValue(startingIndex, 0);
if (!defined(result)) {
result = new NearFarScalar();
}
result.near = array[startingIndex++];
result.nearValue = array[startingIndex++];
result.far = array[startingIndex++];
result.farValue = array[startingIndex];
return result;
};
/**
* Compares the provided NearFarScalar and returns <code>true</code> if they are equal,
* <code>false</code> otherwise.
* @memberof NearFarScalar
*
* @param {NearFarScalar} [left] The first NearFarScalar.
* @param {NearFarScalar} [right] The second NearFarScalar.
*
* @returns {Boolean} <code>true</code> if left and right are equal; otherwise <code>false</code>.
*/
NearFarScalar.equals = function(left, right) {
return (left === right) ||
((defined(left)) &&
(defined(right)) &&
(left.near === right.near) &&
(left.nearValue === right.nearValue) &&
(left.far === right.far) &&
(left.farValue === right.farValue));
};
/**
* Duplicates this instance.
* @memberof NearFarScalar
*
* @param {NearFarScalar} [result] The object onto which to store the result.
* @returns {NearFarScalar} The modified result parameter or a new NearFarScalar instance if one was not provided.
*/
NearFarScalar.prototype.clone = function(result) {
return NearFarScalar.clone(this, result);
};
/**
* Compares this instance to the provided NearFarScalar and returns <code>true</code> if they are equal,
* <code>false</code> otherwise.
* @memberof NearFarScalar
*
* @param {NearFarScalar} [right] The right hand side NearFarScalar.
*
* @returns {Boolean} <code>true</code> if left and right are equal; otherwise <code>false</code>.
*/
NearFarScalar.prototype.equals = function(right) {
return NearFarScalar.equals(this, right);
};
return NearFarScalar;
});