Skip to content

Commit

Permalink
Merge pull request #268 from AnalyticalGraphicsInc/dynamicPositionIssue
Browse files Browse the repository at this point in the history
Dynamic position issue
  • Loading branch information
shunter committed Sep 26, 2012
2 parents 90be092 + 7097aea commit 910f94a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
18 changes: 13 additions & 5 deletions Source/DynamicScene/DynamicPositionProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,17 @@ define([
for (t = 0; t < times.length; t++) {
current = times[t];
if (!steppedOnNow && current.greaterThanOrEquals(currentTime)) {
result[r] = property.getValue(currentTime, result[r++]);
tmp = property.getValue(currentTime, result[r]);
if (typeof tmp !== 'undefined') {
result[r++] = tmp;
}
steppedOnNow = true;
}
if (current.greaterThan(start) && current.lessThan(loopStop)) {
result[r] = property.getValue(current, result[r++]);
tmp = property.getValue(current, result[r]);
if (typeof tmp !== 'undefined') {
result[r++] = tmp;
}
}
}
} else {
Expand Down Expand Up @@ -255,7 +261,10 @@ define([
//Finally, get the value at this non-sampled interval.
if (current.lessThan(loopStop)) {
if (valueType === CzmlCartesian3) {
result[r] = property.getValue(current, result[r++]);
tmp = property.getValue(current, result[r]);
if (typeof tmp !== 'undefined') {
result[r++] = tmp;
}
} else {
scratchCartographic = property.getValue(current, scratchCartographic);
result[r++] = wgs84.cartographicToCartesian(scratchCartographic);
Expand Down Expand Up @@ -322,8 +331,7 @@ define([

//We could handle the data, add it to the property.
if (typeof unwrappedInterval !== 'undefined') {
property._addCzmlIntervalUnwrapped(iso8601Interval.start, iso8601Interval.stop, unwrappedInterval, czmlInterval.epoch, czmlInterval.interpolationAlgorithm,
czmlInterval.interpolationDegree);
property._addCzmlIntervalUnwrapped(iso8601Interval.start, iso8601Interval.stop, unwrappedInterval, czmlInterval.epoch, czmlInterval.interpolationAlgorithm, czmlInterval.interpolationDegree);
}
};

Expand Down
15 changes: 9 additions & 6 deletions Source/DynamicScene/DynamicProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ define([
LagrangePolynomialApproximation) {
"use strict";


//CZML_TODO This is more of an idea than a to-do, but currently DynamicProperty requires
//you know the type of data being loaded up-front by passing valueType. We could take
//a similar approach to DynamicMaterialProperty and have a list of potential valueTypes
Expand All @@ -33,10 +34,10 @@ define([

//Map CZML interval types to their implementation.
var interpolators = {
HERMITE : HermitePolynomialApproximation,
LAGRANGE : LagrangePolynomialApproximation,
LINEAR : LinearApproximation
};
HERMITE : HermitePolynomialApproximation,
LAGRANGE : LagrangePolynomialApproximation,
LINEAR : LinearApproximation
};

//The data associated with each DynamicProperty interval.
function IntervalData() {
Expand Down Expand Up @@ -159,8 +160,10 @@ define([
var values = intervalData.values;
if (intervalData.isSampled && times.length >= 0 && values.length > 0) {
var index = binarySearch(times, time, JulianDate.compare);

if (index < 0) {
if (intervalData.numberOfPoints < 2) {
return undefined;
}
index = ~index;

if (index >= times.length) {
Expand Down Expand Up @@ -321,7 +324,7 @@ define([
interpolationAlgorithm = interpolators[interpolationAlgorithmType];
intervalData.interpolationAlgorithm = interpolationAlgorithm;
}
if (typeof interpolationAlgorithm !== 'undefined '&& typeof interpolationDegree !== 'undefined') {
if (typeof interpolationAlgorithm !== 'undefined' && typeof interpolationDegree !== 'undefined') {
intervalData.interpolationDegree = interpolationDegree;
intervalData.xTable = undefined;
intervalData.yTable = undefined;
Expand Down
15 changes: 15 additions & 0 deletions Specs/DynamicScene/DynamicPropertySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ defineSuite([
expect(result.w).toEqual(0);
});

it('Returns undefined if trying to interpolate with less than two samples.', function() {
var iso8601Epoch = '2012-04-18T15:59:00Z';
var epoch = JulianDate.fromIso8601(iso8601Epoch);

var property = new DynamicProperty(CzmlNumber);
var czmlInterval = {
epoch : iso8601Epoch,
number : [0, 0]
};
property.processCzmlIntervals(czmlInterval);

expect(property.getValue(epoch)).toEqual(0);
expect(property.getValue(epoch.addSeconds(4))).toBeUndefined();
});

it('_mergeNewSamples works for sorted non-intersecting data.', function() {
var times = [];
var values = [];
Expand Down
2 changes: 1 addition & 1 deletion Specs/Renderer/CommandSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global defineSuite*/
defineSuite([
'Renderer/Command',
'Renderer/Command'
], function(
Command) {
"use strict";
Expand Down

0 comments on commit 910f94a

Please sign in to comment.