Skip to content

Commit

Permalink
Merge pull request #12099 from anne-gropler/main
Browse files Browse the repository at this point in the history
Make time parameter optional for Property
  • Loading branch information
ggetz authored Aug 2, 2024
2 parents 2a1dbe2 + ea3edb3 commit 0a69f67
Show file tree
Hide file tree
Showing 41 changed files with 251 additions and 90 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

### 1.121 - 2024-09-01

#### @cesium/engine

##### Additions :tada:

- Made the `time` parameter optional for `Property`, using `JulianDate.now()` as default. [#12099](https://github.com/CesiumGS/cesium/pull/12099)

### 1.120 - 2024-08-01

#### @cesium/engine
Expand Down
10 changes: 8 additions & 2 deletions packages/engine/Source/DataSources/CallbackProperty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";

/**
* A {@link Property} whose value is lazily evaluated by a callback function.
Expand Down Expand Up @@ -46,14 +47,19 @@ Object.defineProperties(CallbackProperty.prototype, {
},
});

const timeScratch = new JulianDate();

/**
* Gets the value of the property.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied or is unsupported.
*/
CallbackProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
return this._callback(time, result);
};

Expand Down Expand Up @@ -104,7 +110,7 @@ CallbackProperty.prototype.equals = function (other) {
* A function that returns the value of the property.
* @callback CallbackProperty.Callback
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into. If omitted, the function must create and return a new instance.
* @returns {object} The modified result parameter, or a new instance if the result parameter was not supplied or is unsupported.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Color from "../Core/Color.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import createPropertyDescriptor from "./createPropertyDescriptor.js";
import Property from "./Property.js";

Expand Down Expand Up @@ -105,14 +106,19 @@ CheckerboardMaterialProperty.prototype.getType = function (time) {
return "Checkerboard";
};

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
CheckerboardMaterialProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
if (!defined(result)) {
result = {};
}
Expand Down
8 changes: 7 additions & 1 deletion packages/engine/Source/DataSources/ColorMaterialProperty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Color from "../Core/Color.js";
import defined from "../Core/defined.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import createPropertyDescriptor from "./createPropertyDescriptor.js";
import Property from "./Property.js";

Expand Down Expand Up @@ -69,14 +70,19 @@ ColorMaterialProperty.prototype.getType = function (time) {
return "Color";
};

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
ColorMaterialProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
if (!defined(result)) {
result = {};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import CompositeProperty from "./CompositeProperty.js";
import Property from "./Property.js";

Expand Down Expand Up @@ -82,19 +83,19 @@ CompositeMaterialProperty.prototype.getType = function (time) {
return undefined;
};

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
CompositeMaterialProperty.prototype.getValue = function (time, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(time)) {
throw new DeveloperError("time is required");
time = JulianDate.now(timeScratch);
}
//>>includeEnd('debug');

const innerProperty = this._composite._intervals.findDataForIntervalContainingDate(
time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import ReferenceFrame from "../Core/ReferenceFrame.js";
import CompositeProperty from "./CompositeProperty.js";
import Property from "./Property.js";
Expand Down Expand Up @@ -82,14 +83,19 @@ Object.defineProperties(CompositePositionProperty.prototype, {
},
});

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time in the fixed frame.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {Cartesian3} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {Cartesian3 | undefined} The modified result parameter or a new instance if the result parameter was not supplied.
*/
CompositePositionProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
};

Expand Down
10 changes: 5 additions & 5 deletions packages/engine/Source/DataSources/CompositeProperty.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Event from "../Core/Event.js";
import EventHelper from "../Core/EventHelper.js";
import JulianDate from "../Core/JulianDate.js";
import TimeIntervalCollection from "../Core/TimeIntervalCollection.js";
import Property from "./Property.js";

Expand Down Expand Up @@ -103,19 +103,19 @@ Object.defineProperties(CompositeProperty.prototype, {
},
});

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
CompositeProperty.prototype.getValue = function (time, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(time)) {
throw new DeveloperError("time is required");
time = JulianDate.now(timeScratch);
}
//>>includeEnd('debug');

const innerProperty = this._intervals.findDataForIntervalContainingDate(time);
if (defined(innerProperty)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import ReferenceFrame from "../Core/ReferenceFrame.js";
import PositionProperty from "./PositionProperty.js";

Expand Down Expand Up @@ -65,14 +66,19 @@ Object.defineProperties(ConstantPositionProperty.prototype, {
},
});

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time in the fixed frame.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
ConstantPositionProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
return this.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
};

Expand Down
8 changes: 7 additions & 1 deletion packages/engine/Source/DataSources/GridMaterialProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Color from "../Core/Color.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import createPropertyDescriptor from "./createPropertyDescriptor.js";
import Property from "./Property.js";

Expand Down Expand Up @@ -134,14 +135,19 @@ GridMaterialProperty.prototype.getType = function (time) {
return "Grid";
};

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
GridMaterialProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
if (!defined(result)) {
result = {};
}
Expand Down
9 changes: 8 additions & 1 deletion packages/engine/Source/DataSources/ImageMaterialProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Color from "../Core/Color.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import createPropertyDescriptor from "./createPropertyDescriptor.js";
import Property from "./Property.js";

Expand Down Expand Up @@ -114,14 +115,20 @@ ImageMaterialProperty.prototype.getType = function (time) {
return "Image";
};

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
ImageMaterialProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}

if (!defined(result)) {
result = {};
}
Expand Down
8 changes: 7 additions & 1 deletion packages/engine/Source/DataSources/MaterialProperty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Color from "../Core/Color.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import JulianDate from "../Core/JulianDate.js";
import Material from "../Scene/Material.js";

/**
Expand Down Expand Up @@ -62,7 +63,7 @@ MaterialProperty.prototype.getType = DeveloperError.throwInstantiationError;
* Gets the value of the property at the provided time.
* @function
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
Expand All @@ -78,11 +79,16 @@ MaterialProperty.prototype.getValue = DeveloperError.throwInstantiationError;
*/
MaterialProperty.prototype.equals = DeveloperError.throwInstantiationError;

const timeScratch = new JulianDate();

/**
* @private
*/
MaterialProperty.getValue = function (time, materialProperty, material) {
let type;
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}

if (defined(materialProperty)) {
type = materialProperty.getType(time);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import TranslationRotationScale from "../Core/TranslationRotationScale.js";
import createPropertyDescriptor from "./createPropertyDescriptor.js";
import Property from "./Property.js";
Expand Down Expand Up @@ -92,14 +93,19 @@ Object.defineProperties(NodeTransformationProperty.prototype, {
scale: createPropertyDescriptor("scale"),
});

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {TranslationRotationScale} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {TranslationRotationScale} The modified result parameter or a new instance if the result parameter was not supplied.
*/
NodeTransformationProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
if (!defined(result)) {
result = new TranslationRotationScale();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Color from "../Core/Color.js";
import defined from "../Core/defined.js";
import Event from "../Core/Event.js";
import JulianDate from "../Core/JulianDate.js";
import createPropertyDescriptor from "./createPropertyDescriptor.js";
import Property from "./Property.js";

Expand Down Expand Up @@ -67,14 +68,19 @@ PolylineArrowMaterialProperty.prototype.getType = function (time) {
return "PolylineArrow";
};

const timeScratch = new JulianDate();

/**
* Gets the value of the property at the provided time.
*
* @param {JulianDate} time The time for which to retrieve the value.
* @param {JulianDate} [time=JulianDate.now()] The time for which to retrieve the value. If omitted, the current system time is used.
* @param {object} [result] The object to store the value into, if omitted, a new instance is created and returned.
* @returns {object} The modified result parameter or a new instance if the result parameter was not supplied.
*/
PolylineArrowMaterialProperty.prototype.getValue = function (time, result) {
if (!defined(time)) {
time = JulianDate.now(timeScratch);
}
if (!defined(result)) {
result = {};
}
Expand Down
Loading

0 comments on commit 0a69f67

Please sign in to comment.