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
2 changes: 1 addition & 1 deletion Documentation/Contributors/CodingGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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
89 changes: 39 additions & 50 deletions Specs/Cesium3DTilesTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,8 @@ Cesium3DTilesTester.waitForTilesLoaded = function (scene, tileset) {
};

Cesium3DTilesTester.loadTileset = async function (scene, url, options) {
options = defaultValue(options, {});
options.cullRequestsWhileMoving = defaultValue(
options.cullRequestsWhileMoving,
false,
);
options = options ?? {};
options.cullRequestsWhileMoving = options.cullRequestsWhileMoving ?? false;

const tileset = await Cesium3DTileset.fromUrl(url, options);

Expand Down Expand Up @@ -145,10 +142,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 @@ -182,12 +179,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 @@ -197,7 +194,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 @@ -206,10 +203,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 @@ -220,10 +214,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 @@ -275,9 +266,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 @@ -290,10 +281,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 @@ -331,10 +320,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 @@ -368,20 +357,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 @@ -421,19 +410,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
Loading