Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove defaultValue() and create DefaultValue namespace #12252

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
  •  
  •  
  •  
5 changes: 1 addition & 4 deletions Apps/Sandcastle/gallery/3D Tiles 1.1 CDB Yemen.html
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@
const propertyValue = feature.getProperty(propertyId);
const property = metadataClass.properties[propertyId];

const propertyType = Cesium.defaultValue(
property.componentType,
property.type,
);
const propertyType = property.componentType ?? property.type;
tableHtmlScratch += `<tr style='font-family: monospace;' title='${property.description}'><th>${property.name}</th><th><b>${property.id}</b></th><td>${propertyType}</td><td>${propertyValue}</td></tr>`;
}
tableHtmlScratch +=
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

const styles = [];
function addStyle(name, style) {
style.pointSize = Cesium.defaultValue(style.pointSize, 5.0);
style.pointSize = style.pointSize ?? 5.0;
styles.push({
name: name,
style: style,
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/Imagery Layers Manipulation.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@
try {
const imageryProvider = await Promise.resolve(imageryProviderPromise);
const layer = new Cesium.ImageryLayer(imageryProvider);
layer.alpha = Cesium.defaultValue(alpha, 0.5);
layer.show = Cesium.defaultValue(show, true);
layer.alpha = alpha ?? 0.5;
layer.show = show ?? true;
layer.name = name;
imageryLayers.add(layer);
Cesium.knockout.track(layer, ["alpha", "show", "name"]);
Expand Down
8 changes: 4 additions & 4 deletions Apps/Sandcastle/gallery/development/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@
});

async function createModel(url, height, heading, pitch, roll) {
height = Cesium.defaultValue(height, 0.0);
heading = Cesium.defaultValue(heading, 0.0);
pitch = Cesium.defaultValue(pitch, 0.0);
roll = Cesium.defaultValue(roll, 0.0);
height = height ?? 0.0;
heading = heading ?? 0.0;
pitch = pitch ?? 0.0;
roll = roll ?? 0.0;
const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);

const origin = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, height);
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Change Log


### 1.124 - 2024-12-02

#### @cesium/engine
Expand All @@ -18,6 +19,12 @@

- Added a `DeveloperError` when `globe` is set to `false` and a `baseLayer` is provided in `Viewer` options. This prevents errors caused by attempting to use a `baseLayer` without a globe. [#12274](https://github.com/CesiumGS/cesium/pull/12274)

### 1.123.2 - 2024-11-10

##### Deprecated :hourglass_flowing_sand:

- defaultValue() has been deprecated. All uses have been changed to the nullish coalescing operator (??)
Comment on lines +24 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can go under the 1.123 release since that will be the next one (and I expect we should be able to get this in by then)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jjspace Is the play to stick with the nullish coalescing operator, or deprecating defaultValue and create DefaultValue? Based on #12238, I understood it is the latter. If that is the case, would it make more sense to first create DefaultValue and then replace defaultValue with DefaultValue in the codebase? I saw Dave mention he may need to redo the majority of the PR, so it may be easier to directly replace defaultValue with DefaultValue. Rather than replace defaultValue with ?? to then replace it with DefaultValue. If I misunderstood anything, could you provide some guidance?


### 1.123.1 - 2024-11-07

#### @cesium/engine
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,5 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
- [Javier Sanchez](https://github.com/jvrjsanchez)
- [Jérôme Fayot](https://github.com/jfayot)
- [Kirn Kim](https://github.com/squrki)
- [David Brown](https://github.com/dave-b-b)
- [Emanuele Mastaglia](https://github.com/Masty88)
2 changes: 1 addition & 1 deletion Documentation/Contributors/CodingGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ To some extent, this guide can be summarized as _make new code similar to existi

- Directory names are `PascalCase`, e.g., `Source/Scene`.
- Constructor functions are `PascalCase`, e.g., `Cartesian3`.
- Functions are `camelCase`, e.g., `defaultValue()`, `Cartesian3.equalsEpsilon()`.
- Functions are `camelCase`, e.g. `Cartesian3.equalsEpsilon()`.
- Files end in `.js` and have the same name as the JavaScript identifier, e.g., `Cartesian3.js` and `defaultValue.js`.
- Variables, including class properties, are `camelCase`, e.g.,

Expand Down
96 changes: 42 additions & 54 deletions Specs/Cesium3DTilesTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,11 @@ const defaultIbl = new ImageBasedLighting({
});

Cesium3DTilesTester.loadTileset = async function (scene, url, options) {
options = defaultValue(options, {});
options.cullRequestsWhileMoving = defaultValue(
options.cullRequestsWhileMoving,
false,
);
options.imageBasedLighting = defaultValue(
options.imageBasedLighting,
defaultIbl,
);
options = options ?? {};
options.cullRequestsWhileMoving = options.cullRequestsWhileMoving ??
false;
options.imageBasedLighting = options.imageBasedLighting ??
defaultIbl;
options.environmentMapOptions = {
enabled: false, // disable other diffuse lighting by default
...options.environmentMapOptions,
Expand Down Expand Up @@ -170,10 +166,10 @@ Cesium3DTilesTester.tileDestroys = function (scene, url, options) {

Cesium3DTilesTester.generateBatchedTileBuffer = function (options) {
// Procedurally generate the tile array buffer for testing purposes
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const magic = defaultValue(options.magic, [98, 51, 100, 109]);
const version = defaultValue(options.version, 1);
const featuresLength = defaultValue(options.featuresLength, 1);
options = options ?? defaultValue.EMPTY_OBJECT;
const magic = options.magic ?? [98, 51, 100, 109];
const version = options.version ?? 1;
const featuresLength = options.featuresLength ?? 1;
const featureTableJson = {
BATCH_LENGTH: featuresLength,
};
Expand Down Expand Up @@ -207,12 +203,12 @@ Cesium3DTilesTester.generateBatchedTileBuffer = function (options) {

Cesium3DTilesTester.generateInstancedTileBuffer = function (options) {
// Procedurally generate the tile array buffer for testing purposes
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const magic = defaultValue(options.magic, [105, 51, 100, 109]);
const version = defaultValue(options.version, 1);
options = options ?? defaultValue.EMPTY_OBJECT;
const magic = options.magic ?? [105, 51, 100, 109];
const version = options.version ?? 1;

const gltfFormat = defaultValue(options.gltfFormat, 1);
const gltfUri = defaultValue(options.gltfUri, "model.gltf");
const gltfFormat = options.gltfFormat ?? 1;
const gltfUri = options.gltfUri ?? "model.gltf";
const gltfUriByteLength = gltfUri.length;

const featureTableJson = options.featureTableJson;
Expand All @@ -222,7 +218,7 @@ Cesium3DTilesTester.generateInstancedTileBuffer = function (options) {
featureTableJsonString = JSON.stringify(featureTableJson);
}
} else {
const featuresLength = defaultValue(options.featuresLength, 1);
const featuresLength = options.featuresLength ?? 1;
featureTableJsonString = JSON.stringify({
INSTANCES_LENGTH: featuresLength,
POSITION: new Array(featuresLength * 3).fill(0),
Expand All @@ -231,10 +227,7 @@ Cesium3DTilesTester.generateInstancedTileBuffer = function (options) {
featureTableJsonString = padStringToByteAlignment(featureTableJsonString, 8);
const featureTableJsonByteLength = featureTableJsonString.length;

const featureTableBinary = defaultValue(
options.featureTableBinary,
new Uint8Array(0),
);
const featureTableBinary = options.featureTableBinary ?? new Uint8Array(0);
const featureTableBinaryByteLength = featureTableBinary.length;

const batchTableJson = options.batchTableJson;
Expand All @@ -245,10 +238,7 @@ Cesium3DTilesTester.generateInstancedTileBuffer = function (options) {
batchTableJsonString = padStringToByteAlignment(batchTableJsonString, 8);
const batchTableJsonByteLength = batchTableJsonString.length;

const batchTableBinary = defaultValue(
options.batchTableBinary,
new Uint8Array(0),
);
const batchTableBinary = options.batchTableBinary ?? new Uint8Array(0);
const batchTableBinaryByteLength = batchTableBinary.length;

const headerByteLength = 32;
Expand Down Expand Up @@ -300,9 +290,9 @@ Cesium3DTilesTester.generateInstancedTileBuffer = function (options) {

Cesium3DTilesTester.generatePointCloudTileBuffer = function (options) {
// Procedurally generate the tile array buffer for testing purposes
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const magic = defaultValue(options.magic, [112, 110, 116, 115]);
const version = defaultValue(options.version, 1);
options = options ?? defaultValue.EMPTY_OBJECT;
const magic = options.magic ?? [112, 110, 116, 115];
const version = options.version ?? 1;
let featureTableJson = options.featureTableJson;
if (!defined(featureTableJson)) {
featureTableJson = {
Expand All @@ -315,10 +305,8 @@ Cesium3DTilesTester.generatePointCloudTileBuffer = function (options) {

let featureTableJsonString = JSON.stringify(featureTableJson);
featureTableJsonString = padStringToByteAlignment(featureTableJsonString, 4);
const featureTableJsonByteLength = defaultValue(
options.featureTableJsonByteLength,
featureTableJsonString.length,
);
const featureTableJsonByteLength =
options.featureTableJsonByteLength ?? featureTableJsonString.length;

const featureTableBinary = new ArrayBuffer(12); // Enough space to hold 3 floats
const featureTableBinaryByteLength = featureTableBinary.byteLength;
Expand Down Expand Up @@ -356,10 +344,10 @@ Cesium3DTilesTester.generatePointCloudTileBuffer = function (options) {

Cesium3DTilesTester.generateCompositeTileBuffer = function (options) {
// Procedurally generate the tile array buffer for testing purposes
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const magic = defaultValue(options.magic, [99, 109, 112, 116]);
const version = defaultValue(options.version, 1);
const tiles = defaultValue(options.tiles, []);
options = options ?? defaultValue.EMPTY_OBJECT;
const magic = options.magic ?? [99, 109, 112, 116];
const version = options.version ?? 1;
const tiles = options.tiles ?? [];
const tilesLength = tiles.length;

let i;
Expand Down Expand Up @@ -393,20 +381,20 @@ Cesium3DTilesTester.generateCompositeTileBuffer = function (options) {

Cesium3DTilesTester.generateVectorTileBuffer = function (options) {
// Procedurally generate the tile array buffer for testing purposes
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const magic = defaultValue(options.magic, [118, 99, 116, 114]);
const version = defaultValue(options.version, 1);
options = options ?? defaultValue.EMPTY_OBJECT;
const magic = options.magic ?? [118, 99, 116, 114];
const version = options.version ?? 1;

let featureTableJsonString;
let featureTableJsonByteLength = 0;
const defineFeatureTable = defaultValue(options.defineFeatureTable, true);
const defineFeatureTable = options.defineFeatureTable ?? true;
if (defineFeatureTable) {
const defineRegion = defaultValue(options.defineRegion, true);
const defineRegion = options.defineRegion ?? true;
const featureTableJson = {
REGION: defineRegion ? [-1.0, -1.0, 1.0, 1.0, -1.0, 1.0] : undefined,
POLYGONS_LENGTH: defaultValue(options.polygonsLength, 0),
POLYLINES_LENGTH: defaultValue(options.polylinesLength, 0),
POINTS_LENGTH: defaultValue(options.pointsLength, 0),
POLYGONS_LENGTH: options.polygonsLength ?? 0,
POLYLINES_LENGTH: options.polylinesLength ?? 0,
POINTS_LENGTH: options.pointsLength ?? 0,
POLYGON_BATCH_IDS: options.polygonBatchIds,
POLYLINE_BATCH_IDS: options.polylineBatchIds,
POINT_BATCH_IDS: options.pointBatchIds,
Expand Down Expand Up @@ -446,19 +434,19 @@ Cesium3DTilesTester.generateVectorTileBuffer = function (options) {

Cesium3DTilesTester.generateGeometryTileBuffer = function (options) {
// Procedurally generate the tile array buffer for testing purposes
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const magic = defaultValue(options.magic, [103, 101, 111, 109]);
const version = defaultValue(options.version, 1);
options = options ?? defaultValue.EMPTY_OBJECT;
const magic = options.magic ?? [103, 101, 111, 109];
const version = options.version ?? 1;

let featureTableJsonString;
let featureTableJsonByteLength = 0;
const defineFeatureTable = defaultValue(options.defineFeatureTable, true);
const defineFeatureTable = options.defineFeatureTable ?? true;
if (defineFeatureTable) {
const featureTableJson = {
BOXES_LENGTH: defaultValue(options.boxesLength, 0),
CYLINDERS_LENGTH: defaultValue(options.cylindersLength, 0),
ELLIPSOIDS_LENGTH: defaultValue(options.ellipsoidsLength, 0),
SPHERES_LENGTH: defaultValue(options.spheresLength, 0),
BOXES_LENGTH: options.boxesLength ?? 0,
CYLINDERS_LENGTH: options.cylindersLength ?? 0,
ELLIPSOIDS_LENGTH: options.ellipsoidsLength ?? 0,
SPHERES_LENGTH: options.spheresLength ?? 0,
BOX_BATCH_IDS: options.boxBatchIds,
CYLINDER_BATCH_IDS: options.cylinderBatchIds,
ELLIPSOID_BATCH_IDS: options.ellipsoidBatchIds,
Expand Down
Loading