diff --git a/Apps/Sandcastle/gallery/3D Tiles 1.1 CDB Yemen.html b/Apps/Sandcastle/gallery/3D Tiles 1.1 CDB Yemen.html index 99e12eb214b0..d71942258122 100644 --- a/Apps/Sandcastle/gallery/3D Tiles 1.1 CDB Yemen.html +++ b/Apps/Sandcastle/gallery/3D Tiles 1.1 CDB Yemen.html @@ -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 += `${property.name}${property.id}${propertyType}${propertyValue}`; } tableHtmlScratch += diff --git a/Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html b/Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html index ce6466ae5692..694dbfe6b4b3 100644 --- a/Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html +++ b/Apps/Sandcastle/gallery/3D Tiles Point Cloud Styling.html @@ -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, diff --git a/Apps/Sandcastle/gallery/Imagery Layers Manipulation.html b/Apps/Sandcastle/gallery/Imagery Layers Manipulation.html index 4e309a339dd7..88aa1c85e9f2 100644 --- a/Apps/Sandcastle/gallery/Imagery Layers Manipulation.html +++ b/Apps/Sandcastle/gallery/Imagery Layers Manipulation.html @@ -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"]); diff --git a/Apps/Sandcastle/gallery/development/3D Models.html b/Apps/Sandcastle/gallery/development/3D Models.html index 0f8a01423422..c09948ff9ef2 100644 --- a/Apps/Sandcastle/gallery/development/3D Models.html +++ b/Apps/Sandcastle/gallery/development/3D Models.html @@ -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); diff --git a/CHANGES.md b/CHANGES.md index 49e2c0056ac6..9ac22980f4b0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ # Change Log + ### 1.124 - 2024-12-02 #### @cesium/engine @@ -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 (??) + ### 1.123.1 - 2024-11-07 #### @cesium/engine diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index cc7913527093..a88af0212221 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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) diff --git a/Documentation/Contributors/CodingGuide/README.md b/Documentation/Contributors/CodingGuide/README.md index 8d85f03bcfcd..6530fb8516a4 100644 --- a/Documentation/Contributors/CodingGuide/README.md +++ b/Documentation/Contributors/CodingGuide/README.md @@ -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., diff --git a/Specs/Cesium3DTilesTester.js b/Specs/Cesium3DTilesTester.js index 6435df08fbb0..3341a59ee583 100644 --- a/Specs/Cesium3DTilesTester.js +++ b/Specs/Cesium3DTilesTester.js @@ -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, @@ -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, }; @@ -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; @@ -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), @@ -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; @@ -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; @@ -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 = { @@ -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; @@ -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; @@ -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, @@ -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, diff --git a/Specs/DomEventSimulator.js b/Specs/DomEventSimulator.js index 8a6093ff6146..1d9c7b0c2da3 100644 --- a/Specs/DomEventSimulator.js +++ b/Specs/DomEventSimulator.js @@ -1,21 +1,21 @@ import { defaultValue, FeatureDetection } from "@cesium/engine"; function createMouseEvent(type, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const canBubble = defaultValue(options.canBubble, true); - const cancelable = defaultValue(options.cancelable, true); - const view = defaultValue(options.view, window); - const detail = defaultValue(options.detail, 0); - const screenX = defaultValue(options.screenX, 0); - const screenY = defaultValue(options.screenY, 0); - const clientX = defaultValue(options.clientX, 0); - const clientY = defaultValue(options.clientY, 0); - const ctrlKey = defaultValue(options.ctrlKey, false); - const altKey = defaultValue(options.altKey, false); - const shiftKey = defaultValue(options.shiftKey, false); - const metaKey = defaultValue(options.metaKey, false); - const button = defaultValue(options.button, 0); - const relatedTarget = defaultValue(options.relatedTarget, null); + options = options ?? defaultValue.EMPTY_OBJECT; + const canBubble = options.canBubble ?? true; + const cancelable = options.cancelable ?? true; + const view = options.view ?? window; + const detail = options.detail ?? 0; + const screenX = options.screenX ?? 0; + const screenY = options.screenY ?? 0; + const clientX = options.clientX ?? 0; + const clientY = options.clientY ?? 0; + const ctrlKey = options.ctrlKey ?? false; + const altKey = options.altKey ?? false; + const shiftKey = options.shiftKey ?? false; + const metaKey = options.metaKey ?? false; + const button = options.button ?? 0; + const relatedTarget = options.relatedTarget ?? null; const event = document.createEvent("MouseEvent"); event.initMouseEvent( @@ -57,22 +57,22 @@ function createModifiersList(ctrlKey, altKey, shiftKey, metaKey) { // MouseWheelEvent is legacy function createMouseWheelEvent(type, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const canBubble = defaultValue(options.canBubble, true); - const cancelable = defaultValue(options.cancelable, true); - const view = defaultValue(options.view, window); - const detail = defaultValue(options.detail, 0); - const screenX = defaultValue(options.screenX, 0); - const screenY = defaultValue(options.screenY, 0); - const clientX = defaultValue(options.clientX, 0); - const clientY = defaultValue(options.clientY, 0); - const button = defaultValue(options.button, 0); - const relatedTarget = defaultValue(options.relatedTarget, null); - const ctrlKey = defaultValue(options.ctrlKey, false); - const altKey = defaultValue(options.altKey, false); - const shiftKey = defaultValue(options.shiftKey, false); - const metaKey = defaultValue(options.metaKey, false); - const wheelDelta = defaultValue(options.wheelDelta, 0); + options = options ?? defaultValue.EMPTY_OBJECT; + const canBubble = options.canBubble ?? true; + const cancelable = options.cancelable ?? true; + const view = options.view ?? window; + const detail = options.detail ?? 0; + const screenX = options.screenX ?? 0; + const screenY = options.screenY ?? 0; + const clientX = options.clientX ?? 0; + const clientY = options.clientY ?? 0; + const button = options.button ?? 0; + const relatedTarget = options.relatedTarget ?? null; + const ctrlKey = options.ctrlKey ?? false; + const altKey = options.altKey ?? false; + const shiftKey = options.shiftKey ?? false; + const metaKey = options.metaKey ?? false; + const wheelDelta = options.wheelDelta ?? 0; const event = document.createEvent("MouseWheelEvent"); const modifiersList = createModifiersList(ctrlKey, altKey, shiftKey, metaKey); @@ -95,25 +95,25 @@ function createMouseWheelEvent(type, options) { } function createWheelEvent(type, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const canBubble = defaultValue(options.canBubble, true); - const cancelable = defaultValue(options.cancelable, true); - const view = defaultValue(options.view, window); - const detail = defaultValue(options.detail, 0); - const screenX = defaultValue(options.screenX, 0); - const screenY = defaultValue(options.screenY, 0); - const clientX = defaultValue(options.clientX, 0); - const clientY = defaultValue(options.clientY, 0); - const button = defaultValue(options.button, 0); - const relatedTarget = defaultValue(options.relatedTarget, null); - const ctrlKey = defaultValue(options.ctrlKey, false); - const altKey = defaultValue(options.altKey, false); - const shiftKey = defaultValue(options.shiftKey, false); - const metaKey = defaultValue(options.metaKey, false); - const deltaX = defaultValue(options.deltaX, 0); - const deltaY = defaultValue(options.deltaY, 0); - const deltaZ = defaultValue(options.deltaZ, 0); - const deltaMode = defaultValue(options.deltaMode, 0); + options = options ?? defaultValue.EMPTY_OBJECT; + const canBubble = options.canBubble ?? true; + const cancelable = options.cancelable ?? true; + const view = options.view ?? window; + const detail = options.detail ?? 0; + const screenX = options.screenX ?? 0; + const screenY = options.screenY ?? 0; + const clientX = options.clientX ?? 0; + const clientY = options.clientY ?? 0; + const button = options.button ?? 0; + const relatedTarget = options.relatedTarget ?? null; + const ctrlKey = options.ctrlKey ?? false; + const altKey = options.altKey ?? false; + const shiftKey = options.shiftKey ?? false; + const metaKey = options.metaKey ?? false; + const deltaX = options.deltaX ?? 0; + const deltaY = options.deltaY ?? 0; + const deltaZ = options.deltaZ ?? 0; + const deltaMode = options.deltaMode ?? 0; try { return new WheelEvent(type, { @@ -165,53 +165,53 @@ function createWheelEvent(type, options) { } function createTouchEvent(type, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const canBubble = defaultValue(options.canBubble, true); - const cancelable = defaultValue(options.cancelable, true); - const view = defaultValue(options.view, window); - const detail = defaultValue(options.detail, 0); + options = options ?? defaultValue.EMPTY_OBJECT; + const canBubble = options.canBubble ?? true; + const cancelable = options.cancelable ?? true; + const view = options.view ?? window; + const detail = options.detail ?? 0; const event = document.createEvent("UIEvent"); event.initUIEvent(type, canBubble, cancelable, view, detail); - event.touches = defaultValue(options.touches, []); - event.targetTouches = defaultValue(options.targetTouches, []); - event.changedTouches = defaultValue(options.changedTouches, []); + event.touches = options.touches ?? []; + event.targetTouches = options.targetTouches ?? []; + event.changedTouches = options.changedTouches ?? []; return event; } function createPointerEvent(type, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let event; if (FeatureDetection.isInternetExplorer()) { - const canBubble = defaultValue(options.canBubble, true); - const cancelable = defaultValue(options.cancelable, true); - const view = defaultValue(options.view, window); - const detail = defaultValue(options.detail, 0); - const screenX = defaultValue(options.screenX, 0); - const screenY = defaultValue(options.screenY, 0); - const clientX = defaultValue(options.clientX, 0); - const clientY = defaultValue(options.clientY, 0); - const ctrlKey = defaultValue(options.ctrlKey, false); - const altKey = defaultValue(options.altKey, false); - const shiftKey = defaultValue(options.shiftKey, false); - const metaKey = defaultValue(options.metaKey, false); - const button = defaultValue(options.button, 0); - const relatedTarget = defaultValue(options.relatedTarget, null); - const offsetX = defaultValue(options.offsetX, 0); - const offsetY = defaultValue(options.offsetY, 0); - const width = defaultValue(options.width, 0); - const height = defaultValue(options.height, 0); - const pressure = defaultValue(options.pressure, 0); - const rotation = defaultValue(options.rotation, 0); - const tiltX = defaultValue(options.tiltX, 0); - const tiltY = defaultValue(options.tiltY, 0); - const pointerId = defaultValue(options.pointerId, 1); - const pointerType = defaultValue(options.pointerType, 0); - const hwTimestamp = defaultValue(options.hwTimestamp, 0); - const isPrimary = defaultValue(options.isPrimary, 0); + const canBubble = options.canBubble ?? true; + const cancelable = options.cancelable ?? true; + const view = options.view ?? window; + const detail = options.detail ?? 0; + const screenX = options.screenX ?? 0; + const screenY = options.screenY ?? 0; + const clientX = options.clientX ?? 0; + const clientY = options.clientY ?? 0; + const ctrlKey = options.ctrlKey ?? false; + const altKey = options.altKey ?? false; + const shiftKey = options.shiftKey ?? false; + const metaKey = options.metaKey ?? false; + const button = options.button ?? 0; + const relatedTarget = options.relatedTarget ?? null; + const offsetX = options.offsetX ?? 0; + const offsetY = options.offsetY ?? 0; + const width = options.width ?? 0; + const height = options.height ?? 0; + const pressure = options.pressure ?? 0; + const rotation = options.rotation ?? 0; + const tiltX = options.tiltX ?? 0; + const tiltY = options.tiltY ?? 0; + const pointerId = options.pointerId ?? 1; + const pointerType = options.pointerType ?? 0; + const hwTimestamp = options.hwTimestamp ?? 0; + const isPrimary = options.isPrimary ?? 0; event = document.createEvent("PointerEvent"); event.initPointerEvent( @@ -245,45 +245,45 @@ function createPointerEvent(type, options) { ); } else { event = new window.PointerEvent(type, { - canBubble: defaultValue(options.canBubble, true), - cancelable: defaultValue(options.cancelable, true), - view: defaultValue(options.view, window), - detail: defaultValue(options.detail, 0), - screenX: defaultValue(options.screenX, 0), - screenY: defaultValue(options.screenY, 0), - clientX: defaultValue(options.clientX, 0), - clientY: defaultValue(options.clientY, 0), - ctrlKey: defaultValue(options.ctrlKey, false), - altKey: defaultValue(options.altKey, false), - shiftKey: defaultValue(options.shiftKey, false), - metaKey: defaultValue(options.metaKey, false), - button: defaultValue(options.button, 0), - relatedTarget: defaultValue(options.relatedTarget, null), - offsetX: defaultValue(options.offsetX, 0), - offsetY: defaultValue(options.offsetY, 0), - width: defaultValue(options.width, 0), - height: defaultValue(options.height, 0), - pressure: defaultValue(options.pressure, 0), - rotation: defaultValue(options.rotation, 0), - tiltX: defaultValue(options.tiltX, 0), - tiltY: defaultValue(options.tiltY, 0), - pointerId: defaultValue(options.pointerId, 1), - pointerType: defaultValue(options.pointerType, 0), - hwTimestamp: defaultValue(options.hwTimestamp, 0), - isPrimary: defaultValue(options.isPrimary, 0), + canBubble: options.canBubble ?? true, + cancelable: options.cancelable ?? true, + view: options.view ?? window, + detail: options.detail ?? 0, + screenX: options.screenX ?? 0, + screenY: options.screenY ?? 0, + clientX: options.clientX ?? 0, + clientY: options.clientY ?? 0, + ctrlKey: options.ctrlKey ?? false, + altKey: options.altKey ?? false, + shiftKey: options.shiftKey ?? false, + metaKey: options.metaKey ?? false, + button: options.button ?? 0, + relatedTarget: options.relatedTarget ?? null, + offsetX: options.offsetX ?? 0, + offsetY: options.offsetY ?? 0, + width: options.width ?? 0, + height: options.height ?? 0, + pressure: options.pressure ?? 0, + rotation: options.rotation ?? 0, + tiltX: options.tiltX ?? 0, + tiltY: options.tiltY ?? 0, + pointerId: options.pointerId ?? 1, + pointerType: options.pointerType ?? 0, + hwTimestamp: options.hwTimestamp ?? 0, + isPrimary: options.isPrimary ?? 0, }); } return event; } function createDeviceOrientationEvent(type, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const canBubble = defaultValue(options.canBubble, true); - const cancelable = defaultValue(options.cancelable, true); - const alpha = defaultValue(options.alpha, 0.0); - const beta = defaultValue(options.beta, 0.0); - const gamma = defaultValue(options.gamma, 0.0); - const absolute = defaultValue(options.absolute, false); + options = options ?? defaultValue.EMPTY_OBJECT; + const canBubble = options.canBubble ?? true; + const cancelable = options.cancelable ?? true; + const alpha = options.alpha ?? 0.0; + const beta = options.beta ?? 0.0; + const gamma = options.gamma ?? 0.0; + const absolute = options.absolute ?? false; let event; event = document.createEvent("DeviceOrientationEvent"); diff --git a/Specs/ImplicitTilingTester.js b/Specs/ImplicitTilingTester.js index 3cce276c929b..70ad97361392 100644 --- a/Specs/ImplicitTilingTester.js +++ b/Specs/ImplicitTilingTester.js @@ -1,4 +1,4 @@ -import { defined, defaultValue } from "@cesium/engine"; +import { defined } from "@cesium/engine"; import concatTypedArrays from "./concatTypedArrays.js"; import MetadataTester from "./MetadataTester.js"; @@ -87,7 +87,7 @@ ImplicitTilingTester.generateSubtreeBuffers = function ( subtreeDescription, constantOnly, ) { - constantOnly = defaultValue(constantOnly, false); + constantOnly = constantOnly ?? false; // This will be populated by makeBufferViews() and makeBuffers() let subtreeJson = {}; @@ -148,10 +148,7 @@ function makeBufferViews(subtreeDescription, subtreeJson) { count: 0, }; - const useLegacySchema = defaultValue( - subtreeDescription.useLegacySchema, - false, - ); + const useLegacySchema = subtreeDescription.useLegacySchema ?? false; const bufferViewJsonArray = []; gatherBufferViews( bufferViewsU8, diff --git a/Specs/MetadataTester.js b/Specs/MetadataTester.js index 09f8de4de4bb..7b294ef2ba0c 100644 --- a/Specs/MetadataTester.js +++ b/Specs/MetadataTester.js @@ -109,7 +109,7 @@ function createProperties(options) { } if (classProperty.isVariableLengthArray) { - const arrayOffsetBufferType = defaultValue(arrayOffsetType, offsetType); + const arrayOffsetBufferType = arrayOffsetType ?? offsetType; const arrayOffsetBuffer = addPadding( createArrayOffsetBuffer( values, @@ -123,10 +123,7 @@ function createProperties(options) { } if (classProperty.type === MetadataType.STRING) { - const stringOffsetBufferType = defaultValue( - stringOffsetType, - offsetType, - ); + const stringOffsetBufferType = stringOffsetType ?? offsetType; const stringOffsetBuffer = addPadding( createStringOffsetBuffer(values, stringOffsetBufferType), ); @@ -146,7 +143,7 @@ function createProperties(options) { } MetadataTester.createMetadataTable = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const disableBigIntSupport = options.disableBigIntSupport; const disableBigInt64ArraySupport = options.disableBigInt64ArraySupport; const disableBigUint64ArraySupport = options.disableBigUint64ArraySupport; @@ -193,7 +190,7 @@ MetadataTester.createMetadataTable = function (options) { }; MetadataTester.createPropertyTable = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const disableBigIntSupport = options.disableBigIntSupport; const disableBigInt64ArraySupport = options.disableBigInt64ArraySupport; const disableBigUint64ArraySupport = options.disableBigUint64ArraySupport; @@ -248,7 +245,7 @@ MetadataTester.createPropertyTable = function (options) { // for EXT_structural_metadata MetadataTester.createPropertyTables = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const propertyTables = []; const bufferViews = {}; @@ -280,7 +277,7 @@ MetadataTester.createPropertyTables = function (options) { // For EXT_feature_metadata MetadataTester.createFeatureTables = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const featureTables = {}; const bufferViews = {}; @@ -312,7 +309,7 @@ MetadataTester.createFeatureTables = function (options) { }; MetadataTester.createGltf = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const propertyTableResults = MetadataTester.createPropertyTables(options); @@ -483,7 +480,7 @@ function createStringOffsetBuffer(values, offsetType) { offset += encoder.encode(strings[i]).length; } offsets[length] = offset; - offsetType = defaultValue(offsetType, MetadataComponentType.UINT32); + offsetType = offsetType ?? MetadataComponentType.UINT32; return createBuffer(offsets, offsetType); } @@ -497,7 +494,7 @@ function createArrayOffsetBuffer(values, type, offsetType) { offset += values[i].length / componentCount; } offsets[length] = offset; - offsetType = defaultValue(offsetType, MetadataComponentType.UINT32); + offsetType = offsetType ?? MetadataComponentType.UINT32; return createBuffer(offsets, offsetType); } diff --git a/Specs/addDefaultMatchers.js b/Specs/addDefaultMatchers.js index 9ad56f65c30a..3e5eedfd4999 100644 --- a/Specs/addDefaultMatchers.js +++ b/Specs/addDefaultMatchers.js @@ -1,6 +1,5 @@ import { Cartesian2, - defaultValue, defined, DeveloperError, FeatureDetection, @@ -377,7 +376,7 @@ function createDefaultMatchers(debug) { return { compare: function (actual, expected, args) { const scene = actual; - const result = scene.pick(defaultValue(args, new Cartesian2(0, 0))); + const result = scene.pick(args ?? new Cartesian2(0, 0)); const webglStub = !!window.webglStub; if (!webglStub) { @@ -398,9 +397,7 @@ function createDefaultMatchers(debug) { return { compare: function (actual, expected, args) { const scene = actual; - const result = scene.pickVoxel( - defaultValue(args, new Cartesian2(0, 0)), - ); + const result = scene.pickVoxel(args ?? new Cartesian2(0, 0)); const webglStub = !!window.webglStub; if (!webglStub) { @@ -555,8 +552,8 @@ function createDefaultMatchers(debug) { compare: function (actual, expected, x, y) { const scene = actual; const canvas = scene.canvas; - x = defaultValue(x, canvas.clientWidth / 2); - y = defaultValue(y, canvas.clientHeight / 2); + x = x ?? canvas.clientWidth / 2; + y = y ?? canvas.clientHeight / 2; const result = scene.pickPosition(new Cartesian2(x, y)); const webglStub = !!window.webglStub; @@ -586,7 +583,7 @@ function createDefaultMatchers(debug) { // options were passed to to a framebuffer context = options.context; framebuffer = options.framebuffer; - epsilon = defaultValue(options.epsilon, epsilon); + epsilon = options.epsilon ?? epsilon; } else { context = options; } @@ -873,8 +870,8 @@ function contextRenderAndReadPixels(options) { let sp = options.shaderProgram; const uniformMap = options.uniformMap; const modelMatrix = options.modelMatrix; - const depth = defaultValue(options.depth, 0.0); - const clear = defaultValue(options.clear, true); + const depth = options.depth ?? 0.0; + const clear = options.clear ?? true; let clearColor; if (!defined(context)) { @@ -957,8 +954,8 @@ function contextRenderAndReadPixels(options) { function expectContextToRender(actual, expected, expectEqual) { const options = actual; const context = options.context; - const clear = defaultValue(options.clear, true); - const epsilon = defaultValue(options.epsilon, 0); + const clear = options.clear ?? true; + const epsilon = options.epsilon ?? 0; if (!defined(expected)) { expected = [255, 255, 255, 255]; diff --git a/Specs/createCamera.js b/Specs/createCamera.js index 2feb6bdb55fb..0a8bc9d85194 100644 --- a/Specs/createCamera.js +++ b/Specs/createCamera.js @@ -8,10 +8,10 @@ import { } from "@cesium/engine"; function MockScene(canvas) { - canvas = defaultValue(canvas, { + canvas = canvas ?? { clientWidth: 512, clientHeight: 384, - }); + }; this.canvas = canvas; this.drawingBufferWidth = canvas.clientWidth * 2; @@ -20,14 +20,14 @@ function MockScene(canvas) { } function createCamera(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const scene = new MockScene(options.canvas); const camera = new Camera(scene); - camera.frustum.near = defaultValue(options.near, 0.01); - camera.frustum.far = defaultValue(options.far, 10.0); + camera.frustum.near = options.near ?? 0.01; + camera.frustum.far = options.far ?? 10.0; - const offset = defaultValue(options.offset, new Cartesian3(-1.0, 0.0, 0.0)); + const offset = options.offset ?? new Cartesian3(-1.0, 0.0, 0.0); if (defined(options.target)) { camera.lookAt(options.target, offset); diff --git a/Specs/createCanvas.js b/Specs/createCanvas.js index eed0cb7af87d..c3cb5f49de1c 100644 --- a/Specs/createCanvas.js +++ b/Specs/createCanvas.js @@ -1,10 +1,8 @@ -import { defaultValue } from "@cesium/engine"; - let canvasCount = 0; function createCanvas(width, height) { - width = defaultValue(width, 1); - height = defaultValue(height, 1); + width = width ?? 1; + height = height ?? 1; const canvas = document.createElement("canvas"); canvas.id = `canvas${canvasCount++}`; diff --git a/Specs/createContext.js b/Specs/createContext.js index fca62cd01cbd..dc6d7ed237b8 100644 --- a/Specs/createContext.js +++ b/Specs/createContext.js @@ -1,4 +1,4 @@ -import { clone, defaultValue, Context } from "@cesium/engine"; +import { clone, Context } from "@cesium/engine"; import createCanvas from "./createCanvas.js"; import createFrameState from "./createFrameState.js"; @@ -6,9 +6,9 @@ import getWebGLStub from "./getWebGLStub.js"; function createContext(options, canvasWidth, canvasHeight) { // clone options so we can change properties - options = clone(defaultValue(options, {})); - options.webgl = clone(defaultValue(options.webgl, {})); - options.webgl.antialias = defaultValue(options.webgl.antialias, false); + options = clone(options ?? {}); + options.webgl = clone(options.webgl ?? {}); + options.webgl.antialias = options.webgl.antialias ?? false; if (!!window.webglStub) { options.getWebGLStub = getWebGLStub; } diff --git a/Specs/createFrameState.js b/Specs/createFrameState.js index a7838a72bdcf..ab4ff3d111a4 100644 --- a/Specs/createFrameState.js +++ b/Specs/createFrameState.js @@ -1,6 +1,5 @@ import { Atmosphere, - defaultValue, GeographicProjection, JulianDate, Camera, @@ -23,20 +22,17 @@ function createFrameState(context, camera, frameNumber, time) { const projection = new GeographicProjection(); frameState.mapProjection = projection; - frameState.frameNumber = defaultValue(frameNumber, 1.0); - frameState.time = defaultValue( - time, - JulianDate.fromDate(new Date("January 1, 2011 12:00:00 EST")), - ); + frameState.frameNumber = frameNumber ?? 1.0; + frameState.time = + time ?? JulianDate.fromDate(new Date("January 1, 2011 12:00:00 EST")); - camera = defaultValue( - camera, + camera = + camera ?? new Camera({ drawingBufferWidth: 1, drawingBufferHeight: 1, mapProjection: projection, - }), - ); + }); frameState.camera = camera; frameState.cullingVolume = camera.frustum.computeCullingVolume( camera.position, diff --git a/Specs/createGlobe.js b/Specs/createGlobe.js index c6d3dce330d7..b3e4a1986761 100644 --- a/Specs/createGlobe.js +++ b/Specs/createGlobe.js @@ -1,7 +1,7 @@ -import { defaultValue, Ellipsoid, Event } from "@cesium/engine"; +import { Ellipsoid, Event } from "@cesium/engine"; function createGlobe(ellipsoid) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); + ellipsoid = ellipsoid ?? Ellipsoid.WGS84; const globe = { _callback: undefined, diff --git a/Specs/createPackableArraySpecs.js b/Specs/createPackableArraySpecs.js index 4d5fc9f41696..6ef90e330d7f 100644 --- a/Specs/createPackableArraySpecs.js +++ b/Specs/createPackableArraySpecs.js @@ -1,5 +1,3 @@ -import { defaultValue } from "@cesium/engine"; - function createPackableArraySpecs( packable, unpackedArray, @@ -7,7 +5,7 @@ function createPackableArraySpecs( stride, namePrefix, ) { - namePrefix = defaultValue(namePrefix, ""); + namePrefix = namePrefix ?? ""; it(`${namePrefix} can pack`, function () { const actualPackedArray = packable.packArray(unpackedArray); diff --git a/Specs/createPackableSpecs.js b/Specs/createPackableSpecs.js index b2678604b830..98f83863f162 100644 --- a/Specs/createPackableSpecs.js +++ b/Specs/createPackableSpecs.js @@ -1,7 +1,7 @@ -import { defaultValue, defined, Math as CesiumMath } from "@cesium/engine"; +import { defined, Math as CesiumMath } from "@cesium/engine"; function createPackableSpecs(packable, instance, packedInstance, namePrefix) { - namePrefix = defaultValue(namePrefix, ""); + namePrefix = namePrefix ?? ""; it(`${namePrefix} can pack`, function () { const packedArray = []; diff --git a/Specs/createScene.js b/Specs/createScene.js index a2cee81a68b5..f3b1a501a309 100644 --- a/Specs/createScene.js +++ b/Specs/createScene.js @@ -1,25 +1,16 @@ -import { - Cartesian2, - clone, - defaultValue, - defined, - Scene, -} from "@cesium/engine"; +import { Cartesian2, clone, defined, Scene } from "@cesium/engine"; import createCanvas from "./createCanvas.js"; import getWebGLStub from "./getWebGLStub.js"; function createScene(options) { - options = defaultValue(options, {}); + options = options ?? {}; // Render tests can be difficult to debug. Let the caller choose a larger // canvas size temporarily. By stepping through a render test, you can see // what the camera sees after each render call. const debugWidth = window.debugCanvasWidth; - const debugHeight = defaultValue( - window.debugCanvasHeight, - window.debugCanvasWidth, - ); + const debugHeight = window.debugCanvasHeight ?? window.debugCanvasWidth; // save the canvas so we don't try to clone an HTMLCanvasElement const canvas = defined(options.canvas) @@ -30,18 +21,12 @@ function createScene(options) { options = clone(options, true); options.canvas = canvas; - options.contextOptions = defaultValue(options.contextOptions, {}); + options.contextOptions = options.contextOptions ?? {}; const contextOptions = options.contextOptions; - contextOptions.webgl = defaultValue(contextOptions.webgl, {}); - contextOptions.webgl.antialias = defaultValue( - contextOptions.webgl.antialias, - false, - ); - contextOptions.webgl.stencil = defaultValue( - contextOptions.webgl.stencil, - true, - ); + contextOptions.webgl = contextOptions.webgl ?? {}; + contextOptions.webgl.antialias = contextOptions.webgl.antialias ?? false; + contextOptions.webgl.stencil = contextOptions.webgl.stencil ?? true; if (!!window.webglStub) { contextOptions.getWebGLStub = getWebGLStub; } @@ -80,7 +65,7 @@ function createScene(options) { this.pick(new Cartesian2(0, 0)); }; - scene.rethrowRenderErrors = defaultValue(options.rethrowRenderErrors, true); + scene.rethrowRenderErrors = options.rethrowRenderErrors ?? true; return scene; } diff --git a/Specs/generateJsonBuffer.js b/Specs/generateJsonBuffer.js index e3de112ca3db..ca8bdfbcefea 100644 --- a/Specs/generateJsonBuffer.js +++ b/Specs/generateJsonBuffer.js @@ -1,11 +1,9 @@ -import { defaultValue } from "@cesium/engine"; - function generateJsonBuffer(json, byteOffset, boundary) { let i; const jsonString = JSON.stringify(json); - byteOffset = defaultValue(byteOffset, 0); - boundary = defaultValue(boundary, 1); + byteOffset = byteOffset ?? 0; + boundary = boundary ?? 1; const byteLength = jsonString.length; const remainder = (byteOffset + byteLength) % boundary; diff --git a/Specs/getWebGLStub.js b/Specs/getWebGLStub.js index 6a7e8d4d8a3e..d66ea6a9384b 100644 --- a/Specs/getWebGLStub.js +++ b/Specs/getWebGLStub.js @@ -1,10 +1,4 @@ -import { - clone, - defaultValue, - defined, - DeveloperError, - WebGLConstants, -} from "@cesium/engine"; +import { clone, defined, DeveloperError, WebGLConstants } from "@cesium/engine"; function getWebGLStub(canvas, options) { const stub = clone(WebGLConstants); @@ -184,17 +178,14 @@ function checkFramebufferStatusStub(target) { function getContextAttributesStub(options) { const contextAttributes = { - alpha: defaultValue(options.alpha, true), - depth: defaultValue(options.depth, true), - stencil: defaultValue(options.stencil, false), - antialias: defaultValue(options.antialias, true), - premultipliedAlpha: defaultValue(options.premultipliedAlpha, true), - preserveDrawingBuffer: defaultValue(options.preserveDrawingBuffer, false), - powerPreference: defaultValue(options.powerPreference, false), - failIfMajorPerformanceCaveat: defaultValue( - options.failIfMajorPerformanceCaveat, - false, - ), + alpha: options.alpha ?? true, + depth: options.depth ?? true, + stencil: options.stencil ?? false, + antialias: options.antialias ?? true, + premultipliedAlpha: options.premultipliedAlpha ?? true, + preserveDrawingBuffer: options.preserveDrawingBuffer ?? false, + powerPreference: options.powerPreference ?? false, + failIfMajorPerformanceCaveat: options.failIfMajorPerformanceCaveat ?? false, }; return function () { diff --git a/Specs/pollToPromise.js b/Specs/pollToPromise.js index 37feaf8375ad..4bc414b61db8 100644 --- a/Specs/pollToPromise.js +++ b/Specs/pollToPromise.js @@ -1,10 +1,10 @@ import { defaultValue, getTimestamp } from "@cesium/engine"; function pollToPromise(f, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const pollInterval = defaultValue(options.pollInterval, 1); - const timeout = defaultValue(options.timeout, 5000); + const pollInterval = options.pollInterval ?? 1; + const timeout = options.timeout ?? 5000; return new Promise(function (resolve, reject) { const startTimestamp = getTimestamp(); diff --git a/Specs/runLater.js b/Specs/runLater.js index b0a33de78a41..b1de545cc891 100644 --- a/Specs/runLater.js +++ b/Specs/runLater.js @@ -1,7 +1,5 @@ -import { defaultValue } from "@cesium/engine"; - function runLater(functionToRunLater, milliseconds) { - milliseconds = defaultValue(milliseconds, 0); + milliseconds = milliseconds ?? 0; return new Promise((resolve, reject) => { setTimeout(function () { diff --git a/packages/engine/Source/Core/ApproximateTerrainHeights.js b/packages/engine/Source/Core/ApproximateTerrainHeights.js index c8dc1230cdc3..55c917b2e1d6 100644 --- a/packages/engine/Source/Core/ApproximateTerrainHeights.js +++ b/packages/engine/Source/Core/ApproximateTerrainHeights.js @@ -4,7 +4,6 @@ import Cartesian2 from "./Cartesian2.js"; import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -71,7 +70,7 @@ ApproximateTerrainHeights.getMinimumMaximumHeights = function ( ); } //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; const xyLevel = getTileXYLevel(rectangle); @@ -142,7 +141,7 @@ ApproximateTerrainHeights.getBoundingSphere = function (rectangle, ellipsoid) { ); } //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; const xyLevel = getTileXYLevel(rectangle); diff --git a/packages/engine/Source/Core/ArcGISTiledElevationTerrainProvider.js b/packages/engine/Source/Core/ArcGISTiledElevationTerrainProvider.js index 41154ff6aa04..db437afdd2ec 100644 --- a/packages/engine/Source/Core/ArcGISTiledElevationTerrainProvider.js +++ b/packages/engine/Source/Core/ArcGISTiledElevationTerrainProvider.js @@ -41,7 +41,7 @@ const ALL_CHILDREN = 15; * @param {ArcGISTiledElevationTerrainProvider.ConstructorOptions} [options] An object describing initialization options. */ function TerrainProviderBuilder(options) { - this.ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + this.ellipsoid = options.ellipsoid ?? Ellipsoid.default; this.credit = undefined; this.tilingScheme = undefined; @@ -85,7 +85,7 @@ function parseMetadataSuccess(terrainProviderBuilder, metadata) { } const spatialReference = metadata.spatialReference; - const wkid = defaultValue(spatialReference.latestWkid, spatialReference.wkid); + const wkid = spatialReference.latestWkid ?? spatialReference.wkid; const extent = metadata.extent; const tilingSchemeOptions = { ellipsoid: terrainProviderBuilder.ellipsoid, @@ -234,7 +234,7 @@ async function requestMetadata( * @see TerrainProvider */ function ArcGISTiledElevationTerrainProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._resource = undefined; this._credit = undefined; @@ -357,7 +357,7 @@ ArcGISTiledElevationTerrainProvider.fromUrl = async function (url, options) { Check.defined("url", url); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; url = await Promise.resolve(url); let resource = Resource.createIfNeeded(url); diff --git a/packages/engine/Source/Core/AxisAlignedBoundingBox.js b/packages/engine/Source/Core/AxisAlignedBoundingBox.js index d5ddea4992a3..92e48b9a9183 100644 --- a/packages/engine/Source/Core/AxisAlignedBoundingBox.js +++ b/packages/engine/Source/Core/AxisAlignedBoundingBox.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Intersect from "./Intersect.js"; @@ -22,14 +21,14 @@ function AxisAlignedBoundingBox(minimum, maximum, center) { * @type {Cartesian3} * @default {@link Cartesian3.ZERO} */ - this.minimum = Cartesian3.clone(defaultValue(minimum, Cartesian3.ZERO)); + this.minimum = Cartesian3.clone(minimum ?? Cartesian3.ZERO); /** * The maximum point defining the bounding box. * @type {Cartesian3} * @default {@link Cartesian3.ZERO} */ - this.maximum = Cartesian3.clone(defaultValue(maximum, Cartesian3.ZERO)); + this.maximum = Cartesian3.clone(maximum ?? Cartesian3.ZERO); // If center was not defined, compute it. if (!defined(center)) { diff --git a/packages/engine/Source/Core/BingMapsGeocoderService.js b/packages/engine/Source/Core/BingMapsGeocoderService.js index 647658fcd2d3..eef76c5748d9 100644 --- a/packages/engine/Source/Core/BingMapsGeocoderService.js +++ b/packages/engine/Source/Core/BingMapsGeocoderService.js @@ -18,7 +18,7 @@ const url = "https://dev.virtualearth.net/REST/v1/Locations"; * @param {string} [options.culture] A Bing Maps {@link https://docs.microsoft.com/en-us/bingmaps/rest-services/common-parameters-and-types/supported-culture-codes|Culture Code} to return results in a specific culture and language. */ function BingMapsGeocoderService(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const key = options.key; //>>includeStart('debug', pragmas.debug); if (!defined(key)) { diff --git a/packages/engine/Source/Core/BoundingRectangle.js b/packages/engine/Source/Core/BoundingRectangle.js index ae678725057a..0f4039505c0d 100644 --- a/packages/engine/Source/Core/BoundingRectangle.js +++ b/packages/engine/Source/Core/BoundingRectangle.js @@ -1,7 +1,6 @@ import Cartesian2 from "./Cartesian2.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Ellipsoid from "./Ellipsoid.js"; import GeographicProjection from "./GeographicProjection.js"; @@ -27,28 +26,28 @@ function BoundingRectangle(x, y, width, height) { * @type {number} * @default 0.0 */ - this.x = defaultValue(x, 0.0); + this.x = x ?? 0.0; /** * The y coordinate of the rectangle. * @type {number} * @default 0.0 */ - this.y = defaultValue(y, 0.0); + this.y = y ?? 0.0; /** * The width of the rectangle. * @type {number} * @default 0.0 */ - this.width = defaultValue(width, 0.0); + this.width = width ?? 0.0; /** * The height of the rectangle. * @type {number} * @default 0.0 */ - this.height = defaultValue(height, 0.0); + this.height = height ?? 0.0; } /** @@ -72,7 +71,7 @@ BoundingRectangle.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.x; array[startingIndex++] = value.y; @@ -95,7 +94,7 @@ BoundingRectangle.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new BoundingRectangle(); @@ -179,7 +178,7 @@ BoundingRectangle.fromRectangle = function (rectangle, projection, result) { } defaultProjection._ellipsoid = Ellipsoid.default; - projection = defaultValue(projection, defaultProjection); + projection = projection ?? defaultProjection; const lowerLeft = projection.project( Rectangle.southwest(rectangle, fromRectangleLowerLeft), diff --git a/packages/engine/Source/Core/BoundingSphere.js b/packages/engine/Source/Core/BoundingSphere.js index 4b9986b60416..b1e0a738c18f 100644 --- a/packages/engine/Source/Core/BoundingSphere.js +++ b/packages/engine/Source/Core/BoundingSphere.js @@ -1,7 +1,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Ellipsoid from "./Ellipsoid.js"; import GeographicProjection from "./GeographicProjection.js"; @@ -30,14 +29,14 @@ function BoundingSphere(center, radius) { * @type {Cartesian3} * @default {@link Cartesian3.ZERO} */ - this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO)); + this.center = Cartesian3.clone(center ?? Cartesian3.ZERO); /** * The radius of the sphere. * @type {number} * @default 0.0 */ - this.radius = defaultValue(radius, 0.0); + this.radius = radius ?? 0.0; } const fromPointsXMin = new Cartesian3(); @@ -276,7 +275,7 @@ BoundingSphere.fromRectangleWithHeights2D = function ( } defaultProjection._ellipsoid = Ellipsoid.default; - projection = defaultValue(projection, defaultProjection); + projection = projection ?? defaultProjection; Rectangle.southwest(rectangle, fromRectangle2DSouthwest); fromRectangle2DSouthwest.height = minimumHeight; @@ -323,8 +322,8 @@ BoundingSphere.fromRectangle3D = function ( surfaceHeight, result, ) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); - surfaceHeight = defaultValue(surfaceHeight, 0.0); + ellipsoid = ellipsoid ?? Ellipsoid.default; + surfaceHeight = surfaceHeight ?? 0.0; if (!defined(result)) { result = new BoundingSphere(); @@ -388,9 +387,9 @@ BoundingSphere.fromVertices = function (positions, center, stride, result) { return result; } - center = defaultValue(center, Cartesian3.ZERO); + center = center ?? Cartesian3.ZERO; - stride = defaultValue(stride, 3); + stride = stride ?? 3; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals("stride", stride, 3); @@ -956,7 +955,7 @@ BoundingSphere.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const center = value.center; array[startingIndex++] = center.x; @@ -980,7 +979,7 @@ BoundingSphere.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new BoundingSphere(); @@ -1279,7 +1278,7 @@ BoundingSphere.projectTo2D = function (sphere, projection, result) { //>>includeEnd('debug'); projectTo2DProjection._ellipsoid = Ellipsoid.default; - projection = defaultValue(projection, projectTo2DProjection); + projection = projection ?? projectTo2DProjection; const ellipsoid = projection.ellipsoid; let center = sphere.center; diff --git a/packages/engine/Source/Core/BoxGeometry.js b/packages/engine/Source/Core/BoxGeometry.js index d6b4e6bc321a..ec797848f5bc 100644 --- a/packages/engine/Source/Core/BoxGeometry.js +++ b/packages/engine/Source/Core/BoxGeometry.js @@ -40,7 +40,7 @@ const diffScratch = new Cartesian3(); * const geometry = Cesium.BoxGeometry.createGeometry(box); */ function BoxGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const min = options.minimum; const max = options.maximum; @@ -58,7 +58,7 @@ function BoxGeometry(options) { } //>>includeEnd('debug'); - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; this._minimum = Cartesian3.clone(min); this._maximum = Cartesian3.clone(max); @@ -88,7 +88,7 @@ function BoxGeometry(options) { * @see BoxGeometry.createGeometry */ BoxGeometry.fromDimensions = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const dimensions = options.dimensions; //>>includeStart('debug', pragmas.debug); @@ -161,7 +161,7 @@ BoxGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value._minimum, array, startingIndex); Cartesian3.pack( @@ -176,7 +176,7 @@ BoxGeometry.pack = function (value, array, startingIndex) { ); array[ startingIndex + 2 * Cartesian3.packedLength + VertexFormat.packedLength - ] = defaultValue(value._offsetAttribute, -1); + ] = value._offsetAttribute ?? -1; return array; }; @@ -204,7 +204,7 @@ BoxGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const min = Cartesian3.unpack(array, startingIndex, scratchMin); const max = Cartesian3.unpack( diff --git a/packages/engine/Source/Core/BoxOutlineGeometry.js b/packages/engine/Source/Core/BoxOutlineGeometry.js index 1933cdad1a40..b631686c62d2 100644 --- a/packages/engine/Source/Core/BoxOutlineGeometry.js +++ b/packages/engine/Source/Core/BoxOutlineGeometry.js @@ -35,7 +35,7 @@ const diffScratch = new Cartesian3(); * const geometry = Cesium.BoxOutlineGeometry.createGeometry(box); */ function BoxOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const min = options.minimum; const max = options.maximum; @@ -78,7 +78,7 @@ function BoxOutlineGeometry(options) { * @see BoxOutlineGeometry.createGeometry */ BoxOutlineGeometry.fromDimensions = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const dimensions = options.dimensions; //>>includeStart('debug', pragmas.debug); @@ -149,14 +149,12 @@ BoxOutlineGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value._min, array, startingIndex); Cartesian3.pack(value._max, array, startingIndex + Cartesian3.packedLength); - array[startingIndex + Cartesian3.packedLength * 2] = defaultValue( - value._offsetAttribute, - -1, - ); + array[startingIndex + Cartesian3.packedLength * 2] = + value._offsetAttribute ?? -1; return array; }; @@ -182,7 +180,7 @@ BoxOutlineGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const min = Cartesian3.unpack(array, startingIndex, scratchMin); const max = Cartesian3.unpack( diff --git a/packages/engine/Source/Core/Cartesian2.js b/packages/engine/Source/Core/Cartesian2.js index 6993889d5a8b..bd7d21ad931f 100644 --- a/packages/engine/Source/Core/Cartesian2.js +++ b/packages/engine/Source/Core/Cartesian2.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import CesiumMath from "./Math.js"; @@ -22,14 +21,14 @@ function Cartesian2(x, y) { * @type {number} * @default 0.0 */ - this.x = defaultValue(x, 0.0); + this.x = x ?? 0.0; /** * The Y component. * @type {number} * @default 0.0 */ - this.y = defaultValue(y, 0.0); + this.y = y ?? 0.0; } /** @@ -113,7 +112,7 @@ Cartesian2.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.x; array[startingIndex] = value.y; @@ -134,7 +133,7 @@ Cartesian2.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Cartesian2(); diff --git a/packages/engine/Source/Core/Cartesian3.js b/packages/engine/Source/Core/Cartesian3.js index c4415d6bace4..56e7e99fb50e 100644 --- a/packages/engine/Source/Core/Cartesian3.js +++ b/packages/engine/Source/Core/Cartesian3.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import CesiumMath from "./Math.js"; @@ -23,21 +22,21 @@ function Cartesian3(x, y, z) { * @type {number} * @default 0.0 */ - this.x = defaultValue(x, 0.0); + this.x = x ?? 0.0; /** * The Y component. * @type {number} * @default 0.0 */ - this.y = defaultValue(y, 0.0); + this.y = y ?? 0.0; /** * The Z component. * @type {number} * @default 0.0 */ - this.z = defaultValue(z, 0.0); + this.z = z ?? 0.0; } /** @@ -58,7 +57,7 @@ Cartesian3.fromSpherical = function (spherical, result) { const clock = spherical.clock; const cone = spherical.cone; - const magnitude = defaultValue(spherical.magnitude, 1.0); + const magnitude = spherical.magnitude ?? 1.0; const radial = magnitude * Math.sin(cone); result.x = radial * Math.cos(clock); result.y = radial * Math.sin(clock); @@ -139,7 +138,7 @@ Cartesian3.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.x; array[startingIndex++] = value.y; @@ -161,7 +160,7 @@ Cartesian3.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Cartesian3(); @@ -925,7 +924,7 @@ Cartesian3.fromRadians = function ( Check.typeOf.number("latitude", latitude); //>>includeEnd('debug'); - height = defaultValue(height, 0.0); + height = height ?? 0.0; const radiiSquared = !defined(ellipsoid) ? Cartesian3._ellipsoidRadiiSquared diff --git a/packages/engine/Source/Core/Cartesian4.js b/packages/engine/Source/Core/Cartesian4.js index a2bffc45b705..4cb9112d951a 100644 --- a/packages/engine/Source/Core/Cartesian4.js +++ b/packages/engine/Source/Core/Cartesian4.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import CesiumMath from "./Math.js"; @@ -24,28 +23,28 @@ function Cartesian4(x, y, z, w) { * @type {number} * @default 0.0 */ - this.x = defaultValue(x, 0.0); + this.x = x ?? 0.0; /** * The Y component. * @type {number} * @default 0.0 */ - this.y = defaultValue(y, 0.0); + this.y = y ?? 0.0; /** * The Z component. * @type {number} * @default 0.0 */ - this.z = defaultValue(z, 0.0); + this.z = z ?? 0.0; /** * The W component. * @type {number} * @default 0.0 */ - this.w = defaultValue(w, 0.0); + this.w = w ?? 0.0; } /** @@ -137,7 +136,7 @@ Cartesian4.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.x; array[startingIndex++] = value.y; @@ -160,7 +159,7 @@ Cartesian4.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Cartesian4(); diff --git a/packages/engine/Source/Core/Cartographic.js b/packages/engine/Source/Core/Cartographic.js index 091d80895ca8..6e57bf57d7bf 100644 --- a/packages/engine/Source/Core/Cartographic.js +++ b/packages/engine/Source/Core/Cartographic.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import CesiumMath from "./Math.js"; import scaleToGeodeticSurface from "./scaleToGeodeticSurface.js"; @@ -22,21 +21,21 @@ function Cartographic(longitude, latitude, height) { * @type {number} * @default 0.0 */ - this.longitude = defaultValue(longitude, 0.0); + this.longitude = longitude ?? 0.0; /** * The latitude, in radians. * @type {number} * @default 0.0 */ - this.latitude = defaultValue(latitude, 0.0); + this.latitude = latitude ?? 0.0; /** * The height, in meters, above the ellipsoid. * @type {number} * @default 0.0 */ - this.height = defaultValue(height, 0.0); + this.height = height ?? 0.0; } /** @@ -55,7 +54,7 @@ Cartographic.fromRadians = function (longitude, latitude, height, result) { Check.typeOf.number("latitude", latitude); //>>includeEnd('debug'); - height = defaultValue(height, 0.0); + height = height ?? 0.0; if (!defined(result)) { return new Cartographic(longitude, latitude, height); @@ -240,7 +239,7 @@ Cartographic.equals = function (left, right) { * @returns {boolean} true if left and right are within the provided epsilon, false otherwise. */ Cartographic.equalsEpsilon = function (left, right, epsilon) { - epsilon = defaultValue(epsilon, 0); + epsilon = epsilon ?? 0; return ( left === right || diff --git a/packages/engine/Source/Core/CatmullRomSpline.js b/packages/engine/Source/Core/CatmullRomSpline.js index b2181f642e67..eab04bad8569 100644 --- a/packages/engine/Source/Core/CatmullRomSpline.js +++ b/packages/engine/Source/Core/CatmullRomSpline.js @@ -148,7 +148,7 @@ const lastTangentScratch = new Cartesian3(); * @see MorphWeightSpline */ function CatmullRomSpline(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const points = options.points; const times = options.times; diff --git a/packages/engine/Source/Core/CesiumTerrainProvider.js b/packages/engine/Source/Core/CesiumTerrainProvider.js index 64497322ab0b..2a63023b11c0 100644 --- a/packages/engine/Source/Core/CesiumTerrainProvider.js +++ b/packages/engine/Source/Core/CesiumTerrainProvider.js @@ -59,10 +59,10 @@ function LayerInformation(layer) { * @param {CesiumTerrainProvider.ConstructorOptions} options An object describing initialization options */ function TerrainProviderBuilder(options) { - this.requestVertexNormals = defaultValue(options.requestVertexNormals, false); - this.requestWaterMask = defaultValue(options.requestWaterMask, false); - this.requestMetadata = defaultValue(options.requestMetadata, true); - this.ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + this.requestVertexNormals = options.requestVertexNormals ?? false; + this.requestWaterMask = options.requestWaterMask ?? false; + this.requestMetadata = options.requestMetadata ?? true; + this.ellipsoid = options.ellipsoid ?? Ellipsoid.default; this.heightmapWidth = 65; this.heightmapStructure = undefined; @@ -475,7 +475,7 @@ async function requestLayerJson(terrainProviderBuilder, provider) { * @see TerrainProvider */ function CesiumTerrainProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._heightmapWidth = undefined; this._heightmapStructure = undefined; @@ -491,10 +491,7 @@ function CesiumTerrainProvider(options) { * @default false * @private */ - this._requestVertexNormals = defaultValue( - options.requestVertexNormals, - false, - ); + this._requestVertexNormals = options.requestVertexNormals ?? false; /** * Boolean flag that indicates if the client should request tile watermasks from the server. @@ -502,7 +499,7 @@ function CesiumTerrainProvider(options) { * @default false * @private */ - this._requestWaterMask = defaultValue(options.requestWaterMask, false); + this._requestWaterMask = options.requestWaterMask ?? false; /** * Boolean flag that indicates if the client should request tile metadata from the server. @@ -510,7 +507,7 @@ function CesiumTerrainProvider(options) { * @default true * @private */ - this._requestMetadata = defaultValue(options.requestMetadata, true); + this._requestMetadata = options.requestMetadata ?? true; this._errorEvent = new Event(); @@ -1229,7 +1226,7 @@ CesiumTerrainProvider.fromUrl = async function (url, options) { Check.defined("url", url); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; url = await Promise.resolve(url); const resource = Resource.createIfNeeded(url); diff --git a/packages/engine/Source/Core/CircleGeometry.js b/packages/engine/Source/Core/CircleGeometry.js index 0f4b0c2bf1e8..0eb0b1b46ff3 100644 --- a/packages/engine/Source/Core/CircleGeometry.js +++ b/packages/engine/Source/Core/CircleGeometry.js @@ -37,7 +37,7 @@ import VertexFormat from "./VertexFormat.js"; * const geometry = Cesium.CircleGeometry.createGeometry(circle); */ function CircleGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const radius = options.radius; //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Core/CircleOutlineGeometry.js b/packages/engine/Source/Core/CircleOutlineGeometry.js index 98662f200a21..2d989ae28b9f 100644 --- a/packages/engine/Source/Core/CircleOutlineGeometry.js +++ b/packages/engine/Source/Core/CircleOutlineGeometry.js @@ -35,7 +35,7 @@ import Ellipsoid from "./Ellipsoid.js"; * const geometry = Cesium.CircleOutlineGeometry.createGeometry(circle); */ function CircleOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const radius = options.radius; //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Core/Clock.js b/packages/engine/Source/Core/Clock.js index 272b9dc78915..153b10af73c5 100644 --- a/packages/engine/Source/Core/Clock.js +++ b/packages/engine/Source/Core/Clock.js @@ -41,7 +41,7 @@ import JulianDate from "./JulianDate.js"; * @see JulianDate */ function Clock(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let currentTime = options.currentTime; let startTime = options.startTime; @@ -103,7 +103,7 @@ function Clock(options) { * @type {ClockRange} * @default {@link ClockRange.UNBOUNDED} */ - this.clockRange = defaultValue(options.clockRange, ClockRange.UNBOUNDED); + this.clockRange = options.clockRange ?? ClockRange.UNBOUNDED; /** * Indicates whether {@link Clock#tick} can advance time. This could be false if data is being buffered, @@ -112,7 +112,7 @@ function Clock(options) { * @type {boolean} * @default true */ - this.canAnimate = defaultValue(options.canAnimate, true); + this.canAnimate = options.canAnimate ?? true; /** * An {@link Event} that is fired whenever {@link Clock#tick} is called. @@ -135,12 +135,9 @@ function Clock(options) { // make values consistent. this.currentTime = currentTime; - this.multiplier = defaultValue(options.multiplier, 1.0); - this.shouldAnimate = defaultValue(options.shouldAnimate, false); - this.clockStep = defaultValue( - options.clockStep, - ClockStep.SYSTEM_CLOCK_MULTIPLIER, - ); + this.multiplier = options.multiplier ?? 1.0; + this.shouldAnimate = options.shouldAnimate ?? false; + this.clockStep = options.clockStep ?? ClockStep.SYSTEM_CLOCK_MULTIPLIER; } Object.defineProperties(Clock.prototype, { diff --git a/packages/engine/Source/Core/Color.js b/packages/engine/Source/Core/Color.js index 8fd5b033119f..f7190ed20aa1 100644 --- a/packages/engine/Source/Core/Color.js +++ b/packages/engine/Source/Core/Color.js @@ -42,25 +42,25 @@ function Color(red, green, blue, alpha) { * @type {number} * @default 1.0 */ - this.red = defaultValue(red, 1.0); + this.red = red ?? 1.0; /** * The green component. * @type {number} * @default 1.0 */ - this.green = defaultValue(green, 1.0); + this.green = green ?? 1.0; /** * The blue component. * @type {number} * @default 1.0 */ - this.blue = defaultValue(blue, 1.0); + this.blue = blue ?? 1.0; /** * The alpha component. * @type {number} * @default 1.0 */ - this.alpha = defaultValue(alpha, 1.0); + this.alpha = alpha ?? 1.0; } /** @@ -99,10 +99,10 @@ Color.fromCartesian4 = function (cartesian, result) { * @returns {Color} The modified result parameter or a new Color instance if one was not provided. */ Color.fromBytes = function (red, green, blue, alpha, result) { - red = Color.byteToFloat(defaultValue(red, 255.0)); - green = Color.byteToFloat(defaultValue(green, 255.0)); - blue = Color.byteToFloat(defaultValue(blue, 255.0)); - alpha = Color.byteToFloat(defaultValue(alpha, 255.0)); + red = Color.byteToFloat(red ?? 255.0); + green = Color.byteToFloat(green ?? 255.0); + blue = Color.byteToFloat(blue ?? 255.0); + alpha = Color.byteToFloat(alpha ?? 255.0); if (!defined(result)) { return new Color(red, green, blue, alpha); @@ -190,10 +190,10 @@ Color.fromRgba = function (rgba, result) { * @see {@link http://www.w3.org/TR/css3-color/#hsl-color|CSS color values} */ Color.fromHsl = function (hue, saturation, lightness, alpha, result) { - hue = defaultValue(hue, 0.0) % 1.0; - saturation = defaultValue(saturation, 0.0); - lightness = defaultValue(lightness, 0.0); - alpha = defaultValue(alpha, 1.0); + hue = (hue ?? 0.0) % 1.0; + saturation = saturation ?? 0.0; + lightness = lightness ?? 0.0; + alpha = alpha ?? 1.0; let red = lightness; let green = lightness; @@ -269,12 +269,12 @@ Color.fromHsl = function (hue, saturation, lightness, alpha, result) { * }); */ Color.fromRandom = function (options, result) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let red = options.red; if (!defined(red)) { - const minimumRed = defaultValue(options.minimumRed, 0); - const maximumRed = defaultValue(options.maximumRed, 1.0); + const minimumRed = options.minimumRed ?? 0; + const maximumRed = options.maximumRed ?? 1.0; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.lessThanOrEquals("minimumRed", minimumRed, maximumRed); @@ -286,8 +286,8 @@ Color.fromRandom = function (options, result) { let green = options.green; if (!defined(green)) { - const minimumGreen = defaultValue(options.minimumGreen, 0); - const maximumGreen = defaultValue(options.maximumGreen, 1.0); + const minimumGreen = options.minimumGreen ?? 0; + const maximumGreen = options.maximumGreen ?? 1.0; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.lessThanOrEquals( @@ -303,8 +303,8 @@ Color.fromRandom = function (options, result) { let blue = options.blue; if (!defined(blue)) { - const minimumBlue = defaultValue(options.minimumBlue, 0); - const maximumBlue = defaultValue(options.maximumBlue, 1.0); + const minimumBlue = options.minimumBlue ?? 0; + const maximumBlue = options.maximumBlue ?? 1.0; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.lessThanOrEquals( @@ -320,8 +320,8 @@ Color.fromRandom = function (options, result) { let alpha = options.alpha; if (!defined(alpha)) { - const minimumAlpha = defaultValue(options.minimumAlpha, 0); - const maximumAlpha = defaultValue(options.maximumAlpha, 1.0); + const minimumAlpha = options.minimumAlpha ?? 0; + const maximumAlpha = options.maximumAlpha ?? 1.0; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.lessThanOrEquals( @@ -396,7 +396,7 @@ Color.fromCssColorString = function (color, result) { result.red = parseInt(matches[1], 16) / 15; result.green = parseInt(matches[2], 16) / 15.0; result.blue = parseInt(matches[3], 16) / 15.0; - result.alpha = parseInt(defaultValue(matches[4], "f"), 16) / 15.0; + result.alpha = parseInt(matches[4] ?? "f", 16) / 15.0; return result; } @@ -405,7 +405,7 @@ Color.fromCssColorString = function (color, result) { result.red = parseInt(matches[1], 16) / 255.0; result.green = parseInt(matches[2], 16) / 255.0; result.blue = parseInt(matches[3], 16) / 255.0; - result.alpha = parseInt(defaultValue(matches[4], "ff"), 16) / 255.0; + result.alpha = parseInt(matches[4] ?? "ff", 16) / 255.0; return result; } @@ -417,7 +417,7 @@ Color.fromCssColorString = function (color, result) { parseFloat(matches[2]) / ("%" === matches[2].substr(-1) ? 100.0 : 255.0); result.blue = parseFloat(matches[3]) / ("%" === matches[3].substr(-1) ? 100.0 : 255.0); - result.alpha = parseFloat(defaultValue(matches[4], "1.0")); + result.alpha = parseFloat(matches[4] ?? "1.0"); return result; } @@ -427,7 +427,7 @@ Color.fromCssColorString = function (color, result) { parseFloat(matches[1]) / 360.0, parseFloat(matches[2]) / 100.0, parseFloat(matches[3]) / 100.0, - parseFloat(defaultValue(matches[4], "1.0")), + parseFloat(matches[4] ?? "1.0"), result, ); } @@ -457,7 +457,7 @@ Color.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.red; array[startingIndex++] = value.green; array[startingIndex++] = value.blue; @@ -479,7 +479,7 @@ Color.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Color(); } diff --git a/packages/engine/Source/Core/ColorGeometryInstanceAttribute.js b/packages/engine/Source/Core/ColorGeometryInstanceAttribute.js index 87992d602b2f..41983e91f29f 100644 --- a/packages/engine/Source/Core/ColorGeometryInstanceAttribute.js +++ b/packages/engine/Source/Core/ColorGeometryInstanceAttribute.js @@ -1,6 +1,5 @@ import Color from "./Color.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -33,10 +32,10 @@ import DeveloperError from "./DeveloperError.js"; * @see GeometryInstanceAttribute */ function ColorGeometryInstanceAttribute(red, green, blue, alpha) { - red = defaultValue(red, 1.0); - green = defaultValue(green, 1.0); - blue = defaultValue(blue, 1.0); - alpha = defaultValue(alpha, 1.0); + red = red ?? 1.0; + green = green ?? 1.0; + blue = blue ?? 1.0; + alpha = alpha ?? 1.0; /** * The values for the attributes stored in a typed array. diff --git a/packages/engine/Source/Core/ComponentDatatype.js b/packages/engine/Source/Core/ComponentDatatype.js index 4e6a3892148a..d6b3c1faa0f2 100644 --- a/packages/engine/Source/Core/ComponentDatatype.js +++ b/packages/engine/Source/Core/ComponentDatatype.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import WebGLConstants from "./WebGLConstants.js"; @@ -274,12 +273,11 @@ ComponentDatatype.createArrayBufferView = function ( } //>>includeEnd('debug'); - byteOffset = defaultValue(byteOffset, 0); - length = defaultValue( - length, + byteOffset = byteOffset ?? 0; + length = + length ?? (buffer.byteLength - byteOffset) / - ComponentDatatype.getSizeInBytes(componentDatatype), - ); + ComponentDatatype.getSizeInBytes(componentDatatype); switch (componentDatatype) { case ComponentDatatype.BYTE: diff --git a/packages/engine/Source/Core/CoplanarPolygonGeometry.js b/packages/engine/Source/Core/CoplanarPolygonGeometry.js index 8d2c7def35cb..9f0c843efce1 100644 --- a/packages/engine/Source/Core/CoplanarPolygonGeometry.js +++ b/packages/engine/Source/Core/CoplanarPolygonGeometry.js @@ -247,20 +247,18 @@ function createGeometryFromPolygon( * */ function CoplanarPolygonGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const polygonHierarchy = options.polygonHierarchy; const textureCoordinates = options.textureCoordinates; //>>includeStart('debug', pragmas.debug); Check.defined("options.polygonHierarchy", polygonHierarchy); //>>includeEnd('debug'); - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; this._vertexFormat = VertexFormat.clone(vertexFormat); this._polygonHierarchy = polygonHierarchy; - this._stRotation = defaultValue(options.stRotation, 0.0); - this._ellipsoid = Ellipsoid.clone( - defaultValue(options.ellipsoid, Ellipsoid.default), - ); + this._stRotation = options.stRotation ?? 0.0; + this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default); this._workerName = "createCoplanarPolygonGeometry"; this._textureCoordinates = textureCoordinates; @@ -311,7 +309,7 @@ function CoplanarPolygonGeometry(options) { * @see PolygonGeometry#createGeometry */ CoplanarPolygonGeometry.fromPositions = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.positions", options.positions); @@ -344,7 +342,7 @@ CoplanarPolygonGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; startingIndex = PolygonGeometryLibrary.packPolygonHierarchy( value._polygonHierarchy, @@ -393,7 +391,7 @@ CoplanarPolygonGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy( array, diff --git a/packages/engine/Source/Core/CoplanarPolygonOutlineGeometry.js b/packages/engine/Source/Core/CoplanarPolygonOutlineGeometry.js index 011799c84f8d..fe8cdeb71074 100644 --- a/packages/engine/Source/Core/CoplanarPolygonOutlineGeometry.js +++ b/packages/engine/Source/Core/CoplanarPolygonOutlineGeometry.js @@ -71,7 +71,7 @@ function createGeometryFromPositions(positions) { * const geometry = Cesium.CoplanarPolygonOutlineGeometry.createGeometry(polygonOutline); */ function CoplanarPolygonOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const polygonHierarchy = options.polygonHierarchy; //>>includeStart('debug', pragmas.debug); Check.defined("options.polygonHierarchy", polygonHierarchy); @@ -99,7 +99,7 @@ function CoplanarPolygonOutlineGeometry(options) { * @returns {CoplanarPolygonOutlineGeometry} */ CoplanarPolygonOutlineGeometry.fromPositions = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.positions", options.positions); @@ -128,7 +128,7 @@ CoplanarPolygonOutlineGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; startingIndex = PolygonGeometryLibrary.packPolygonHierarchy( value._polygonHierarchy, @@ -162,7 +162,7 @@ CoplanarPolygonOutlineGeometry.unpack = function ( Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy( array, diff --git a/packages/engine/Source/Core/CorridorGeometry.js b/packages/engine/Source/Core/CorridorGeometry.js index 0b5ead6bfcc0..55029e3f4c36 100644 --- a/packages/engine/Source/Core/CorridorGeometry.js +++ b/packages/engine/Source/Core/CorridorGeometry.js @@ -1070,7 +1070,7 @@ function computeRectangle(positions, ellipsoid, width, cornerType, result) { * }); */ function CorridorGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; const width = options.width; @@ -1079,25 +1079,20 @@ function CorridorGeometry(options) { Check.defined("options.width", width); //>>includeEnd('debug'); - const height = defaultValue(options.height, 0.0); - const extrudedHeight = defaultValue(options.extrudedHeight, height); + const height = options.height ?? 0.0; + const extrudedHeight = options.extrudedHeight ?? height; this._positions = positions; - this._ellipsoid = Ellipsoid.clone( - defaultValue(options.ellipsoid, Ellipsoid.default), - ); + this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default); this._vertexFormat = VertexFormat.clone( - defaultValue(options.vertexFormat, VertexFormat.DEFAULT), + options.vertexFormat ?? VertexFormat.DEFAULT, ); this._width = width; this._height = Math.max(height, extrudedHeight); this._extrudedHeight = Math.min(height, extrudedHeight); - this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); - this._granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - this._shadowVolume = defaultValue(options.shadowVolume, false); + this._cornerType = options.cornerType ?? CornerType.ROUNDED; + this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + this._shadowVolume = options.shadowVolume ?? false; this._workerName = "createCorridorGeometry"; this._offsetAttribute = options.offsetAttribute; this._rectangle = undefined; @@ -1129,7 +1124,7 @@ CorridorGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const positions = value._positions; const length = positions.length; @@ -1151,7 +1146,7 @@ CorridorGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._cornerType; array[startingIndex++] = value._granularity; array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -1184,7 +1179,7 @@ CorridorGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const length = array[startingIndex++]; const positions = new Array(length); @@ -1253,7 +1248,7 @@ CorridorGeometry.unpack = function (array, startingIndex, result) { * @returns {Rectangle} The result rectangle. */ CorridorGeometry.computeRectangle = function (options, result) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; const width = options.width; @@ -1262,8 +1257,8 @@ CorridorGeometry.computeRectangle = function (options, result) { Check.defined("options.width", width); //>>includeEnd('debug'); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - const cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; + const cornerType = options.cornerType ?? CornerType.ROUNDED; return computeRectangle(positions, ellipsoid, width, cornerType, result); }; diff --git a/packages/engine/Source/Core/CorridorOutlineGeometry.js b/packages/engine/Source/Core/CorridorOutlineGeometry.js index 5718f107d2f0..294b82443baf 100644 --- a/packages/engine/Source/Core/CorridorOutlineGeometry.js +++ b/packages/engine/Source/Core/CorridorOutlineGeometry.js @@ -376,7 +376,7 @@ function computePositionsExtruded(params) { * }); */ function CorridorOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; const width = options.width; @@ -385,21 +385,16 @@ function CorridorOutlineGeometry(options) { Check.typeOf.number("options.width", width); //>>includeEnd('debug'); - const height = defaultValue(options.height, 0.0); - const extrudedHeight = defaultValue(options.extrudedHeight, height); + const height = options.height ?? 0.0; + const extrudedHeight = options.extrudedHeight ?? height; this._positions = positions; - this._ellipsoid = Ellipsoid.clone( - defaultValue(options.ellipsoid, Ellipsoid.default), - ); + this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default); this._width = width; this._height = Math.max(height, extrudedHeight); this._extrudedHeight = Math.min(height, extrudedHeight); - this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); - this._granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); + this._cornerType = options.cornerType ?? CornerType.ROUNDED; + this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; this._offsetAttribute = options.offsetAttribute; this._workerName = "createCorridorOutlineGeometry"; @@ -426,7 +421,7 @@ CorridorOutlineGeometry.pack = function (value, array, startingIndex) { Check.typeOf.object("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const positions = value._positions; const length = positions.length; @@ -444,7 +439,7 @@ CorridorOutlineGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._cornerType; array[startingIndex++] = value._granularity; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -474,7 +469,7 @@ CorridorOutlineGeometry.unpack = function (array, startingIndex, result) { Check.typeOf.object("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const length = array[startingIndex++]; const positions = new Array(length); diff --git a/packages/engine/Source/Core/Credit.js b/packages/engine/Source/Core/Credit.js index bbbe7984a43f..28c541f84183 100644 --- a/packages/engine/Source/Core/Credit.js +++ b/packages/engine/Source/Core/Credit.js @@ -1,6 +1,5 @@ import DOMPurify from "dompurify"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; let nextCreditId = 0; @@ -34,7 +33,7 @@ function Credit(html, showOnScreen) { creditToId[key] = id; } - showOnScreen = defaultValue(showOnScreen, false); + showOnScreen = showOnScreen ?? false; // Credits are immutable so generate an id to use to optimize equal() this._id = id; diff --git a/packages/engine/Source/Core/CullingVolume.js b/packages/engine/Source/Core/CullingVolume.js index 67b7724c27f0..57017a271884 100644 --- a/packages/engine/Source/Core/CullingVolume.js +++ b/packages/engine/Source/Core/CullingVolume.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Cartesian4 from "./Cartesian4.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Intersect from "./Intersect.js"; @@ -22,7 +21,7 @@ function CullingVolume(planes) { * @type {Cartesian4[]} * @default [] */ - this.planes = defaultValue(planes, []); + this.planes = planes ?? []; } const faces = [new Cartesian3(), new Cartesian3(), new Cartesian3()]; diff --git a/packages/engine/Source/Core/CustomHeightmapTerrainProvider.js b/packages/engine/Source/Core/CustomHeightmapTerrainProvider.js index eeefc818e31a..919eee2155a0 100644 --- a/packages/engine/Source/Core/CustomHeightmapTerrainProvider.js +++ b/packages/engine/Source/Core/CustomHeightmapTerrainProvider.js @@ -54,7 +54,7 @@ import TerrainProvider from "./TerrainProvider.js"; * @see TerrainProvider */ function CustomHeightmapTerrainProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.callback", options.callback); @@ -67,7 +67,7 @@ function CustomHeightmapTerrainProvider(options) { this._tilingScheme = options.tilingScheme; if (!defined(this._tilingScheme)) { this._tilingScheme = new GeographicTilingScheme({ - ellipsoid: defaultValue(options.ellipsoid, Ellipsoid.default), + ellipsoid: options.ellipsoid ?? Ellipsoid.default, }); } diff --git a/packages/engine/Source/Core/CylinderGeometry.js b/packages/engine/Source/Core/CylinderGeometry.js index 2733c91d36a2..bcbd8d199780 100644 --- a/packages/engine/Source/Core/CylinderGeometry.js +++ b/packages/engine/Source/Core/CylinderGeometry.js @@ -48,13 +48,13 @@ const positionScratch = new Cartesian3(); * const geometry = Cesium.CylinderGeometry.createGeometry(cylinder); */ function CylinderGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const length = options.length; const topRadius = options.topRadius; const bottomRadius = options.bottomRadius; - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - const slices = defaultValue(options.slices, 128); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; + const slices = options.slices ?? 128; //>>includeStart('debug', pragmas.debug); if (!defined(length)) { @@ -115,7 +115,7 @@ CylinderGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; VertexFormat.pack(value._vertexFormat, array, startingIndex); startingIndex += VertexFormat.packedLength; @@ -124,7 +124,7 @@ CylinderGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._topRadius; array[startingIndex++] = value._bottomRadius; array[startingIndex++] = value._slices; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -154,7 +154,7 @@ CylinderGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const vertexFormat = VertexFormat.unpack( array, diff --git a/packages/engine/Source/Core/CylinderOutlineGeometry.js b/packages/engine/Source/Core/CylinderOutlineGeometry.js index 45e7e57fa094..c0e9d767bc9f 100644 --- a/packages/engine/Source/Core/CylinderOutlineGeometry.js +++ b/packages/engine/Source/Core/CylinderOutlineGeometry.js @@ -47,14 +47,14 @@ const radiusScratch = new Cartesian2(); * const geometry = Cesium.CylinderOutlineGeometry.createGeometry(cylinder); */ function CylinderOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const length = options.length; const topRadius = options.topRadius; const bottomRadius = options.bottomRadius; - const slices = defaultValue(options.slices, 128); + const slices = options.slices ?? 128; const numberOfVerticalLines = Math.max( - defaultValue(options.numberOfVerticalLines, 16), + options.numberOfVerticalLines ?? 16, 0, ); @@ -103,14 +103,14 @@ CylinderOutlineGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value._length; array[startingIndex++] = value._topRadius; array[startingIndex++] = value._bottomRadius; array[startingIndex++] = value._slices; array[startingIndex++] = value._numberOfVerticalLines; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -137,7 +137,7 @@ CylinderOutlineGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const length = array[startingIndex++]; const topRadius = array[startingIndex++]; diff --git a/packages/engine/Source/Core/DistanceDisplayCondition.js b/packages/engine/Source/Core/DistanceDisplayCondition.js index e00e08aec341..8c908e454c23 100644 --- a/packages/engine/Source/Core/DistanceDisplayCondition.js +++ b/packages/engine/Source/Core/DistanceDisplayCondition.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -16,10 +15,10 @@ import DeveloperError from "./DeveloperError.js"; * billboard.distanceDisplayCondition = new Cesium.DistanceDisplayCondition(10.0, 20.0); */ function DistanceDisplayCondition(near, far) { - near = defaultValue(near, 0.0); + near = near ?? 0.0; this._near = near; - far = defaultValue(far, Number.MAX_VALUE); + far = far ?? Number.MAX_VALUE; this._far = far; } @@ -79,7 +78,7 @@ DistanceDisplayCondition.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.near; array[startingIndex] = value.far; @@ -102,7 +101,7 @@ DistanceDisplayCondition.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new DistanceDisplayCondition(); diff --git a/packages/engine/Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js b/packages/engine/Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js index d999a65cfdff..ce0495253759 100644 --- a/packages/engine/Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js +++ b/packages/engine/Source/Core/DistanceDisplayConditionGeometryInstanceAttribute.js @@ -1,5 +1,4 @@ import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -33,8 +32,8 @@ import DeveloperError from "./DeveloperError.js"; * @see GeometryInstanceAttribute */ function DistanceDisplayConditionGeometryInstanceAttribute(near, far) { - near = defaultValue(near, 0.0); - far = defaultValue(far, Number.MAX_VALUE); + near = near ?? 0.0; + far = far ?? Number.MAX_VALUE; //>>includeStart('debug', pragmas.debug); if (far <= near) { diff --git a/packages/engine/Source/Core/EarthOrientationParameters.js b/packages/engine/Source/Core/EarthOrientationParameters.js index 76a34e141422..3ad14a0a140f 100644 --- a/packages/engine/Source/Core/EarthOrientationParameters.js +++ b/packages/engine/Source/Core/EarthOrientationParameters.js @@ -33,7 +33,7 @@ import TimeStandard from "./TimeStandard.js"; * @private */ function EarthOrientationParameters(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._dates = undefined; this._samples = undefined; @@ -49,7 +49,7 @@ function EarthOrientationParameters(options) { this._columnCount = 0; this._lastIndex = -1; - this._addNewLeapSeconds = defaultValue(options.addNewLeapSeconds, true); + this._addNewLeapSeconds = options.addNewLeapSeconds ?? true; if (defined(options.data)) { // Use supplied EOP data. @@ -107,7 +107,7 @@ EarthOrientationParameters.fromUrl = async function (url, options) { Check.defined("url", url); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resource = Resource.createIfNeeded(url); diff --git a/packages/engine/Source/Core/EllipseGeometry.js b/packages/engine/Source/Core/EllipseGeometry.js index 8908ddfa91a8..60b9ba2edeb5 100644 --- a/packages/engine/Source/Core/EllipseGeometry.js +++ b/packages/engine/Source/Core/EllipseGeometry.js @@ -918,17 +918,14 @@ function computeRectangle( * @see EllipseGeometry.createGeometry */ function EllipseGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const center = options.center; - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; const semiMajorAxis = options.semiMajorAxis; const semiMinorAxis = options.semiMinorAxis; - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; //>>includeStart('debug', pragmas.debug); Check.defined("options.center", center); @@ -944,20 +941,20 @@ function EllipseGeometry(options) { } //>>includeEnd('debug'); - const height = defaultValue(options.height, 0.0); - const extrudedHeight = defaultValue(options.extrudedHeight, height); + const height = options.height ?? 0.0; + const extrudedHeight = options.extrudedHeight ?? height; this._center = Cartesian3.clone(center); this._semiMajorAxis = semiMajorAxis; this._semiMinorAxis = semiMinorAxis; this._ellipsoid = Ellipsoid.clone(ellipsoid); - this._rotation = defaultValue(options.rotation, 0.0); - this._stRotation = defaultValue(options.stRotation, 0.0); + this._rotation = options.rotation ?? 0.0; + this._stRotation = options.stRotation ?? 0.0; this._height = Math.max(extrudedHeight, height); this._granularity = granularity; this._vertexFormat = VertexFormat.clone(vertexFormat); this._extrudedHeight = Math.min(extrudedHeight, height); - this._shadowVolume = defaultValue(options.shadowVolume, false); + this._shadowVolume = options.shadowVolume ?? false; this._workerName = "createEllipseGeometry"; this._offsetAttribute = options.offsetAttribute; @@ -990,7 +987,7 @@ EllipseGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value._center, array, startingIndex); startingIndex += Cartesian3.packedLength; @@ -1009,7 +1006,7 @@ EllipseGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._granularity; array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -1045,7 +1042,7 @@ EllipseGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const center = Cartesian3.unpack(array, startingIndex, scratchCenter); startingIndex += Cartesian3.packedLength; @@ -1117,17 +1114,14 @@ EllipseGeometry.unpack = function (array, startingIndex, result) { * @returns {Rectangle} The result rectangle */ EllipseGeometry.computeRectangle = function (options, result) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const center = options.center; - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; const semiMajorAxis = options.semiMajorAxis; const semiMinorAxis = options.semiMinorAxis; - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const rotation = defaultValue(options.rotation, 0.0); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const rotation = options.rotation ?? 0.0; //>>includeStart('debug', pragmas.debug); Check.defined("options.center", center); diff --git a/packages/engine/Source/Core/EllipseOutlineGeometry.js b/packages/engine/Source/Core/EllipseOutlineGeometry.js index 346bbc3e71bd..cc140519f674 100644 --- a/packages/engine/Source/Core/EllipseOutlineGeometry.js +++ b/packages/engine/Source/Core/EllipseOutlineGeometry.js @@ -137,7 +137,7 @@ function computeExtrudedEllipse(options) { }); } - let numberOfVerticalLines = defaultValue(options.numberOfVerticalLines, 16); + let numberOfVerticalLines = options.numberOfVerticalLines ?? 16; numberOfVerticalLines = CesiumMath.clamp( numberOfVerticalLines, 0, @@ -211,16 +211,13 @@ function computeExtrudedEllipse(options) { * const geometry = Cesium.EllipseOutlineGeometry.createGeometry(ellipse); */ function EllipseOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const center = options.center; - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; const semiMajorAxis = options.semiMajorAxis; const semiMinorAxis = options.semiMinorAxis; - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; //>>includeStart('debug', pragmas.debug); if (!defined(center)) { @@ -242,19 +239,19 @@ function EllipseOutlineGeometry(options) { } //>>includeEnd('debug'); - const height = defaultValue(options.height, 0.0); - const extrudedHeight = defaultValue(options.extrudedHeight, height); + const height = options.height ?? 0.0; + const extrudedHeight = options.extrudedHeight ?? height; this._center = Cartesian3.clone(center); this._semiMajorAxis = semiMajorAxis; this._semiMinorAxis = semiMinorAxis; this._ellipsoid = Ellipsoid.clone(ellipsoid); - this._rotation = defaultValue(options.rotation, 0.0); + this._rotation = options.rotation ?? 0.0; this._height = Math.max(extrudedHeight, height); this._granularity = granularity; this._extrudedHeight = Math.min(extrudedHeight, height); this._numberOfVerticalLines = Math.max( - defaultValue(options.numberOfVerticalLines, 16), + options.numberOfVerticalLines ?? 16, 0, ); this._offsetAttribute = options.offsetAttribute; @@ -287,7 +284,7 @@ EllipseOutlineGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value._center, array, startingIndex); startingIndex += Cartesian3.packedLength; @@ -302,7 +299,7 @@ EllipseOutlineGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._granularity; array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._numberOfVerticalLines; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -337,7 +334,7 @@ EllipseOutlineGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const center = Cartesian3.unpack(array, startingIndex, scratchCenter); startingIndex += Cartesian3.packedLength; diff --git a/packages/engine/Source/Core/Ellipsoid.js b/packages/engine/Source/Core/Ellipsoid.js index def0d0862dee..1a4b2250ab70 100644 --- a/packages/engine/Source/Core/Ellipsoid.js +++ b/packages/engine/Source/Core/Ellipsoid.js @@ -2,16 +2,15 @@ import Cartesian2 from "./Cartesian2.js"; import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import CesiumMath from "./Math.js"; import scaleToGeodeticSurface from "./scaleToGeodeticSurface.js"; function initialize(ellipsoid, x, y, z) { - x = defaultValue(x, 0.0); - y = defaultValue(y, 0.0); - z = defaultValue(z, 0.0); + x = x ?? 0.0; + y = y ?? 0.0; + z = z ?? 0.0; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals("x", x, 0.0); @@ -321,7 +320,7 @@ Ellipsoid.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value._radii, array, startingIndex); @@ -341,7 +340,7 @@ Ellipsoid.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const radii = Cartesian3.unpack(array, startingIndex); return Ellipsoid.fromCartesian3(radii, result); @@ -716,7 +715,7 @@ Ellipsoid.prototype.getSurfaceNormalIntersectionWithZAxis = function ( Check.typeOf.number.greaterThan("Ellipsoid.radii.z", this._radii.z, 0); //>>includeEnd('debug'); - buffer = defaultValue(buffer, 0.0); + buffer = buffer ?? 0.0; const squaredXOverSquaredZ = this._squaredXOverSquaredZ; diff --git a/packages/engine/Source/Core/EllipsoidGeodesic.js b/packages/engine/Source/Core/EllipsoidGeodesic.js index ce3ce373b4b1..37a0335ad7d6 100644 --- a/packages/engine/Source/Core/EllipsoidGeodesic.js +++ b/packages/engine/Source/Core/EllipsoidGeodesic.js @@ -1,7 +1,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Ellipsoid from "./Ellipsoid.js"; import CesiumMath from "./Math.js"; @@ -284,7 +283,7 @@ function computeProperties(ellipsoidGeodesic, start, end, ellipsoid) { * @param {Ellipsoid} [ellipsoid=Ellipsoid.default] The ellipsoid on which the geodesic lies. */ function EllipsoidGeodesic(start, end, ellipsoid) { - const e = defaultValue(ellipsoid, Ellipsoid.default); + const e = ellipsoid ?? Ellipsoid.default; this._ellipsoid = e; this._start = new Cartographic(); this._end = new Cartographic(); diff --git a/packages/engine/Source/Core/EllipsoidGeometry.js b/packages/engine/Source/Core/EllipsoidGeometry.js index 3912ad9c4d10..f60b039da5be 100644 --- a/packages/engine/Source/Core/EllipsoidGeometry.js +++ b/packages/engine/Source/Core/EllipsoidGeometry.js @@ -55,17 +55,17 @@ const sin = Math.sin; * const geometry = Cesium.EllipsoidGeometry.createGeometry(ellipsoid); */ function EllipsoidGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - - const radii = defaultValue(options.radii, defaultRadii); - const innerRadii = defaultValue(options.innerRadii, radii); - const minimumClock = defaultValue(options.minimumClock, 0.0); - const maximumClock = defaultValue(options.maximumClock, CesiumMath.TWO_PI); - const minimumCone = defaultValue(options.minimumCone, 0.0); - const maximumCone = defaultValue(options.maximumCone, CesiumMath.PI); - const stackPartitions = Math.round(defaultValue(options.stackPartitions, 64)); - const slicePartitions = Math.round(defaultValue(options.slicePartitions, 64)); - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + options = options ?? defaultValue.EMPTY_OBJECT; + + const radii = options.radii ?? defaultRadii; + const innerRadii = options.innerRadii ?? radii; + const minimumClock = options.minimumClock ?? 0.0; + const maximumClock = options.maximumClock ?? CesiumMath.TWO_PI; + const minimumCone = options.minimumCone ?? 0.0; + const maximumCone = options.maximumCone ?? CesiumMath.PI; + const stackPartitions = Math.round(options.stackPartitions ?? 64); + const slicePartitions = Math.round(options.slicePartitions ?? 64); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; //>>includeStart('debug', pragmas.debug); if (slicePartitions < 3) { @@ -119,7 +119,7 @@ EllipsoidGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value._radii, array, startingIndex); startingIndex += Cartesian3.packedLength; @@ -136,7 +136,7 @@ EllipsoidGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._maximumCone; array[startingIndex++] = value._stackPartitions; array[startingIndex++] = value._slicePartitions; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -172,7 +172,7 @@ EllipsoidGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const radii = Cartesian3.unpack(array, startingIndex, scratchRadii); startingIndex += Cartesian3.packedLength; diff --git a/packages/engine/Source/Core/EllipsoidOutlineGeometry.js b/packages/engine/Source/Core/EllipsoidOutlineGeometry.js index 0fbd1edd2434..eeee97eed72e 100644 --- a/packages/engine/Source/Core/EllipsoidOutlineGeometry.js +++ b/packages/engine/Source/Core/EllipsoidOutlineGeometry.js @@ -47,17 +47,17 @@ const sin = Math.sin; * const geometry = Cesium.EllipsoidOutlineGeometry.createGeometry(ellipsoid); */ function EllipsoidOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - - const radii = defaultValue(options.radii, defaultRadii); - const innerRadii = defaultValue(options.innerRadii, radii); - const minimumClock = defaultValue(options.minimumClock, 0.0); - const maximumClock = defaultValue(options.maximumClock, CesiumMath.TWO_PI); - const minimumCone = defaultValue(options.minimumCone, 0.0); - const maximumCone = defaultValue(options.maximumCone, CesiumMath.PI); - const stackPartitions = Math.round(defaultValue(options.stackPartitions, 10)); - const slicePartitions = Math.round(defaultValue(options.slicePartitions, 8)); - const subdivisions = Math.round(defaultValue(options.subdivisions, 128)); + options = options ?? defaultValue.EMPTY_OBJECT; + + const radii = options.radii ?? defaultRadii; + const innerRadii = options.innerRadii ?? radii; + const minimumClock = options.minimumClock ?? 0.0; + const maximumClock = options.maximumClock ?? CesiumMath.TWO_PI; + const minimumCone = options.minimumCone ?? 0.0; + const maximumCone = options.maximumCone ?? CesiumMath.PI; + const stackPartitions = Math.round(options.stackPartitions ?? 10); + const slicePartitions = Math.round(options.slicePartitions ?? 8); + const subdivisions = Math.round(options.subdivisions ?? 128); //>>includeStart('debug', pragmas.debug); if (stackPartitions < 1) { @@ -119,7 +119,7 @@ EllipsoidOutlineGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value._radii, array, startingIndex); startingIndex += Cartesian3.packedLength; @@ -134,7 +134,7 @@ EllipsoidOutlineGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._stackPartitions; array[startingIndex++] = value._slicePartitions; array[startingIndex++] = value._subdivisions; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -169,7 +169,7 @@ EllipsoidOutlineGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const radii = Cartesian3.unpack(array, startingIndex, scratchRadii); startingIndex += Cartesian3.packedLength; diff --git a/packages/engine/Source/Core/EllipsoidRhumbLine.js b/packages/engine/Source/Core/EllipsoidRhumbLine.js index 834b8a857b74..7e422b2e6abc 100644 --- a/packages/engine/Source/Core/EllipsoidRhumbLine.js +++ b/packages/engine/Source/Core/EllipsoidRhumbLine.js @@ -1,7 +1,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -391,7 +390,7 @@ function interpolateUsingSurfaceDistance( * @exception {DeveloperError} angle between start and end must be at least 0.0125 radians. */ function EllipsoidRhumbLine(start, end, ellipsoid) { - const e = defaultValue(ellipsoid, Ellipsoid.default); + const e = ellipsoid ?? Ellipsoid.default; this._ellipsoid = e; this._start = new Cartographic(); this._end = new Cartographic(); @@ -500,7 +499,7 @@ EllipsoidRhumbLine.fromStartHeadingDistance = function ( Check.typeOf.number.greaterThan("distance", distance, 0.0); //>>includeEnd('debug'); - const e = defaultValue(ellipsoid, Ellipsoid.default); + const e = ellipsoid ?? Ellipsoid.default; const major = e.maximumRadius; const minor = e.minimumRadius; const majorSquared = major * major; diff --git a/packages/engine/Source/Core/EllipsoidTangentPlane.js b/packages/engine/Source/Core/EllipsoidTangentPlane.js index c7b73ca4888f..8133963d8383 100644 --- a/packages/engine/Source/Core/EllipsoidTangentPlane.js +++ b/packages/engine/Source/Core/EllipsoidTangentPlane.js @@ -3,7 +3,6 @@ import Cartesian2 from "./Cartesian2.js"; import Cartesian3 from "./Cartesian3.js"; import Cartesian4 from "./Cartesian4.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -31,7 +30,7 @@ function EllipsoidTangentPlane(origin, ellipsoid) { Check.defined("origin", origin); //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; origin = ellipsoid.scaleToGeodeticSurface(origin); //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Core/EllipsoidTerrainProvider.js b/packages/engine/Source/Core/EllipsoidTerrainProvider.js index ad08037ccf4b..70a57a0db377 100644 --- a/packages/engine/Source/Core/EllipsoidTerrainProvider.js +++ b/packages/engine/Source/Core/EllipsoidTerrainProvider.js @@ -24,12 +24,12 @@ import TerrainProvider from "./TerrainProvider.js"; * @see TerrainProvider */ function EllipsoidTerrainProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._tilingScheme = options.tilingScheme; if (!defined(this._tilingScheme)) { this._tilingScheme = new GeographicTilingScheme({ - ellipsoid: defaultValue(options.ellipsoid, Ellipsoid.default), + ellipsoid: options.ellipsoid ?? Ellipsoid.default, }); } diff --git a/packages/engine/Source/Core/EllipsoidalOccluder.js b/packages/engine/Source/Core/EllipsoidalOccluder.js index 6f8fee3143f9..e60f9ccbf70a 100644 --- a/packages/engine/Source/Core/EllipsoidalOccluder.js +++ b/packages/engine/Source/Core/EllipsoidalOccluder.js @@ -1,7 +1,6 @@ import BoundingSphere from "./BoundingSphere.js"; import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Ellipsoid from "./Ellipsoid.js"; import Rectangle from "./Rectangle.js"; @@ -418,8 +417,8 @@ function computeHorizonCullingPointFromVertices( result = new Cartesian3(); } - stride = defaultValue(stride, 3); - center = defaultValue(center, Cartesian3.ZERO); + stride = stride ?? 3; + center = center ?? Cartesian3.ZERO; const scaledSpaceDirectionToPoint = computeScaledSpaceDirectionToPoint( ellipsoid, directionToPoint, diff --git a/packages/engine/Source/Core/FeatureDetection.js b/packages/engine/Source/Core/FeatureDetection.js index 425b247ecb95..31fb350852cd 100644 --- a/packages/engine/Source/Core/FeatureDetection.js +++ b/packages/engine/Source/Core/FeatureDetection.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Fullscreen from "./Fullscreen.js"; @@ -314,7 +313,7 @@ const FeatureDetection = { firefoxVersion: firefoxVersion, isWindows: isWindows, isIPadOrIOS: isIPadOrIOS, - hardwareConcurrency: defaultValue(theNavigator.hardwareConcurrency, 3), + hardwareConcurrency: theNavigator.hardwareConcurrency ?? 3, supportsPointerEvents: supportsPointerEvents, supportsImageRenderingPixelated: supportsImageRenderingPixelated, supportsWebP: supportsWebP, diff --git a/packages/engine/Source/Core/FrustumGeometry.js b/packages/engine/Source/Core/FrustumGeometry.js index 7b005fef26b6..9c777ef1ea3a 100644 --- a/packages/engine/Source/Core/FrustumGeometry.js +++ b/packages/engine/Source/Core/FrustumGeometry.js @@ -3,7 +3,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartesian4 from "./Cartesian4.js"; import Check from "./Check.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Geometry from "./Geometry.js"; import GeometryAttribute from "./GeometryAttribute.js"; @@ -42,12 +41,12 @@ function FrustumGeometry(options) { const frustum = options.frustum; const orientation = options.orientation; const origin = options.origin; - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; // This is private because it is used by DebugCameraPrimitive to draw a multi-frustum by // creating multiple FrustumGeometry objects. This way the near plane of one frustum doesn't overlap // the far plane of another. - const drawNearPlane = defaultValue(options._drawNearPlane, true); + const drawNearPlane = options._drawNearPlane ?? true; let frustumType; let frustumPackedLength; @@ -94,7 +93,7 @@ FrustumGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const frustumType = value._frustumType; const frustum = value._frustum; @@ -138,7 +137,7 @@ FrustumGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const frustumType = array[startingIndex++]; @@ -277,9 +276,9 @@ FrustumGeometry._computeNearFarPlanes = function ( orientation, scratchRotationMatrix, ); - let x = defaultValue(xDirection, scratchXDirection); - let y = defaultValue(yDirection, scratchYDirection); - let z = defaultValue(zDirection, scratchZDirection); + let x = xDirection ?? scratchXDirection; + let y = yDirection ?? scratchYDirection; + let z = zDirection ?? scratchZDirection; x = Matrix3.getColumn(rotationMatrix, 0, x); y = Matrix3.getColumn(rotationMatrix, 1, y); diff --git a/packages/engine/Source/Core/FrustumOutlineGeometry.js b/packages/engine/Source/Core/FrustumOutlineGeometry.js index f77783980bd0..ffb512d8fdbb 100644 --- a/packages/engine/Source/Core/FrustumOutlineGeometry.js +++ b/packages/engine/Source/Core/FrustumOutlineGeometry.js @@ -2,7 +2,6 @@ import BoundingSphere from "./BoundingSphere.js"; import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import FrustumGeometry from "./FrustumGeometry.js"; import Geometry from "./Geometry.js"; @@ -42,7 +41,7 @@ function FrustumOutlineGeometry(options) { // This is private because it is used by DebugCameraPrimitive to draw a multi-frustum by // creating multiple FrustumOutlineGeometrys. This way the near plane of one frustum doesn't overlap // the far plane of another. - const drawNearPlane = defaultValue(options._drawNearPlane, true); + const drawNearPlane = options._drawNearPlane ?? true; let frustumType; let frustumPackedLength; @@ -84,7 +83,7 @@ FrustumOutlineGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const frustumType = value._frustumType; const frustum = value._frustum; @@ -125,7 +124,7 @@ FrustumOutlineGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const frustumType = array[startingIndex++]; diff --git a/packages/engine/Source/Core/GeographicProjection.js b/packages/engine/Source/Core/GeographicProjection.js index 1b209050a9d5..2246276c1b2d 100644 --- a/packages/engine/Source/Core/GeographicProjection.js +++ b/packages/engine/Source/Core/GeographicProjection.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -19,7 +18,7 @@ import Ellipsoid from "./Ellipsoid.js"; * @see WebMercatorProjection */ function GeographicProjection(ellipsoid) { - this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + this._ellipsoid = ellipsoid ?? Ellipsoid.default; this._semimajorAxis = this._ellipsoid.maximumRadius; this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis; } diff --git a/packages/engine/Source/Core/GeographicTilingScheme.js b/packages/engine/Source/Core/GeographicTilingScheme.js index f23d5d4c98ab..b215cb9da6b7 100644 --- a/packages/engine/Source/Core/GeographicTilingScheme.js +++ b/packages/engine/Source/Core/GeographicTilingScheme.js @@ -25,19 +25,13 @@ import Rectangle from "./Rectangle.js"; * the tile tree. */ function GeographicTilingScheme(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - this._rectangle = defaultValue(options.rectangle, Rectangle.MAX_VALUE); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.default; + this._rectangle = options.rectangle ?? Rectangle.MAX_VALUE; this._projection = new GeographicProjection(this._ellipsoid); - this._numberOfLevelZeroTilesX = defaultValue( - options.numberOfLevelZeroTilesX, - 2, - ); - this._numberOfLevelZeroTilesY = defaultValue( - options.numberOfLevelZeroTilesY, - 1, - ); + this._numberOfLevelZeroTilesX = options.numberOfLevelZeroTilesX ?? 2; + this._numberOfLevelZeroTilesY = options.numberOfLevelZeroTilesY ?? 1; } Object.defineProperties(GeographicTilingScheme.prototype, { diff --git a/packages/engine/Source/Core/Geometry.js b/packages/engine/Source/Core/Geometry.js index 6c134fd02d6d..372a54831c05 100644 --- a/packages/engine/Source/Core/Geometry.js +++ b/packages/engine/Source/Core/Geometry.js @@ -65,7 +65,7 @@ import Transforms from "./Transforms.js"; * }); */ function Geometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.attributes", options.attributes); @@ -135,10 +135,7 @@ function Geometry(options) { * * @default PrimitiveType.TRIANGLES */ - this.primitiveType = defaultValue( - options.primitiveType, - PrimitiveType.TRIANGLES, - ); + this.primitiveType = options.primitiveType ?? PrimitiveType.TRIANGLES; /** * An optional bounding sphere that fully encloses the geometry. This is @@ -153,7 +150,7 @@ function Geometry(options) { /** * @private */ - this.geometryType = defaultValue(options.geometryType, GeometryType.NONE); + this.geometryType = options.geometryType ?? GeometryType.NONE; /** * @private diff --git a/packages/engine/Source/Core/GeometryAttribute.js b/packages/engine/Source/Core/GeometryAttribute.js index 9f4d442c0a7a..b4d23040144c 100644 --- a/packages/engine/Source/Core/GeometryAttribute.js +++ b/packages/engine/Source/Core/GeometryAttribute.js @@ -38,7 +38,7 @@ import DeveloperError from "./DeveloperError.js"; * @see Geometry */ function GeometryAttribute(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.componentDatatype)) { @@ -110,7 +110,7 @@ function GeometryAttribute(options) { * Cesium.Color.floatToByte(color.alpha) * ]); */ - this.normalize = defaultValue(options.normalize, false); + this.normalize = options.normalize ?? false; /** * The values for the attributes stored in a typed array. In the code example, diff --git a/packages/engine/Source/Core/GeometryAttributes.js b/packages/engine/Source/Core/GeometryAttributes.js index 522d76dd2ed5..3c3275d27311 100644 --- a/packages/engine/Source/Core/GeometryAttributes.js +++ b/packages/engine/Source/Core/GeometryAttributes.js @@ -11,7 +11,7 @@ import defaultValue from "./defaultValue.js"; * @constructor */ function GeometryAttributes(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The 3D position attribute. diff --git a/packages/engine/Source/Core/GeometryInstance.js b/packages/engine/Source/Core/GeometryInstance.js index 18ad60900919..48888a221aff 100644 --- a/packages/engine/Source/Core/GeometryInstance.js +++ b/packages/engine/Source/Core/GeometryInstance.js @@ -49,7 +49,7 @@ import Matrix4 from "./Matrix4.js"; * @see Geometry */ function GeometryInstance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.geometry)) { @@ -75,9 +75,7 @@ function GeometryInstance(options) { * * @default Matrix4.IDENTITY */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); /** * User-defined object returned when the instance is picked or used to get/set per-instance attributes. @@ -106,7 +104,7 @@ function GeometryInstance(options) { * * @default {} */ - this.attributes = defaultValue(options.attributes, {}); + this.attributes = options.attributes ?? {}; /** * @private diff --git a/packages/engine/Source/Core/GeometryInstanceAttribute.js b/packages/engine/Source/Core/GeometryInstanceAttribute.js index d00730c92778..c94b4ce34ebb 100644 --- a/packages/engine/Source/Core/GeometryInstanceAttribute.js +++ b/packages/engine/Source/Core/GeometryInstanceAttribute.js @@ -40,7 +40,7 @@ import DeveloperError from "./DeveloperError.js"; * @see DistanceDisplayConditionGeometryInstanceAttribute */ function GeometryInstanceAttribute(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.componentDatatype)) { @@ -111,7 +111,7 @@ function GeometryInstanceAttribute(options) { * Cesium.Color.floatToByte(color.alpha) * ]; */ - this.normalize = defaultValue(options.normalize, false); + this.normalize = options.normalize ?? false; /** * The values for the attributes stored in a typed array. In the code example, diff --git a/packages/engine/Source/Core/GeometryPipeline.js b/packages/engine/Source/Core/GeometryPipeline.js index 7b7dd96b12d4..e9628655af93 100644 --- a/packages/engine/Source/Core/GeometryPipeline.js +++ b/packages/engine/Source/Core/GeometryPipeline.js @@ -6,7 +6,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartesian4 from "./Cartesian4.js"; import Cartographic from "./Cartographic.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import EncodedCartesian3 from "./EncodedCartesian3.js"; @@ -169,7 +168,7 @@ GeometryPipeline.createLineSegmentsForVectors = function ( attributeName, length, ) { - attributeName = defaultValue(attributeName, "normal"); + attributeName = attributeName ?? "normal"; //>>includeStart('debug', pragmas.debug); if (!defined(geometry)) { @@ -185,7 +184,7 @@ GeometryPipeline.createLineSegmentsForVectors = function ( } //>>includeEnd('debug'); - length = defaultValue(length, 10000.0); + length = length ?? 10000.0; const positions = geometry.attributes.position.values; const vectors = geometry.attributes[attributeName].values; diff --git a/packages/engine/Source/Core/GoogleEarthEnterpriseMetadata.js b/packages/engine/Source/Core/GoogleEarthEnterpriseMetadata.js index bc485be490aa..f4a30def0e71 100644 --- a/packages/engine/Source/Core/GoogleEarthEnterpriseMetadata.js +++ b/packages/engine/Source/Core/GoogleEarthEnterpriseMetadata.js @@ -2,7 +2,6 @@ import * as protobuf from "protobufjs/dist/minimal/protobuf.js"; import buildModuleUrl from "./buildModuleUrl.js"; import Check from "./Check.js"; import Credit from "./Credit.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import GoogleEarthEnterpriseTileInformation from "./GoogleEarthEnterpriseTileInformation.js"; import isBitSet from "./isBitSet.js"; @@ -304,8 +303,8 @@ GoogleEarthEnterpriseMetadata.prototype.getQuadTreePacket = function ( version, request, ) { - version = defaultValue(version, 1); - quadKey = defaultValue(quadKey, ""); + version = version ?? 1; + quadKey = quadKey ?? ""; const resource = getMetadataResource(this, quadKey, version, request); const promise = resource.fetchArrayBuffer(); @@ -549,34 +548,24 @@ function requestDbRoot(that) { const dbRoot = dbrootParser.DbRootProto.decode( new Uint8Array(result.buffer), ); - that.imageryPresent = defaultValue( - dbRoot.imageryPresent, - that.imageryPresent, - ); + that.imageryPresent = dbRoot.imageryPresent ?? that.imageryPresent; that.protoImagery = dbRoot.protoImagery; - that.terrainPresent = defaultValue( - dbRoot.terrainPresent, - that.terrainPresent, - ); + that.terrainPresent = dbRoot.terrainPresent ?? that.terrainPresent; if (defined(dbRoot.endSnippet) && defined(dbRoot.endSnippet.model)) { const model = dbRoot.endSnippet.model; - that.negativeAltitudeExponentBias = defaultValue( - model.negativeAltitudeExponentBias, - that.negativeAltitudeExponentBias, - ); - that.negativeAltitudeThreshold = defaultValue( - model.compressedNegativeAltitudeThreshold, - that.negativeAltitudeThreshold, - ); + that.negativeAltitudeExponentBias = + model.negativeAltitudeExponentBias ?? + that.negativeAltitudeExponentBias; + that.negativeAltitudeThreshold = + model.compressedNegativeAltitudeThreshold ?? + that.negativeAltitudeThreshold; } if (defined(dbRoot.databaseVersion)) { - that._quadPacketVersion = defaultValue( - dbRoot.databaseVersion.quadtreeVersion, - that._quadPacketVersion, - ); + that._quadPacketVersion = + dbRoot.databaseVersion.quadtreeVersion ?? that._quadPacketVersion; } const providers = that.providers; - const providerInfo = defaultValue(dbRoot.providerInfo, []); + const providerInfo = dbRoot.providerInfo ?? []; const count = providerInfo.length; for (let i = 0; i < count; ++i) { const provider = providerInfo[i]; diff --git a/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainData.js b/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainData.js index e3c4b68bf208..7d15f2f0fb7a 100644 --- a/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainData.js +++ b/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainData.js @@ -55,7 +55,7 @@ import TerrainMesh from "./TerrainMesh.js"; * @see QuantizedMeshTerrainData */ function GoogleEarthEnterpriseTerrainData(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.buffer", options.buffer); Check.typeOf.number( @@ -76,14 +76,14 @@ function GoogleEarthEnterpriseTerrainData(options) { // Convert from google layout to layout of other providers // 3 2 -> 2 3 // 0 1 -> 0 1 - const googleChildTileMask = defaultValue(options.childTileMask, 15); + const googleChildTileMask = options.childTileMask ?? 15; let childTileMask = googleChildTileMask & 3; // Bottom row is identical childTileMask |= googleChildTileMask & 4 ? 8 : 0; // NE childTileMask |= googleChildTileMask & 8 ? 4 : 0; // NW this._childTileMask = childTileMask; - this._createdByUpsampling = defaultValue(options.createdByUpsampling, false); + this._createdByUpsampling = options.createdByUpsampling ?? false; this._skirtHeight = undefined; this._bufferType = this._buffer.constructor; @@ -145,7 +145,7 @@ const rectangleScratch = new Rectangle(); * be retried later. */ GoogleEarthEnterpriseTerrainData.prototype.createMesh = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.tilingScheme", options.tilingScheme); @@ -158,12 +158,9 @@ GoogleEarthEnterpriseTerrainData.prototype.createMesh = function (options) { const x = options.x; const y = options.y; const level = options.level; - const exaggeration = defaultValue(options.exaggeration, 1.0); - const exaggerationRelativeHeight = defaultValue( - options.exaggerationRelativeHeight, - 0.0, - ); - const throttle = defaultValue(options.throttle, true); + const exaggeration = options.exaggeration ?? 1.0; + const exaggerationRelativeHeight = options.exaggerationRelativeHeight ?? 0.0; + const throttle = options.throttle ?? true; const ellipsoid = tilingScheme.ellipsoid; tilingScheme.tileXYToNativeRectangle(x, y, level, nativeRectangleScratch); diff --git a/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainProvider.js b/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainProvider.js index d13e05ac1d71..b2e61a94d813 100644 --- a/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +++ b/packages/engine/Source/Core/GoogleEarthEnterpriseTerrainProvider.js @@ -97,7 +97,7 @@ TerrainCache.prototype.tidy = function () { * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} */ function GoogleEarthEnterpriseTerrainProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._tilingScheme = new GeographicTilingScheme({ numberOfLevelZeroTilesX: 2, diff --git a/packages/engine/Source/Core/GregorianDate.js b/packages/engine/Source/Core/GregorianDate.js index c5291ca31ab1..d853e17897e7 100644 --- a/packages/engine/Source/Core/GregorianDate.js +++ b/packages/engine/Source/Core/GregorianDate.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import DeveloperError from "./DeveloperError.js"; import isLeapYear from "./isLeapYear.js"; @@ -40,14 +39,14 @@ function GregorianDate( const minimumSecond = 0; const minimumMillisecond = 0; - year = defaultValue(year, minimumYear); - month = defaultValue(month, minimumMonth); - day = defaultValue(day, minimumDay); - hour = defaultValue(hour, minimumHour); - minute = defaultValue(minute, minimumMinute); - second = defaultValue(second, minimumSecond); - millisecond = defaultValue(millisecond, minimumMillisecond); - isLeapSecond = defaultValue(isLeapSecond, false); + year = year ?? minimumYear; + month = month ?? minimumMonth; + day = day ?? minimumDay; + hour = hour ?? minimumHour; + minute = minute ?? minimumMinute; + second = second ?? minimumSecond; + millisecond = millisecond ?? minimumMillisecond; + isLeapSecond = isLeapSecond ?? false; //>>includeStart('debug', pragmas.debug); validateRange(); validateDate(); diff --git a/packages/engine/Source/Core/GroundPolylineGeometry.js b/packages/engine/Source/Core/GroundPolylineGeometry.js index 56f207eb9c6f..8ee553c5f82b 100644 --- a/packages/engine/Source/Core/GroundPolylineGeometry.js +++ b/packages/engine/Source/Core/GroundPolylineGeometry.js @@ -72,7 +72,7 @@ const WALL_INITIAL_MAX_HEIGHT = 1000.0; * }); */ function GroundPolylineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; //>>includeStart('debug', pragmas.debug); @@ -94,7 +94,7 @@ function GroundPolylineGeometry(options) { * The screen space width in pixels. * @type {number} */ - this.width = defaultValue(options.width, 1.0); // Doesn't get packed, not necessary for computing geometry. + this.width = options.width ?? 1.0; // Doesn't get packed, not necessary for computing geometry. this._positions = positions; @@ -104,7 +104,7 @@ function GroundPolylineGeometry(options) { * @type {boolean} * @default 9999.0 */ - this.granularity = defaultValue(options.granularity, 9999.0); + this.granularity = options.granularity ?? 9999.0; /** * Whether during geometry creation a line segment will be added between the last and first line positions to make this Polyline a loop. @@ -112,14 +112,14 @@ function GroundPolylineGeometry(options) { * @type {boolean} * @default false */ - this.loop = defaultValue(options.loop, false); + this.loop = options.loop ?? false; /** * The type of path the polyline must follow. Valid options are {@link ArcType.GEODESIC} and {@link ArcType.RHUMB}. * @type {ArcType} * @default ArcType.GEODESIC */ - this.arcType = defaultValue(options.arcType, ArcType.GEODESIC); + this.arcType = options.arcType ?? ArcType.GEODESIC; this._ellipsoid = Ellipsoid.default; @@ -297,7 +297,7 @@ GroundPolylineGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - let index = defaultValue(startingIndex, 0); + let index = startingIndex ?? 0; const positions = value._positions; const positionsLength = positions.length; @@ -335,7 +335,7 @@ GroundPolylineGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - let index = defaultValue(startingIndex, 0); + let index = startingIndex ?? 0; const positionsLength = array[index++]; const positions = new Array(positionsLength); diff --git a/packages/engine/Source/Core/HeadingPitchRange.js b/packages/engine/Source/Core/HeadingPitchRange.js index 6d9ae0e71ee7..6dc891de079f 100644 --- a/packages/engine/Source/Core/HeadingPitchRange.js +++ b/packages/engine/Source/Core/HeadingPitchRange.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; /** @@ -19,7 +18,7 @@ function HeadingPitchRange(heading, pitch, range) { * @type {number} * @default 0.0 */ - this.heading = defaultValue(heading, 0.0); + this.heading = heading ?? 0.0; /** * Pitch is the rotation from the local xy-plane. Positive pitch angles @@ -27,14 +26,14 @@ function HeadingPitchRange(heading, pitch, range) { * @type {number} * @default 0.0 */ - this.pitch = defaultValue(pitch, 0.0); + this.pitch = pitch ?? 0.0; /** * Range is the distance from the center of the local frame. * @type {number} * @default 0.0 */ - this.range = defaultValue(range, 0.0); + this.range = range ?? 0.0; } /** diff --git a/packages/engine/Source/Core/HeadingPitchRoll.js b/packages/engine/Source/Core/HeadingPitchRoll.js index 2fe724cc998b..39192d66c194 100644 --- a/packages/engine/Source/Core/HeadingPitchRoll.js +++ b/packages/engine/Source/Core/HeadingPitchRoll.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import CesiumMath from "./Math.js"; @@ -20,19 +19,19 @@ function HeadingPitchRoll(heading, pitch, roll) { * @type {number} * @default 0.0 */ - this.heading = defaultValue(heading, 0.0); + this.heading = heading ?? 0.0; /** * Gets or sets the pitch. * @type {number} * @default 0.0 */ - this.pitch = defaultValue(pitch, 0.0); + this.pitch = pitch ?? 0.0; /** * Gets or sets the roll. * @type {number} * @default 0.0 */ - this.roll = defaultValue(roll, 0.0); + this.roll = roll ?? 0.0; } /** diff --git a/packages/engine/Source/Core/Heap.js b/packages/engine/Source/Core/Heap.js index 700475cedc55..2d4cd2496432 100644 --- a/packages/engine/Source/Core/Heap.js +++ b/packages/engine/Source/Core/Heap.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; /** @@ -108,7 +107,7 @@ function swap(array, a, b) { * @param {number} [length] The length to resize internal array to. Defaults to the current length of the heap. */ Heap.prototype.reserve = function (length) { - length = defaultValue(length, this._length); + length = length ?? this._length; this._array.length = length; }; @@ -118,7 +117,7 @@ Heap.prototype.reserve = function (length) { * @param {number} [index=0] The starting index to heapify from. */ Heap.prototype.heapify = function (index) { - index = defaultValue(index, 0); + index = index ?? 0; const length = this._length; const comparator = this._comparator; const array = this._array; @@ -208,7 +207,7 @@ Heap.prototype.insert = function (element) { * @returns {*} The specified element of the heap. */ Heap.prototype.pop = function (index) { - index = defaultValue(index, 0); + index = index ?? 0; if (this._length === 0) { return undefined; } diff --git a/packages/engine/Source/Core/HeightmapTerrainData.js b/packages/engine/Source/Core/HeightmapTerrainData.js index 1b8b47d3be61..5fce569f0485 100644 --- a/packages/engine/Source/Core/HeightmapTerrainData.js +++ b/packages/engine/Source/Core/HeightmapTerrainData.js @@ -109,39 +109,29 @@ function HeightmapTerrainData(options) { this._buffer = options.buffer; this._width = options.width; this._height = options.height; - this._childTileMask = defaultValue(options.childTileMask, 15); - this._encoding = defaultValue(options.encoding, HeightmapEncoding.NONE); + this._childTileMask = options.childTileMask ?? 15; + this._encoding = options.encoding ?? HeightmapEncoding.NONE; const defaultStructure = HeightmapTessellator.DEFAULT_STRUCTURE; let structure = options.structure; if (!defined(structure)) { structure = defaultStructure; } else if (structure !== defaultStructure) { - structure.heightScale = defaultValue( - structure.heightScale, - defaultStructure.heightScale, - ); - structure.heightOffset = defaultValue( - structure.heightOffset, - defaultStructure.heightOffset, - ); - structure.elementsPerHeight = defaultValue( - structure.elementsPerHeight, - defaultStructure.elementsPerHeight, - ); - structure.stride = defaultValue(structure.stride, defaultStructure.stride); - structure.elementMultiplier = defaultValue( - structure.elementMultiplier, - defaultStructure.elementMultiplier, - ); - structure.isBigEndian = defaultValue( - structure.isBigEndian, - defaultStructure.isBigEndian, - ); + structure.heightScale = + structure.heightScale ?? defaultStructure.heightScale; + structure.heightOffset = + structure.heightOffset ?? defaultStructure.heightOffset; + structure.elementsPerHeight = + structure.elementsPerHeight ?? defaultStructure.elementsPerHeight; + structure.stride = structure.stride ?? defaultStructure.stride; + structure.elementMultiplier = + structure.elementMultiplier ?? defaultStructure.elementMultiplier; + structure.isBigEndian = + structure.isBigEndian ?? defaultStructure.isBigEndian; } this._structure = structure; - this._createdByUpsampling = defaultValue(options.createdByUpsampling, false); + this._createdByUpsampling = options.createdByUpsampling ?? false; this._waterMask = options.waterMask; this._skirtHeight = undefined; @@ -208,7 +198,7 @@ const createMeshTaskProcessorThrottle = new TaskProcessor( * be retried later. */ HeightmapTerrainData.prototype.createMesh = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.tilingScheme", options.tilingScheme); @@ -221,12 +211,9 @@ HeightmapTerrainData.prototype.createMesh = function (options) { const x = options.x; const y = options.y; const level = options.level; - const exaggeration = defaultValue(options.exaggeration, 1.0); - const exaggerationRelativeHeight = defaultValue( - options.exaggerationRelativeHeight, - 0.0, - ); - const throttle = defaultValue(options.throttle, true); + const exaggeration = options.exaggeration ?? 1.0; + const exaggerationRelativeHeight = options.exaggerationRelativeHeight ?? 0.0; + const throttle = options.throttle ?? true; const ellipsoid = tilingScheme.ellipsoid; const nativeRectangle = tilingScheme.tileXYToNativeRectangle(x, y, level); @@ -340,11 +327,8 @@ HeightmapTerrainData.prototype._createMeshSync = function (options) { const x = options.x; const y = options.y; const level = options.level; - const exaggeration = defaultValue(options.exaggeration, 1.0); - const exaggerationRelativeHeight = defaultValue( - options.exaggerationRelativeHeight, - 0.0, - ); + const exaggeration = options.exaggeration ?? 1.0; + const exaggerationRelativeHeight = options.exaggerationRelativeHeight ?? 0.0; const ellipsoid = tilingScheme.ellipsoid; const nativeRectangle = tilingScheme.tileXYToNativeRectangle(x, y, level); diff --git a/packages/engine/Source/Core/HeightmapTessellator.js b/packages/engine/Source/Core/HeightmapTessellator.js index b49e1a695e05..91b48d6aeeca 100644 --- a/packages/engine/Source/Core/HeightmapTessellator.js +++ b/packages/engine/Source/Core/HeightmapTessellator.js @@ -2,7 +2,6 @@ import AxisAlignedBoundingBox from "./AxisAlignedBoundingBox.js"; import BoundingSphere from "./BoundingSphere.js"; import Cartesian2 from "./Cartesian2.js"; import Cartesian3 from "./Cartesian3.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -148,8 +147,8 @@ HeightmapTessellator.computeVertices = function (options) { const skirtHeight = options.skirtHeight; const hasSkirts = skirtHeight > 0.0; - const isGeographic = defaultValue(options.isGeographic, true); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + const isGeographic = options.isGeographic ?? true; + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; const oneOverGlobeSemimajorAxis = 1.0 / ellipsoid.maximumRadius; @@ -187,44 +186,29 @@ HeightmapTessellator.computeVertices = function (options) { let relativeToCenter = options.relativeToCenter; const hasRelativeToCenter = defined(relativeToCenter); relativeToCenter = hasRelativeToCenter ? relativeToCenter : Cartesian3.ZERO; - const includeWebMercatorT = defaultValue(options.includeWebMercatorT, false); + const includeWebMercatorT = options.includeWebMercatorT ?? false; - const exaggeration = defaultValue(options.exaggeration, 1.0); - const exaggerationRelativeHeight = defaultValue( - options.exaggerationRelativeHeight, - 0.0, - ); + const exaggeration = options.exaggeration ?? 1.0; + const exaggerationRelativeHeight = options.exaggerationRelativeHeight ?? 0.0; const hasExaggeration = exaggeration !== 1.0; const includeGeodeticSurfaceNormals = hasExaggeration; - const structure = defaultValue( - options.structure, - HeightmapTessellator.DEFAULT_STRUCTURE, - ); - const heightScale = defaultValue( - structure.heightScale, - HeightmapTessellator.DEFAULT_STRUCTURE.heightScale, - ); - const heightOffset = defaultValue( - structure.heightOffset, - HeightmapTessellator.DEFAULT_STRUCTURE.heightOffset, - ); - const elementsPerHeight = defaultValue( - structure.elementsPerHeight, - HeightmapTessellator.DEFAULT_STRUCTURE.elementsPerHeight, - ); - const stride = defaultValue( - structure.stride, - HeightmapTessellator.DEFAULT_STRUCTURE.stride, - ); - const elementMultiplier = defaultValue( - structure.elementMultiplier, - HeightmapTessellator.DEFAULT_STRUCTURE.elementMultiplier, - ); - const isBigEndian = defaultValue( - structure.isBigEndian, - HeightmapTessellator.DEFAULT_STRUCTURE.isBigEndian, - ); + const structure = options.structure ?? HeightmapTessellator.DEFAULT_STRUCTURE; + const heightScale = + structure.heightScale ?? HeightmapTessellator.DEFAULT_STRUCTURE.heightScale; + const heightOffset = + structure.heightOffset ?? + HeightmapTessellator.DEFAULT_STRUCTURE.heightOffset; + const elementsPerHeight = + structure.elementsPerHeight ?? + HeightmapTessellator.DEFAULT_STRUCTURE.elementsPerHeight; + const stride = + structure.stride ?? HeightmapTessellator.DEFAULT_STRUCTURE.stride; + const elementMultiplier = + structure.elementMultiplier ?? + HeightmapTessellator.DEFAULT_STRUCTURE.elementMultiplier; + const isBigEndian = + structure.isBigEndian ?? HeightmapTessellator.DEFAULT_STRUCTURE.isBigEndian; let rectangleWidth = Rectangle.computeWidth(nativeRectangle); let rectangleHeight = Rectangle.computeHeight(nativeRectangle); diff --git a/packages/engine/Source/Core/HermitePolynomialApproximation.js b/packages/engine/Source/Core/HermitePolynomialApproximation.js index e8cab0d6fa28..3bcec6b518ce 100644 --- a/packages/engine/Source/Core/HermitePolynomialApproximation.js +++ b/packages/engine/Source/Core/HermitePolynomialApproximation.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import CesiumMath from "./Math.js"; @@ -83,7 +82,7 @@ HermitePolynomialApproximation.getRequiredDataPoints = function ( degree, inputOrder, ) { - inputOrder = defaultValue(inputOrder, 0); + inputOrder = inputOrder ?? 0; //>>includeStart('debug', pragmas.debug); if (!defined(degree)) { diff --git a/packages/engine/Source/Core/HermiteSpline.js b/packages/engine/Source/Core/HermiteSpline.js index bad84e49c200..0d5fccb6ecee 100644 --- a/packages/engine/Source/Core/HermiteSpline.js +++ b/packages/engine/Source/Core/HermiteSpline.js @@ -167,7 +167,7 @@ function generateNatural(points) { * @see MorphWeightSpline */ function HermiteSpline(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const points = options.points; const times = options.times; @@ -320,7 +320,7 @@ Object.defineProperties(HermiteSpline.prototype, { * }); */ HermiteSpline.createC1 = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const times = options.times; const points = options.points; @@ -380,7 +380,7 @@ HermiteSpline.createC1 = function (options) { * }); */ HermiteSpline.createNaturalCubic = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const times = options.times; const points = options.points; @@ -450,7 +450,7 @@ HermiteSpline.createNaturalCubic = function (options) { * }); */ HermiteSpline.createClampedCubic = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const times = options.times; const points = options.points; diff --git a/packages/engine/Source/Core/Iau2006XysData.js b/packages/engine/Source/Core/Iau2006XysData.js index 86849d1756d6..e61ad19ab9a3 100644 --- a/packages/engine/Source/Core/Iau2006XysData.js +++ b/packages/engine/Source/Core/Iau2006XysData.js @@ -26,24 +26,22 @@ import TimeStandard from "./TimeStandard.js"; * @private */ function Iau2006XysData(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._xysFileUrlTemplate = Resource.createIfNeeded( options.xysFileUrlTemplate, ); - this._interpolationOrder = defaultValue(options.interpolationOrder, 9); - this._sampleZeroJulianEphemerisDate = defaultValue( - options.sampleZeroJulianEphemerisDate, - 2442396.5, - ); + this._interpolationOrder = options.interpolationOrder ?? 9; + this._sampleZeroJulianEphemerisDate = + options.sampleZeroJulianEphemerisDate ?? 2442396.5; this._sampleZeroDateTT = new JulianDate( this._sampleZeroJulianEphemerisDate, 0.0, TimeStandard.TAI, ); - this._stepSizeDays = defaultValue(options.stepSizeDays, 1.0); - this._samplesPerXysFile = defaultValue(options.samplesPerXysFile, 1000); - this._totalSamples = defaultValue(options.totalSamples, 27426); + this._stepSizeDays = options.stepSizeDays ?? 1.0; + this._samplesPerXysFile = options.samplesPerXysFile ?? 1000; + this._totalSamples = options.totalSamples ?? 27426; this._samples = new Array(this._totalSamples * 3); this._chunkDownloadsInProgress = []; diff --git a/packages/engine/Source/Core/IntersectionTests.js b/packages/engine/Source/Core/IntersectionTests.js index 4ba53f228c12..99d3a2ed3321 100644 --- a/packages/engine/Source/Core/IntersectionTests.js +++ b/packages/engine/Source/Core/IntersectionTests.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Interval from "./Interval.js"; @@ -103,7 +102,7 @@ IntersectionTests.rayTriangleParametric = function ( } //>>includeEnd('debug'); - cullBackFaces = defaultValue(cullBackFaces, false); + cullBackFaces = cullBackFaces ?? false; const origin = ray.origin; const direction = ray.direction; diff --git a/packages/engine/Source/Core/Interval.js b/packages/engine/Source/Core/Interval.js index 4f8f99c8b962..cc6cda92844b 100644 --- a/packages/engine/Source/Core/Interval.js +++ b/packages/engine/Source/Core/Interval.js @@ -1,5 +1,3 @@ -import defaultValue from "./defaultValue.js"; - /** * Represents the closed interval [start, stop]. * @alias Interval @@ -14,12 +12,12 @@ function Interval(start, stop) { * @type {number} * @default 0.0 */ - this.start = defaultValue(start, 0.0); + this.start = start ?? 0.0; /** * The end of the interval. * @type {number} * @default 0.0 */ - this.stop = defaultValue(stop, 0.0); + this.stop = stop ?? 0.0; } export default Interval; diff --git a/packages/engine/Source/Core/IonGeocoderService.js b/packages/engine/Source/Core/IonGeocoderService.js index 81da96b7dbba..76e62d8b1a0c 100644 --- a/packages/engine/Source/Core/IonGeocoderService.js +++ b/packages/engine/Source/Core/IonGeocoderService.js @@ -19,16 +19,14 @@ import Resource from "./Resource.js"; * @see Ion */ function IonGeocoderService(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.scene", options.scene); //>>includeEnd('debug'); - const accessToken = defaultValue(options.accessToken, Ion.defaultAccessToken); - const server = Resource.createIfNeeded( - defaultValue(options.server, Ion.defaultServer), - ); + const accessToken = options.accessToken ?? Ion.defaultAccessToken; + const server = Resource.createIfNeeded(options.server ?? Ion.defaultServer); server.appendForwardSlash(); const defaultTokenCredit = Ion.getDefaultTokenCredit(accessToken); diff --git a/packages/engine/Source/Core/IonResource.js b/packages/engine/Source/Core/IonResource.js index c9cc74bca53e..9dd1f272e962 100644 --- a/packages/engine/Source/Core/IonResource.js +++ b/packages/engine/Source/Core/IonResource.js @@ -159,7 +159,7 @@ IonResource.getCreditsFromEndpoint = function (endpoint, endpointResource) { /** @inheritdoc */ IonResource.prototype.clone = function (result) { // We always want to use the root's information because it's the most up-to-date - const ionRoot = defaultValue(this._ionRoot, this); + const ionRoot = this._ionRoot ?? this; if (!defined(result)) { result = new IonResource( @@ -220,9 +220,9 @@ IonResource._createEndpointResource = function (assetId, options) { Check.defined("assetId", assetId); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - let server = defaultValue(options.server, Ion.defaultServer); - const accessToken = defaultValue(options.accessToken, Ion.defaultAccessToken); + options = options ?? defaultValue.EMPTY_OBJECT; + let server = options.server ?? Ion.defaultServer; + const accessToken = options.accessToken ?? Ion.defaultAccessToken; server = Resource.createIfNeeded(server); const resourceOptions = { @@ -237,7 +237,7 @@ IonResource._createEndpointResource = function (assetId, options) { }; function retryCallback(that, error) { - const ionRoot = defaultValue(that._ionRoot, that); + const ionRoot = that._ionRoot ?? that; const endpointResource = ionRoot._ionEndpointResource; // Image is not available in worker threads, so this avoids diff --git a/packages/engine/Source/Core/JulianDate.js b/packages/engine/Source/Core/JulianDate.js index 092e4683e5a8..eaf22d5e7842 100644 --- a/packages/engine/Source/Core/JulianDate.js +++ b/packages/engine/Source/Core/JulianDate.js @@ -1,5 +1,4 @@ import binarySearch from "./binarySearch.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import GregorianDate from "./GregorianDate.js"; @@ -216,9 +215,9 @@ function JulianDate(julianDayNumber, secondsOfDay, timeStandard) { */ this.secondsOfDay = undefined; - julianDayNumber = defaultValue(julianDayNumber, 0.0); - secondsOfDay = defaultValue(secondsOfDay, 0.0); - timeStandard = defaultValue(timeStandard, TimeStandard.UTC); + julianDayNumber = julianDayNumber ?? 0.0; + secondsOfDay = secondsOfDay ?? 0.0; + timeStandard = timeStandard ?? TimeStandard.UTC; //If julianDayNumber is fractional, make it an integer and add the number of seconds the fraction represented. const wholeDays = julianDayNumber | 0; @@ -896,7 +895,7 @@ JulianDate.equals = function (left, right) { * @returns {boolean} true if the two dates are within epsilon seconds of each other; otherwise false. */ JulianDate.equalsEpsilon = function (left, right, epsilon) { - epsilon = defaultValue(epsilon, 0); + epsilon = epsilon ?? 0; return ( left === right || diff --git a/packages/engine/Source/Core/LinearSpline.js b/packages/engine/Source/Core/LinearSpline.js index 3c025670b704..2aeac111530a 100644 --- a/packages/engine/Source/Core/LinearSpline.js +++ b/packages/engine/Source/Core/LinearSpline.js @@ -42,7 +42,7 @@ import Spline from "./Spline.js"; * @see MorphWeightSpline */ function LinearSpline(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const points = options.points; const times = options.times; diff --git a/packages/engine/Source/Core/ManagedArray.js b/packages/engine/Source/Core/ManagedArray.js index 9eeb280e5ffd..70b8da3b488e 100644 --- a/packages/engine/Source/Core/ManagedArray.js +++ b/packages/engine/Source/Core/ManagedArray.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; /** * A wrapper around arrays so that the internal length of the array can be manually managed. @@ -11,7 +10,7 @@ import defaultValue from "./defaultValue.js"; * @param {number} [length=0] The initial length of the array. */ function ManagedArray(length) { - length = defaultValue(length, 0); + length = length ?? 0; this._array = new Array(length); this._length = length; } @@ -157,7 +156,7 @@ ManagedArray.prototype.resize = function (length) { * @param {number} [length] The length. */ ManagedArray.prototype.trim = function (length) { - length = defaultValue(length, this._length); + length = length ?? this._length; this._array.length = length; }; export default ManagedArray; diff --git a/packages/engine/Source/Core/Math.js b/packages/engine/Source/Core/Math.js index 91579c5f6a8f..2ea709c7d076 100644 --- a/packages/engine/Source/Core/Math.js +++ b/packages/engine/Source/Core/Math.js @@ -1,6 +1,5 @@ import MersenneTwister from "mersenne-twister"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -205,14 +204,16 @@ CesiumMath.FOUR_GIGABYTES = 4 * 1024 * 1024 * 1024; * @param {number} value The value to return the sign of. * @returns {number} The sign of value. */ -CesiumMath.sign = defaultValue(Math.sign, function sign(value) { - value = +value; // coerce to number - if (value === 0 || value !== value) { - // zero or NaN - return value; - } - return value > 0 ? 1 : -1; -}); +CesiumMath.sign = + Math.sign ?? + function sign(value) { + value = +value; // coerce to number + if (value === 0 || value !== value) { + // zero or NaN + return value; + } + return value > 0 ? 1 : -1; + }; /** * Returns 1.0 if the given value is positive or zero, and -1.0 if it is negative. @@ -234,7 +235,7 @@ CesiumMath.signNotZero = function (value) { * @see CesiumMath.fromSNorm */ CesiumMath.toSNorm = function (value, rangeMaximum) { - rangeMaximum = defaultValue(rangeMaximum, 255); + rangeMaximum = rangeMaximum ?? 255; return Math.round( (CesiumMath.clamp(value, -1.0, 1.0) * 0.5 + 0.5) * rangeMaximum, ); @@ -249,7 +250,7 @@ CesiumMath.toSNorm = function (value, rangeMaximum) { * @see CesiumMath.toSNorm */ CesiumMath.fromSNorm = function (value, rangeMaximum) { - rangeMaximum = defaultValue(rangeMaximum, 255); + rangeMaximum = rangeMaximum ?? 255; return ( (CesiumMath.clamp(value, 0.0, rangeMaximum) / rangeMaximum) * 2.0 - 1.0 ); @@ -291,9 +292,11 @@ CesiumMath.normalize = function (value, rangeMinimum, rangeMaximum) { * @param {number} value The number whose hyperbolic sine is to be returned. * @returns {number} The hyperbolic sine of value. */ -CesiumMath.sinh = defaultValue(Math.sinh, function sinh(value) { - return (Math.exp(value) - Math.exp(-value)) / 2.0; -}); +CesiumMath.sinh = + Math.sinh ?? + function sinh(value) { + return (Math.exp(value) - Math.exp(-value)) / 2.0; + }; /** * Returns the hyperbolic cosine of a number. @@ -315,9 +318,11 @@ CesiumMath.sinh = defaultValue(Math.sinh, function sinh(value) { * @param {number} value The number whose hyperbolic cosine is to be returned. * @returns {number} The hyperbolic cosine of value. */ -CesiumMath.cosh = defaultValue(Math.cosh, function cosh(value) { - return (Math.exp(value) + Math.exp(-value)) / 2.0; -}); +CesiumMath.cosh = + Math.cosh ?? + function cosh(value) { + return (Math.exp(value) + Math.exp(-value)) / 2.0; + }; /** * Computes the linear interpolation of two values. @@ -621,8 +626,8 @@ CesiumMath.equalsEpsilon = function ( } //>>includeEnd('debug'); - relativeEpsilon = defaultValue(relativeEpsilon, 0.0); - absoluteEpsilon = defaultValue(absoluteEpsilon, relativeEpsilon); + relativeEpsilon = relativeEpsilon ?? 0.0; + absoluteEpsilon = absoluteEpsilon ?? relativeEpsilon; const absDiff = Math.abs(left - right); return ( absDiff <= absoluteEpsilon || @@ -785,7 +790,7 @@ CesiumMath.factorial = function (n) { * const m = Cesium.Math.incrementWrap(10, 10, 0); // returns 0 */ CesiumMath.incrementWrap = function (n, maximumValue, minimumValue) { - minimumValue = defaultValue(minimumValue, 0.0); + minimumValue = minimumValue ?? 0.0; //>>includeStart('debug', pragmas.debug); if (!defined(n)) { @@ -1031,10 +1036,12 @@ CesiumMath.logBase = function (number, base) { * @param {number} [number] The number. * @returns {number} The result. */ -CesiumMath.cbrt = defaultValue(Math.cbrt, function cbrt(number) { - const result = Math.pow(Math.abs(number), 1.0 / 3.0); - return number < 0.0 ? -result : result; -}); +CesiumMath.cbrt = + Math.cbrt ?? + function cbrt(number) { + const result = Math.pow(Math.abs(number), 1.0 / 3.0); + return number < 0.0 ? -result : result; + }; /** * Finds the base 2 logarithm of a number. @@ -1043,9 +1050,11 @@ CesiumMath.cbrt = defaultValue(Math.cbrt, function cbrt(number) { * @param {number} number The number. * @returns {number} The result. */ -CesiumMath.log2 = defaultValue(Math.log2, function log2(number) { - return Math.log(number) * Math.LOG2E; -}); +CesiumMath.log2 = + Math.log2 ?? + function log2(number) { + return Math.log(number) * Math.LOG2E; + }; /** * Calculate the fog impact at a given distance. Useful for culling. diff --git a/packages/engine/Source/Core/Matrix2.js b/packages/engine/Source/Core/Matrix2.js index 479489d6cd93..814ce010101c 100644 --- a/packages/engine/Source/Core/Matrix2.js +++ b/packages/engine/Source/Core/Matrix2.js @@ -1,6 +1,5 @@ import Cartesian2 from "./Cartesian2.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -26,10 +25,10 @@ import DeveloperError from "./DeveloperError.js"; * @see Matrix4 */ function Matrix2(column0Row0, column1Row0, column0Row1, column1Row1) { - this[0] = defaultValue(column0Row0, 0.0); - this[1] = defaultValue(column0Row1, 0.0); - this[2] = defaultValue(column1Row0, 0.0); - this[3] = defaultValue(column1Row1, 0.0); + this[0] = column0Row0 ?? 0.0; + this[1] = column0Row1 ?? 0.0; + this[2] = column1Row0 ?? 0.0; + this[3] = column1Row1 ?? 0.0; } /** @@ -53,7 +52,7 @@ Matrix2.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value[0]; array[startingIndex++] = value[1]; @@ -76,7 +75,7 @@ Matrix2.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Matrix2(); @@ -957,7 +956,7 @@ Matrix2.equalsArray = function (matrix, array, offset) { * @returns {boolean} true if left and right are within the provided epsilon, false otherwise. */ Matrix2.equalsEpsilon = function (left, right, epsilon) { - epsilon = defaultValue(epsilon, 0); + epsilon = epsilon ?? 0; return ( left === right || (defined(left) && diff --git a/packages/engine/Source/Core/Matrix3.js b/packages/engine/Source/Core/Matrix3.js index 9174f3c37096..7a7ab6c3213e 100644 --- a/packages/engine/Source/Core/Matrix3.js +++ b/packages/engine/Source/Core/Matrix3.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import CesiumMath from "./Math.js"; @@ -47,15 +46,15 @@ function Matrix3( column1Row2, column2Row2, ) { - this[0] = defaultValue(column0Row0, 0.0); - this[1] = defaultValue(column0Row1, 0.0); - this[2] = defaultValue(column0Row2, 0.0); - this[3] = defaultValue(column1Row0, 0.0); - this[4] = defaultValue(column1Row1, 0.0); - this[5] = defaultValue(column1Row2, 0.0); - this[6] = defaultValue(column2Row0, 0.0); - this[7] = defaultValue(column2Row1, 0.0); - this[8] = defaultValue(column2Row2, 0.0); + this[0] = column0Row0 ?? 0.0; + this[1] = column0Row1 ?? 0.0; + this[2] = column0Row2 ?? 0.0; + this[3] = column1Row0 ?? 0.0; + this[4] = column1Row1 ?? 0.0; + this[5] = column1Row2 ?? 0.0; + this[6] = column2Row0 ?? 0.0; + this[7] = column2Row1 ?? 0.0; + this[8] = column2Row2 ?? 0.0; } /** @@ -79,7 +78,7 @@ Matrix3.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value[0]; array[startingIndex++] = value[1]; @@ -107,7 +106,7 @@ Matrix3.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Matrix3(); @@ -1648,7 +1647,7 @@ Matrix3.equals = function (left, right) { * @returns {boolean} true if left and right are within the provided epsilon, false otherwise. */ Matrix3.equalsEpsilon = function (left, right, epsilon) { - epsilon = defaultValue(epsilon, 0); + epsilon = epsilon ?? 0; return ( left === right || diff --git a/packages/engine/Source/Core/Matrix4.js b/packages/engine/Source/Core/Matrix4.js index afd1949ad9f4..e085eb101902 100644 --- a/packages/engine/Source/Core/Matrix4.js +++ b/packages/engine/Source/Core/Matrix4.js @@ -71,22 +71,22 @@ function Matrix4( column2Row3, column3Row3, ) { - this[0] = defaultValue(column0Row0, 0.0); - this[1] = defaultValue(column0Row1, 0.0); - this[2] = defaultValue(column0Row2, 0.0); - this[3] = defaultValue(column0Row3, 0.0); - this[4] = defaultValue(column1Row0, 0.0); - this[5] = defaultValue(column1Row1, 0.0); - this[6] = defaultValue(column1Row2, 0.0); - this[7] = defaultValue(column1Row3, 0.0); - this[8] = defaultValue(column2Row0, 0.0); - this[9] = defaultValue(column2Row1, 0.0); - this[10] = defaultValue(column2Row2, 0.0); - this[11] = defaultValue(column2Row3, 0.0); - this[12] = defaultValue(column3Row0, 0.0); - this[13] = defaultValue(column3Row1, 0.0); - this[14] = defaultValue(column3Row2, 0.0); - this[15] = defaultValue(column3Row3, 0.0); + this[0] = column0Row0 ?? 0.0; + this[1] = column0Row1 ?? 0.0; + this[2] = column0Row2 ?? 0.0; + this[3] = column0Row3 ?? 0.0; + this[4] = column1Row0 ?? 0.0; + this[5] = column1Row1 ?? 0.0; + this[6] = column1Row2 ?? 0.0; + this[7] = column1Row3 ?? 0.0; + this[8] = column2Row0 ?? 0.0; + this[9] = column2Row1 ?? 0.0; + this[10] = column2Row2 ?? 0.0; + this[11] = column2Row3 ?? 0.0; + this[12] = column3Row0 ?? 0.0; + this[13] = column3Row1 ?? 0.0; + this[14] = column3Row2 ?? 0.0; + this[15] = column3Row3 ?? 0.0; } /** @@ -110,7 +110,7 @@ Matrix4.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value[0]; array[startingIndex++] = value[1]; @@ -145,7 +145,7 @@ Matrix4.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Matrix4(); @@ -389,7 +389,7 @@ Matrix4.fromRotationTranslation = function (rotation, translation, result) { Check.typeOf.object("rotation", rotation); //>>includeEnd('debug'); - translation = defaultValue(translation, Cartesian3.ZERO); + translation = translation ?? Cartesian3.ZERO; if (!defined(result)) { return new Matrix4( @@ -1073,13 +1073,13 @@ Matrix4.computeViewportTransformation = function ( result = new Matrix4(); } - viewport = defaultValue(viewport, defaultValue.EMPTY_OBJECT); - const x = defaultValue(viewport.x, 0.0); - const y = defaultValue(viewport.y, 0.0); - const width = defaultValue(viewport.width, 0.0); - const height = defaultValue(viewport.height, 0.0); - nearDepthRange = defaultValue(nearDepthRange, 0.0); - farDepthRange = defaultValue(farDepthRange, 1.0); + viewport = viewport ?? defaultValue.EMPTY_OBJECT; + const x = viewport.x ?? 0.0; + const y = viewport.y ?? 0.0; + const width = viewport.width ?? 0.0; + const height = viewport.height ?? 0.0; + nearDepthRange = nearDepthRange ?? 0.0; + farDepthRange = farDepthRange ?? 1.0; const halfWidth = width * 0.5; const halfHeight = height * 0.5; @@ -2577,7 +2577,7 @@ Matrix4.equals = function (left, right) { * //Prints "Difference between both the matrices is not less than 0.1" on the console */ Matrix4.equalsEpsilon = function (left, right, epsilon) { - epsilon = defaultValue(epsilon, 0); + epsilon = epsilon ?? 0; return ( left === right || diff --git a/packages/engine/Source/Core/MorphWeightSpline.js b/packages/engine/Source/Core/MorphWeightSpline.js index a3ff99b7555b..2bbc6bb2f330 100644 --- a/packages/engine/Source/Core/MorphWeightSpline.js +++ b/packages/engine/Source/Core/MorphWeightSpline.js @@ -40,7 +40,7 @@ import Spline from "./Spline.js"; * @see QuaternionSpline */ function MorphWeightSpline(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const weights = options.weights; const times = options.times; diff --git a/packages/engine/Source/Core/NearFarScalar.js b/packages/engine/Source/Core/NearFarScalar.js index bddaf7912839..cfc4253b1fa0 100644 --- a/packages/engine/Source/Core/NearFarScalar.js +++ b/packages/engine/Source/Core/NearFarScalar.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -20,25 +19,25 @@ function NearFarScalar(near, nearValue, far, farValue) { * @type {number} * @default 0.0 */ - this.near = defaultValue(near, 0.0); + this.near = near ?? 0.0; /** * The value at the lower bound of the camera range. * @type {number} * @default 0.0 */ - this.nearValue = defaultValue(nearValue, 0.0); + this.nearValue = nearValue ?? 0.0; /** * The upper bound of the camera range. * @type {number} * @default 1.0 */ - this.far = defaultValue(far, 1.0); + this.far = far ?? 1.0; /** * The value at the upper bound of the camera range. * @type {number} * @default 0.0 */ - this.farValue = defaultValue(farValue, 0.0); + this.farValue = farValue ?? 0.0; } /** @@ -94,7 +93,7 @@ NearFarScalar.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.near; array[startingIndex++] = value.nearValue; @@ -119,7 +118,7 @@ NearFarScalar.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new NearFarScalar(); diff --git a/packages/engine/Source/Core/Occluder.js b/packages/engine/Source/Core/Occluder.js index ed24dde73bf9..ba7553d4408c 100644 --- a/packages/engine/Source/Core/Occluder.js +++ b/packages/engine/Source/Core/Occluder.js @@ -1,6 +1,5 @@ import BoundingSphere from "./BoundingSphere.js"; import Cartesian3 from "./Cartesian3.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -507,7 +506,7 @@ Occluder.computeOccludeePointFromRectangle = function (rectangle, ellipsoid) { } //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; const positions = Rectangle.subsample( rectangle, ellipsoid, diff --git a/packages/engine/Source/Core/OffsetGeometryInstanceAttribute.js b/packages/engine/Source/Core/OffsetGeometryInstanceAttribute.js index 039d0b2136af..16d7e61571cb 100644 --- a/packages/engine/Source/Core/OffsetGeometryInstanceAttribute.js +++ b/packages/engine/Source/Core/OffsetGeometryInstanceAttribute.js @@ -1,6 +1,5 @@ import Check from "./Check.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; /** @@ -19,9 +18,9 @@ import defined from "./defined.js"; * @see GeometryInstanceAttribute */ function OffsetGeometryInstanceAttribute(x, y, z) { - x = defaultValue(x, 0); - y = defaultValue(y, 0); - z = defaultValue(z, 0); + x = x ?? 0; + y = y ?? 0; + z = z ?? 0; /** * The values for the attributes stored in a typed array. diff --git a/packages/engine/Source/Core/OpenCageGeocoderService.js b/packages/engine/Source/Core/OpenCageGeocoderService.js index 0ff5c2e62c76..f3162d2459eb 100644 --- a/packages/engine/Source/Core/OpenCageGeocoderService.js +++ b/packages/engine/Source/Core/OpenCageGeocoderService.js @@ -2,7 +2,6 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; import combine from "./combine.js"; import Credit from "./Credit.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Rectangle from "./Rectangle.js"; import Resource from "./Resource.js"; @@ -48,7 +47,7 @@ function OpenCageGeocoderService(url, apiKey, params) { url.appendForwardSlash(); url.setQueryParameters({ key: apiKey }); this._url = url; - this._params = defaultValue(params, {}); + this._params = params ?? {}; this._credit = new Credit( `Geodata copyright OpenStreetMap contributors`, false, diff --git a/packages/engine/Source/Core/OrientedBoundingBox.js b/packages/engine/Source/Core/OrientedBoundingBox.js index cf4a6d392b47..b1828f7e62c3 100644 --- a/packages/engine/Source/Core/OrientedBoundingBox.js +++ b/packages/engine/Source/Core/OrientedBoundingBox.js @@ -3,7 +3,6 @@ import Cartesian2 from "./Cartesian2.js"; import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -44,7 +43,7 @@ function OrientedBoundingBox(center, halfAxes) { * @type {Cartesian3} * @default {@link Cartesian3.ZERO} */ - this.center = Cartesian3.clone(defaultValue(center, Cartesian3.ZERO)); + this.center = Cartesian3.clone(center ?? Cartesian3.ZERO); /** * The three orthogonal half-axes of the bounding box. Equivalently, the * transformation matrix, to rotate and scale a 2x2x2 cube centered at the @@ -52,7 +51,7 @@ function OrientedBoundingBox(center, halfAxes) { * @type {Matrix3} * @default {@link Matrix3.ZERO} */ - this.halfAxes = Matrix3.clone(defaultValue(halfAxes, Matrix3.ZERO)); + this.halfAxes = Matrix3.clone(halfAxes ?? Matrix3.ZERO); } /** @@ -77,7 +76,7 @@ OrientedBoundingBox.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Cartesian3.pack(value.center, array, startingIndex); Matrix3.pack(value.halfAxes, array, startingIndex + Cartesian3.packedLength); @@ -98,7 +97,7 @@ OrientedBoundingBox.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new OrientedBoundingBox(); @@ -371,9 +370,9 @@ OrientedBoundingBox.fromRectangle = function ( } //>>includeEnd('debug'); - minimumHeight = defaultValue(minimumHeight, 0.0); - maximumHeight = defaultValue(maximumHeight, 0.0); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + minimumHeight = minimumHeight ?? 0.0; + maximumHeight = maximumHeight ?? 0.0; + ellipsoid = ellipsoid ?? Ellipsoid.default; let minX, maxX, minY, maxY, minZ, maxZ, plane; diff --git a/packages/engine/Source/Core/OrthographicFrustum.js b/packages/engine/Source/Core/OrthographicFrustum.js index 5d3d60245128..02d7a2936bac 100644 --- a/packages/engine/Source/Core/OrthographicFrustum.js +++ b/packages/engine/Source/Core/OrthographicFrustum.js @@ -28,7 +28,7 @@ import OrthographicOffCenterFrustum from "./OrthographicOffCenterFrustum.js"; * frustum.far = 50.0 * maxRadii; */ function OrthographicFrustum(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._offCenterFrustum = new OrthographicOffCenterFrustum(); @@ -53,7 +53,7 @@ function OrthographicFrustum(options) { * @type {number} * @default 1.0 */ - this.near = defaultValue(options.near, 1.0); + this.near = options.near ?? 1.0; this._near = this.near; /** @@ -61,7 +61,7 @@ function OrthographicFrustum(options) { * @type {number} * @default 500000000.0; */ - this.far = defaultValue(options.far, 500000000.0); + this.far = options.far ?? 500000000.0; this._far = this.far; } @@ -86,7 +86,7 @@ OrthographicFrustum.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.width; array[startingIndex++] = value.aspectRatio; @@ -109,7 +109,7 @@ OrthographicFrustum.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new OrthographicFrustum(); diff --git a/packages/engine/Source/Core/OrthographicOffCenterFrustum.js b/packages/engine/Source/Core/OrthographicOffCenterFrustum.js index a28790bc965b..77839788b9d5 100644 --- a/packages/engine/Source/Core/OrthographicOffCenterFrustum.js +++ b/packages/engine/Source/Core/OrthographicOffCenterFrustum.js @@ -36,7 +36,7 @@ import Matrix4 from "./Matrix4.js"; * frustum.far = 50.0 * maxRadii; */ function OrthographicOffCenterFrustum(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The left clipping plane. @@ -75,7 +75,7 @@ function OrthographicOffCenterFrustum(options) { * @type {number} * @default 1.0 */ - this.near = defaultValue(options.near, 1.0); + this.near = options.near ?? 1.0; this._near = this.near; /** @@ -83,7 +83,7 @@ function OrthographicOffCenterFrustum(options) { * @type {number} * @default 500000000.0; */ - this.far = defaultValue(options.far, 500000000.0); + this.far = options.far ?? 500000000.0; this._far = this.far; this._cullingVolume = new CullingVolume(); diff --git a/packages/engine/Source/Core/PerspectiveFrustum.js b/packages/engine/Source/Core/PerspectiveFrustum.js index 9c42b739ce58..a24380baa4be 100644 --- a/packages/engine/Source/Core/PerspectiveFrustum.js +++ b/packages/engine/Source/Core/PerspectiveFrustum.js @@ -33,7 +33,7 @@ import PerspectiveOffCenterFrustum from "./PerspectiveOffCenterFrustum.js"; * @see PerspectiveOffCenterFrustum */ function PerspectiveFrustum(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._offCenterFrustum = new PerspectiveOffCenterFrustum(); @@ -63,7 +63,7 @@ function PerspectiveFrustum(options) { * @type {number} * @default 1.0 */ - this.near = defaultValue(options.near, 1.0); + this.near = options.near ?? 1.0; this._near = this.near; /** @@ -71,7 +71,7 @@ function PerspectiveFrustum(options) { * @type {number} * @default 500000000.0 */ - this.far = defaultValue(options.far, 500000000.0); + this.far = options.far ?? 500000000.0; this._far = this.far; /** @@ -79,7 +79,7 @@ function PerspectiveFrustum(options) { * @type {number} * @default 0.0 */ - this.xOffset = defaultValue(options.xOffset, 0.0); + this.xOffset = options.xOffset ?? 0.0; this._xOffset = this.xOffset; /** @@ -87,7 +87,7 @@ function PerspectiveFrustum(options) { * @type {number} * @default 0.0 */ - this.yOffset = defaultValue(options.yOffset, 0.0); + this.yOffset = options.yOffset ?? 0.0; this._yOffset = this.yOffset; } @@ -112,7 +112,7 @@ PerspectiveFrustum.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.fov; array[startingIndex++] = value.aspectRatio; @@ -137,7 +137,7 @@ PerspectiveFrustum.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new PerspectiveFrustum(); diff --git a/packages/engine/Source/Core/PerspectiveOffCenterFrustum.js b/packages/engine/Source/Core/PerspectiveOffCenterFrustum.js index fb4c4af981dd..2b1ed81e93fc 100644 --- a/packages/engine/Source/Core/PerspectiveOffCenterFrustum.js +++ b/packages/engine/Source/Core/PerspectiveOffCenterFrustum.js @@ -37,7 +37,7 @@ import Matrix4 from "./Matrix4.js"; * @see PerspectiveFrustum */ function PerspectiveOffCenterFrustum(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * Defines the left clipping plane. @@ -76,7 +76,7 @@ function PerspectiveOffCenterFrustum(options) { * @type {number} * @default 1.0 */ - this.near = defaultValue(options.near, 1.0); + this.near = options.near ?? 1.0; this._near = this.near; /** @@ -84,7 +84,7 @@ function PerspectiveOffCenterFrustum(options) { * @type {number} * @default 500000000.0 */ - this.far = defaultValue(options.far, 500000000.0); + this.far = options.far ?? 500000000.0; this._far = this.far; this._cullingVolume = new CullingVolume(); diff --git a/packages/engine/Source/Core/PlaneGeometry.js b/packages/engine/Source/Core/PlaneGeometry.js index cfc96a536ae7..922d2fde1ce8 100644 --- a/packages/engine/Source/Core/PlaneGeometry.js +++ b/packages/engine/Source/Core/PlaneGeometry.js @@ -25,9 +25,9 @@ import VertexFormat from "./VertexFormat.js"; * }); */ function PlaneGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; this._vertexFormat = vertexFormat; this._workerName = "createPlaneGeometry"; @@ -54,7 +54,7 @@ PlaneGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; VertexFormat.pack(value._vertexFormat, array, startingIndex); @@ -79,7 +79,7 @@ PlaneGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const vertexFormat = VertexFormat.unpack( array, diff --git a/packages/engine/Source/Core/PolygonGeometry.js b/packages/engine/Source/Core/PolygonGeometry.js index de5ab60ecf30..112b3b691788 100644 --- a/packages/engine/Source/Core/PolygonGeometry.js +++ b/packages/engine/Source/Core/PolygonGeometry.js @@ -690,19 +690,16 @@ function PolygonGeometry(options) { //>>includeEnd('debug'); const polygonHierarchy = options.polygonHierarchy; - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const stRotation = defaultValue(options.stRotation, 0.0); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const stRotation = options.stRotation ?? 0.0; const textureCoordinates = options.textureCoordinates; - const perPositionHeight = defaultValue(options.perPositionHeight, false); + const perPositionHeight = options.perPositionHeight ?? false; const perPositionHeightExtrude = perPositionHeight && defined(options.extrudedHeight); - let height = defaultValue(options.height, 0.0); - let extrudedHeight = defaultValue(options.extrudedHeight, height); + let height = options.height ?? 0.0; + let extrudedHeight = options.extrudedHeight ?? height; if (!perPositionHeightExtrude) { const h = Math.max(height, extrudedHeight); @@ -716,15 +713,15 @@ function PolygonGeometry(options) { this._stRotation = stRotation; this._height = height; this._extrudedHeight = extrudedHeight; - this._closeTop = defaultValue(options.closeTop, true); - this._closeBottom = defaultValue(options.closeBottom, true); + this._closeTop = options.closeTop ?? true; + this._closeBottom = options.closeBottom ?? true; this._polygonHierarchy = polygonHierarchy; this._perPositionHeight = perPositionHeight; this._perPositionHeightExtrude = perPositionHeightExtrude; - this._shadowVolume = defaultValue(options.shadowVolume, false); + this._shadowVolume = options.shadowVolume ?? false; this._workerName = "createPolygonGeometry"; this._offsetAttribute = options.offsetAttribute; - this._arcType = defaultValue(options.arcType, ArcType.GEODESIC); + this._arcType = options.arcType ?? ArcType.GEODESIC; this._rectangle = undefined; this._textureCoordinateRotationPoints = undefined; @@ -784,7 +781,7 @@ function PolygonGeometry(options) { * @see PolygonGeometry#createGeometry */ PolygonGeometry.fromPositions = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.positions", options.positions); @@ -825,7 +822,7 @@ PolygonGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; startingIndex = PolygonGeometryLibrary.packPolygonHierarchy( value._polygonHierarchy, @@ -849,7 +846,7 @@ PolygonGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._closeTop ? 1.0 : 0.0; array[startingIndex++] = value._closeBottom ? 1.0 : 0.0; array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0; - array[startingIndex++] = defaultValue(value._offsetAttribute, -1); + array[startingIndex++] = value._offsetAttribute ?? -1; array[startingIndex++] = value._arcType; if (defined(value._textureCoordinates)) { startingIndex = PolygonGeometryLibrary.packPolygonHierarchy( @@ -885,7 +882,7 @@ PolygonGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy( array, diff --git a/packages/engine/Source/Core/PolygonGeometryLibrary.js b/packages/engine/Source/Core/PolygonGeometryLibrary.js index ef288ae330df..fa6069e3a0df 100644 --- a/packages/engine/Source/Core/PolygonGeometryLibrary.js +++ b/packages/engine/Source/Core/PolygonGeometryLibrary.js @@ -4,7 +4,6 @@ import Cartesian2 from "./Cartesian2.js"; import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Ellipsoid from "./Ellipsoid.js"; import EllipsoidRhumbLine from "./EllipsoidRhumbLine.js"; @@ -362,7 +361,7 @@ PolygonGeometryLibrary.scaleToGeodeticHeightExtruded = function ( ellipsoid, perPositionHeight, ) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; const n1 = scaleToGeodeticHeightN1; let n2 = scaleToGeodeticHeightN2; diff --git a/packages/engine/Source/Core/PolygonOutlineGeometry.js b/packages/engine/Source/Core/PolygonOutlineGeometry.js index f103369d1dce..6cb7e01a4358 100644 --- a/packages/engine/Source/Core/PolygonOutlineGeometry.js +++ b/packages/engine/Source/Core/PolygonOutlineGeometry.js @@ -368,18 +368,15 @@ function PolygonOutlineGeometry(options) { //>>includeEnd('debug'); const polygonHierarchy = options.polygonHierarchy; - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const perPositionHeight = defaultValue(options.perPositionHeight, false); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const perPositionHeight = options.perPositionHeight ?? false; const perPositionHeightExtrude = perPositionHeight && defined(options.extrudedHeight); - const arcType = defaultValue(options.arcType, ArcType.GEODESIC); + const arcType = options.arcType ?? ArcType.GEODESIC; - let height = defaultValue(options.height, 0.0); - let extrudedHeight = defaultValue(options.extrudedHeight, height); + let height = options.height ?? 0.0; + let extrudedHeight = options.extrudedHeight ?? height; if (!perPositionHeightExtrude) { const h = Math.max(height, extrudedHeight); @@ -426,7 +423,7 @@ PolygonOutlineGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; startingIndex = PolygonGeometryLibrary.packPolygonHierarchy( value._polygonHierarchy, @@ -444,7 +441,7 @@ PolygonOutlineGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._perPositionHeightExtrude ? 1.0 : 0.0; array[startingIndex++] = value._perPositionHeight ? 1.0 : 0.0; array[startingIndex++] = value._arcType; - array[startingIndex++] = defaultValue(value._offsetAttribute, -1); + array[startingIndex++] = value._offsetAttribute ?? -1; array[startingIndex] = value.packedLength; return array; @@ -468,7 +465,7 @@ PolygonOutlineGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const polygonHierarchy = PolygonGeometryLibrary.unpackPolygonHierarchy( array, @@ -539,7 +536,7 @@ PolygonOutlineGeometry.unpack = function (array, startingIndex, result) { * @see PolygonOutlineGeometry#createGeometry */ PolygonOutlineGeometry.fromPositions = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.positions", options.positions); diff --git a/packages/engine/Source/Core/PolygonPipeline.js b/packages/engine/Source/Core/PolygonPipeline.js index 328668edb7ce..4e703d240a85 100644 --- a/packages/engine/Source/Core/PolygonPipeline.js +++ b/packages/engine/Source/Core/PolygonPipeline.js @@ -4,7 +4,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Ellipsoid from "./Ellipsoid.js"; import EllipsoidRhumbLine from "./EllipsoidRhumbLine.js"; @@ -106,7 +105,7 @@ PolygonPipeline.computeSubdivision = function ( texcoords, granularity, ) { - granularity = defaultValue(granularity, CesiumMath.RADIANS_PER_DEGREE); + granularity = granularity ?? CesiumMath.RADIANS_PER_DEGREE; const hasTexcoords = defined(texcoords); @@ -341,7 +340,7 @@ PolygonPipeline.computeRhumbLineSubdivision = function ( texcoords, granularity, ) { - granularity = defaultValue(granularity, CesiumMath.RADIANS_PER_DEGREE); + granularity = granularity ?? CesiumMath.RADIANS_PER_DEGREE; const hasTexcoords = defined(texcoords); @@ -597,13 +596,13 @@ PolygonPipeline.scaleToGeodeticHeight = function ( ellipsoid, scaleToSurface, ) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; let n = scaleToGeodeticHeightN; let p = scaleToGeodeticHeightP; - height = defaultValue(height, 0.0); - scaleToSurface = defaultValue(scaleToSurface, true); + height = height ?? 0.0; + scaleToSurface = scaleToSurface ?? true; if (defined(positions)) { const length = positions.length; diff --git a/packages/engine/Source/Core/PolylineGeometry.js b/packages/engine/Source/Core/PolylineGeometry.js index d0f9ec3dcf68..f54c3941fe12 100644 --- a/packages/engine/Source/Core/PolylineGeometry.js +++ b/packages/engine/Source/Core/PolylineGeometry.js @@ -98,11 +98,11 @@ function interpolateColors(p0, p1, color0, color1, numPoints) { * const geometry = Cesium.PolylineGeometry.createGeometry(polyline); */ function PolylineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; const colors = options.colors; - const width = defaultValue(options.width, 1.0); - const colorsPerVertex = defaultValue(options.colorsPerVertex, false); + const width = options.width ?? 1.0; + const colorsPerVertex = options.colorsPerVertex ?? false; //>>includeStart('debug', pragmas.debug); if (!defined(positions) || positions.length < 2) { @@ -125,17 +125,12 @@ function PolylineGeometry(options) { this._width = width; this._colorsPerVertex = colorsPerVertex; this._vertexFormat = VertexFormat.clone( - defaultValue(options.vertexFormat, VertexFormat.DEFAULT), + options.vertexFormat ?? VertexFormat.DEFAULT, ); - this._arcType = defaultValue(options.arcType, ArcType.GEODESIC); - this._granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - this._ellipsoid = Ellipsoid.clone( - defaultValue(options.ellipsoid, Ellipsoid.default), - ); + this._arcType = options.arcType ?? ArcType.GEODESIC; + this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default); this._workerName = "createPolylineGeometry"; let numComponents = 1 + positions.length * Cartesian3.packedLength; @@ -168,7 +163,7 @@ PolylineGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -230,7 +225,7 @@ PolylineGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; diff --git a/packages/engine/Source/Core/PolylinePipeline.js b/packages/engine/Source/Core/PolylinePipeline.js index 62227355b99c..b00e60291c87 100644 --- a/packages/engine/Source/Core/PolylinePipeline.js +++ b/packages/engine/Source/Core/PolylinePipeline.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -208,7 +207,7 @@ PolylinePipeline.wrapLongitude = function (positions, modelMatrix) { const segments = []; if (defined(positions) && positions.length > 0) { - modelMatrix = defaultValue(modelMatrix, Matrix4.IDENTITY); + modelMatrix = modelMatrix ?? Matrix4.IDENTITY; const inverseModelMatrix = Matrix4.inverseTransformation( modelMatrix, wrapLongitudeInversMatrix, @@ -337,8 +336,8 @@ PolylinePipeline.generateArc = function (options) { //>>includeEnd('debug'); const length = positions.length; - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - let height = defaultValue(options.height, 0); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; + let height = options.height ?? 0; const hasHeightArray = Array.isArray(height); if (length < 1) { @@ -357,10 +356,7 @@ PolylinePipeline.generateArc = function (options) { let minDistance = options.minDistance; if (!defined(minDistance)) { - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius); } @@ -444,8 +440,8 @@ PolylinePipeline.generateRhumbArc = function (options) { //>>includeEnd('debug'); const length = positions.length; - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - let height = defaultValue(options.height, 0); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; + let height = options.height ?? 0; const hasHeightArray = Array.isArray(height); if (length < 1) { @@ -462,10 +458,7 @@ PolylinePipeline.generateRhumbArc = function (options) { return [p.x, p.y, p.z]; } - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; let numPoints = 0; let i; diff --git a/packages/engine/Source/Core/PolylineVolumeGeometry.js b/packages/engine/Source/Core/PolylineVolumeGeometry.js index 4567b67069b7..fd631a0cc7e2 100644 --- a/packages/engine/Source/Core/PolylineVolumeGeometry.js +++ b/packages/engine/Source/Core/PolylineVolumeGeometry.js @@ -207,7 +207,7 @@ function computeAttributes( * }); */ function PolylineVolumeGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.polylinePositions; const shape = options.shapePositions; @@ -222,17 +222,12 @@ function PolylineVolumeGeometry(options) { this._positions = positions; this._shape = shape; - this._ellipsoid = Ellipsoid.clone( - defaultValue(options.ellipsoid, Ellipsoid.default), - ); - this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); + this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default); + this._cornerType = options.cornerType ?? CornerType.ROUNDED; this._vertexFormat = VertexFormat.clone( - defaultValue(options.vertexFormat, VertexFormat.DEFAULT), - ); - this._granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, + options.vertexFormat ?? VertexFormat.DEFAULT, ); + this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; this._workerName = "createPolylineVolumeGeometry"; let numComponents = 1 + positions.length * Cartesian3.packedLength; @@ -265,7 +260,7 @@ PolylineVolumeGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -323,7 +318,7 @@ PolylineVolumeGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; diff --git a/packages/engine/Source/Core/PolylineVolumeOutlineGeometry.js b/packages/engine/Source/Core/PolylineVolumeOutlineGeometry.js index 6ac4232b505e..51b60a5d5d15 100644 --- a/packages/engine/Source/Core/PolylineVolumeOutlineGeometry.js +++ b/packages/engine/Source/Core/PolylineVolumeOutlineGeometry.js @@ -108,7 +108,7 @@ function computeAttributes(positions, shape) { * }); */ function PolylineVolumeOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.polylinePositions; const shape = options.shapePositions; @@ -123,14 +123,9 @@ function PolylineVolumeOutlineGeometry(options) { this._positions = positions; this._shape = shape; - this._ellipsoid = Ellipsoid.clone( - defaultValue(options.ellipsoid, Ellipsoid.default), - ); - this._cornerType = defaultValue(options.cornerType, CornerType.ROUNDED); - this._granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); + this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default); + this._cornerType = options.cornerType ?? CornerType.ROUNDED; + this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; this._workerName = "createPolylineVolumeOutlineGeometry"; let numComponents = 1 + positions.length * Cartesian3.packedLength; @@ -162,7 +157,7 @@ PolylineVolumeOutlineGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -216,7 +211,7 @@ PolylineVolumeOutlineGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; diff --git a/packages/engine/Source/Core/QuantizedMeshTerrainData.js b/packages/engine/Source/Core/QuantizedMeshTerrainData.js index 5f2e17d49051..a727f38313cb 100644 --- a/packages/engine/Source/Core/QuantizedMeshTerrainData.js +++ b/packages/engine/Source/Core/QuantizedMeshTerrainData.js @@ -199,9 +199,9 @@ function QuantizedMeshTerrainData(options) { this._eastSkirtHeight = options.eastSkirtHeight; this._northSkirtHeight = options.northSkirtHeight; - this._childTileMask = defaultValue(options.childTileMask, 15); + this._childTileMask = options.childTileMask ?? 15; - this._createdByUpsampling = defaultValue(options.createdByUpsampling, false); + this._createdByUpsampling = options.createdByUpsampling ?? false; this._waterMask = options.waterMask; this._mesh = undefined; @@ -288,7 +288,7 @@ const createMeshTaskProcessorThrottle = new TaskProcessor( * be retried later. */ QuantizedMeshTerrainData.prototype.createMesh = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.tilingScheme", options.tilingScheme); @@ -301,12 +301,9 @@ QuantizedMeshTerrainData.prototype.createMesh = function (options) { const x = options.x; const y = options.y; const level = options.level; - const exaggeration = defaultValue(options.exaggeration, 1.0); - const exaggerationRelativeHeight = defaultValue( - options.exaggerationRelativeHeight, - 0.0, - ); - const throttle = defaultValue(options.throttle, true); + const exaggeration = options.exaggeration ?? 1.0; + const exaggerationRelativeHeight = options.exaggerationRelativeHeight ?? 0.0; + const throttle = options.throttle ?? true; const ellipsoid = tilingScheme.ellipsoid; const rectangle = tilingScheme.tileXYToRectangle(x, y, level); @@ -362,10 +359,9 @@ QuantizedMeshTerrainData.prototype.createMesh = function (options) { const maximumHeight = result.maximumHeight; const boundingSphere = that._boundingSphere; const obb = that._orientedBoundingBox; - const occludeePointInScaledSpace = defaultValue( - Cartesian3.clone(result.occludeePointInScaledSpace), - that._horizonOcclusionPoint, - ); + const occludeePointInScaledSpace = + Cartesian3.clone(result.occludeePointInScaledSpace) ?? + that._horizonOcclusionPoint; const stride = result.vertexStride; const terrainEncoding = TerrainEncoding.clone(result.encoding); diff --git a/packages/engine/Source/Core/Quaternion.js b/packages/engine/Source/Core/Quaternion.js index b91289d9662d..ef8ccbcdbff5 100644 --- a/packages/engine/Source/Core/Quaternion.js +++ b/packages/engine/Source/Core/Quaternion.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import FeatureDetection from "./FeatureDetection.js"; import CesiumMath from "./Math.js"; @@ -24,28 +23,28 @@ function Quaternion(x, y, z, w) { * @type {number} * @default 0.0 */ - this.x = defaultValue(x, 0.0); + this.x = x ?? 0.0; /** * The Y component. * @type {number} * @default 0.0 */ - this.y = defaultValue(y, 0.0); + this.y = y ?? 0.0; /** * The Z component. * @type {number} * @default 0.0 */ - this.z = defaultValue(z, 0.0); + this.z = z ?? 0.0; /** * The W component. * @type {number} * @default 0.0 */ - this.w = defaultValue(w, 0.0); + this.w = w ?? 0.0; } let fromAxisAngleScratch = new Cartesian3(); @@ -239,7 +238,7 @@ Quaternion.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.x; array[startingIndex++] = value.y; @@ -262,7 +261,7 @@ Quaternion.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Quaternion(); @@ -1072,7 +1071,7 @@ Quaternion.equals = function (left, right) { * @returns {boolean} true if left and right are within the provided epsilon, false otherwise. */ Quaternion.equalsEpsilon = function (left, right, epsilon) { - epsilon = defaultValue(epsilon, 0); + epsilon = epsilon ?? 0; return ( left === right || diff --git a/packages/engine/Source/Core/QuaternionSpline.js b/packages/engine/Source/Core/QuaternionSpline.js index bf7bd05e5bd6..8fae3736c7b5 100644 --- a/packages/engine/Source/Core/QuaternionSpline.js +++ b/packages/engine/Source/Core/QuaternionSpline.js @@ -50,7 +50,7 @@ function createEvaluateFunction(spline) { * @see MorphWeightSpline */ function QuaternionSpline(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const points = options.points; const times = options.times; diff --git a/packages/engine/Source/Core/Ray.js b/packages/engine/Source/Core/Ray.js index 6b63229d65b0..acff1c4e86d4 100644 --- a/packages/engine/Source/Core/Ray.js +++ b/packages/engine/Source/Core/Ray.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; /** @@ -12,7 +11,7 @@ import defined from "./defined.js"; * @param {Cartesian3} [direction=Cartesian3.ZERO] The direction of the ray. */ function Ray(origin, direction) { - direction = Cartesian3.clone(defaultValue(direction, Cartesian3.ZERO)); + direction = Cartesian3.clone(direction ?? Cartesian3.ZERO); if (!Cartesian3.equals(direction, Cartesian3.ZERO)) { Cartesian3.normalize(direction, direction); } @@ -22,7 +21,7 @@ function Ray(origin, direction) { * @type {Cartesian3} * @default {@link Cartesian3.ZERO} */ - this.origin = Cartesian3.clone(defaultValue(origin, Cartesian3.ZERO)); + this.origin = Cartesian3.clone(origin ?? Cartesian3.ZERO); /** * The direction of the ray. diff --git a/packages/engine/Source/Core/Rectangle.js b/packages/engine/Source/Core/Rectangle.js index 915a5289f909..bd7ed3f8e76f 100644 --- a/packages/engine/Source/Core/Rectangle.js +++ b/packages/engine/Source/Core/Rectangle.js @@ -1,7 +1,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Ellipsoid from "./Ellipsoid.js"; import CesiumMath from "./Math.js"; @@ -29,7 +28,7 @@ function Rectangle(west, south, east, north) { * @type {number} * @default 0.0 */ - this.west = defaultValue(west, 0.0); + this.west = west ?? 0.0; /** * The southernmost latitude in radians in the range [-Pi/2, Pi/2]. @@ -37,7 +36,7 @@ function Rectangle(west, south, east, north) { * @type {number} * @default 0.0 */ - this.south = defaultValue(south, 0.0); + this.south = south ?? 0.0; /** * The easternmost longitude in radians in the range [-Pi, Pi]. @@ -45,7 +44,7 @@ function Rectangle(west, south, east, north) { * @type {number} * @default 0.0 */ - this.east = defaultValue(east, 0.0); + this.east = east ?? 0.0; /** * The northernmost latitude in radians in the range [-Pi/2, Pi/2]. @@ -53,7 +52,7 @@ function Rectangle(west, south, east, north) { * @type {number} * @default 0.0 */ - this.north = defaultValue(north, 0.0); + this.north = north ?? 0.0; } Object.defineProperties(Rectangle.prototype, { @@ -103,7 +102,7 @@ Rectangle.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.west; array[startingIndex++] = value.south; @@ -126,7 +125,7 @@ Rectangle.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new Rectangle(); @@ -182,10 +181,10 @@ Rectangle.computeHeight = function (rectangle) { * const rectangle = Cesium.Rectangle.fromDegrees(0.0, 20.0, 10.0, 30.0); */ Rectangle.fromDegrees = function (west, south, east, north, result) { - west = CesiumMath.toRadians(defaultValue(west, 0.0)); - south = CesiumMath.toRadians(defaultValue(south, 0.0)); - east = CesiumMath.toRadians(defaultValue(east, 0.0)); - north = CesiumMath.toRadians(defaultValue(north, 0.0)); + west = CesiumMath.toRadians(west ?? 0.0); + south = CesiumMath.toRadians(south ?? 0.0); + east = CesiumMath.toRadians(east ?? 0.0); + north = CesiumMath.toRadians(north ?? 0.0); if (!defined(result)) { return new Rectangle(west, south, east, north); @@ -217,10 +216,10 @@ Rectangle.fromRadians = function (west, south, east, north, result) { return new Rectangle(west, south, east, north); } - result.west = defaultValue(west, 0.0); - result.south = defaultValue(south, 0.0); - result.east = defaultValue(east, 0.0); - result.north = defaultValue(north, 0.0); + result.west = west ?? 0.0; + result.south = south ?? 0.0; + result.east = east ?? 0.0; + result.north = north ?? 0.0; return result; }; @@ -294,7 +293,7 @@ Rectangle.fromCartesianArray = function (cartesians, ellipsoid, result) { //>>includeStart('debug', pragmas.debug); Check.defined("cartesians", cartesians); //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; let west = Number.MAX_VALUE; let east = -Number.MAX_VALUE; @@ -466,7 +465,7 @@ Rectangle.clone = function (rectangle, result) { * @returns {boolean} true if left and right are within the provided epsilon, false otherwise. */ Rectangle.equalsEpsilon = function (left, right, absoluteEpsilon) { - absoluteEpsilon = defaultValue(absoluteEpsilon, 0); + absoluteEpsilon = absoluteEpsilon ?? 0; return ( left === right || @@ -943,8 +942,8 @@ Rectangle.subsample = function (rectangle, ellipsoid, surfaceHeight, result) { Check.typeOf.object("rectangle", rectangle); //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); - surfaceHeight = defaultValue(surfaceHeight, 0.0); + ellipsoid = ellipsoid ?? Ellipsoid.default; + surfaceHeight = surfaceHeight ?? 0.0; if (!defined(result)) { result = []; diff --git a/packages/engine/Source/Core/RectangleGeometry.js b/packages/engine/Source/Core/RectangleGeometry.js index 53bfe23d43d1..f7effec14e49 100644 --- a/packages/engine/Source/Core/RectangleGeometry.js +++ b/packages/engine/Source/Core/RectangleGeometry.js @@ -1014,7 +1014,7 @@ function computeRectangle(rectangle, granularity, rotation, ellipsoid, result) { * const geometry = Cesium.RectangleGeometry.createGeometry(rectangle); */ function RectangleGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const rectangle = options.rectangle; @@ -1028,25 +1028,20 @@ function RectangleGeometry(options) { } //>>includeEnd('debug'); - const height = defaultValue(options.height, 0.0); - const extrudedHeight = defaultValue(options.extrudedHeight, height); + const height = options.height ?? 0.0; + const extrudedHeight = options.extrudedHeight ?? height; this._rectangle = Rectangle.clone(rectangle); - this._granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - this._ellipsoid = Ellipsoid.clone( - defaultValue(options.ellipsoid, Ellipsoid.default), - ); + this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + this._ellipsoid = Ellipsoid.clone(options.ellipsoid ?? Ellipsoid.default); this._surfaceHeight = Math.max(height, extrudedHeight); - this._rotation = defaultValue(options.rotation, 0.0); - this._stRotation = defaultValue(options.stRotation, 0.0); + this._rotation = options.rotation ?? 0.0; + this._stRotation = options.stRotation ?? 0.0; this._vertexFormat = VertexFormat.clone( - defaultValue(options.vertexFormat, VertexFormat.DEFAULT), + options.vertexFormat ?? VertexFormat.DEFAULT, ); this._extrudedHeight = Math.min(height, extrudedHeight); - this._shadowVolume = defaultValue(options.shadowVolume, false); + this._shadowVolume = options.shadowVolume ?? false; this._workerName = "createRectangleGeometry"; this._offsetAttribute = options.offsetAttribute; this._rotatedRectangle = undefined; @@ -1079,7 +1074,7 @@ RectangleGeometry.pack = function (value, array, startingIndex) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Rectangle.pack(value._rectangle, array, startingIndex); startingIndex += Rectangle.packedLength; @@ -1096,7 +1091,7 @@ RectangleGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._stRotation; array[startingIndex++] = value._extrudedHeight; array[startingIndex++] = value._shadowVolume ? 1.0 : 0.0; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -1129,7 +1124,7 @@ RectangleGeometry.unpack = function (array, startingIndex, result) { Check.defined("array", array); //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle); startingIndex += Rectangle.packedLength; @@ -1193,7 +1188,7 @@ RectangleGeometry.unpack = function (array, startingIndex, result) { * @returns {Rectangle} The result rectangle */ RectangleGeometry.computeRectangle = function (options, result) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const rectangle = options.rectangle; @@ -1207,12 +1202,9 @@ RectangleGeometry.computeRectangle = function (options, result) { } //>>includeEnd('debug'); - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - const rotation = defaultValue(options.rotation, 0.0); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; + const rotation = options.rotation ?? 0.0; return computeRectangle(rectangle, granularity, rotation, ellipsoid, result); }; diff --git a/packages/engine/Source/Core/RectangleOutlineGeometry.js b/packages/engine/Source/Core/RectangleOutlineGeometry.js index d831c29ffc2f..be44e6c7fd8a 100644 --- a/packages/engine/Source/Core/RectangleOutlineGeometry.js +++ b/packages/engine/Source/Core/RectangleOutlineGeometry.js @@ -270,15 +270,12 @@ function constructExtrudedRectangle(rectangleGeometry, computedOptions) { * const geometry = Cesium.RectangleOutlineGeometry.createGeometry(rectangle); */ function RectangleOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const rectangle = options.rectangle; - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - const rotation = defaultValue(options.rotation, 0.0); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; + const rotation = options.rotation ?? 0.0; //>>includeStart('debug', pragmas.debug); if (!defined(rectangle)) { @@ -292,8 +289,8 @@ function RectangleOutlineGeometry(options) { } //>>includeEnd('debug'); - const height = defaultValue(options.height, 0.0); - const extrudedHeight = defaultValue(options.extrudedHeight, height); + const height = options.height ?? 0.0; + const extrudedHeight = options.extrudedHeight ?? height; this._rectangle = Rectangle.clone(rectangle); this._granularity = granularity; @@ -332,7 +329,7 @@ RectangleOutlineGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; Rectangle.pack(value._rectangle, array, startingIndex); startingIndex += Rectangle.packedLength; @@ -344,7 +341,7 @@ RectangleOutlineGeometry.pack = function (value, array, startingIndex) { array[startingIndex++] = value._surfaceHeight; array[startingIndex++] = value._rotation; array[startingIndex++] = value._extrudedHeight; - array[startingIndex] = defaultValue(value._offsetAttribute, -1); + array[startingIndex] = value._offsetAttribute ?? -1; return array; }; @@ -376,7 +373,7 @@ RectangleOutlineGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; const rectangle = Rectangle.unpack(array, startingIndex, scratchRectangle); startingIndex += Rectangle.packedLength; diff --git a/packages/engine/Source/Core/Request.js b/packages/engine/Source/Core/Request.js index 0274ab3e4d55..1097c1570fdc 100644 --- a/packages/engine/Source/Core/Request.js +++ b/packages/engine/Source/Core/Request.js @@ -21,10 +21,10 @@ import RequestType from "./RequestType.js"; * @param {string} [options.serverKey] A key used to identify the server that a request is going to. */ function Request(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const throttleByServer = defaultValue(options.throttleByServer, false); - const throttle = defaultValue(options.throttle, false); + const throttleByServer = options.throttleByServer ?? false; + const throttle = options.throttle ?? false; /** * The URL to request. @@ -64,7 +64,7 @@ function Request(options) { * @type {number} * @default 0.0 */ - this.priority = defaultValue(options.priority, 0.0); + this.priority = options.priority ?? 0.0; /** * Whether to throttle and prioritize the request. If false, the request will be sent immediately. If true, the @@ -97,7 +97,7 @@ function Request(options) { * * @default RequestType.OTHER */ - this.type = defaultValue(options.type, RequestType.OTHER); + this.type = options.type ?? RequestType.OTHER; /** * A key used to identify the server that a request is going to. It is derived from the url's authority and scheme. diff --git a/packages/engine/Source/Core/RequestScheduler.js b/packages/engine/Source/Core/RequestScheduler.js index e07970bbd619..1734325d6b29 100644 --- a/packages/engine/Source/Core/RequestScheduler.js +++ b/packages/engine/Source/Core/RequestScheduler.js @@ -1,6 +1,5 @@ import Uri from "urijs"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defer from "./defer.js"; import defined from "./defined.js"; import Event from "./Event.js"; @@ -164,12 +163,11 @@ function updatePriority(request) { * @private */ RequestScheduler.serverHasOpenSlots = function (serverKey, desiredRequests) { - desiredRequests = defaultValue(desiredRequests, 1); + desiredRequests = desiredRequests ?? 1; - const maxRequests = defaultValue( - RequestScheduler.requestsByServer[serverKey], - RequestScheduler.maximumRequestsPerServer, - ); + const maxRequests = + RequestScheduler.requestsByServer[serverKey] ?? + RequestScheduler.maximumRequestsPerServer; const hasOpenSlotsServer = numberOfActiveRequestsByServer[serverKey] + desiredRequests <= maxRequests; diff --git a/packages/engine/Source/Core/Resource.js b/packages/engine/Source/Core/Resource.js index 6c5c6566450f..466ac2cde1de 100644 --- a/packages/engine/Source/Core/Resource.js +++ b/packages/engine/Source/Core/Resource.js @@ -91,7 +91,7 @@ const xhrBlobSupported = (function () { * }); */ function Resource(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; if (typeof options === "string") { options = { url: options, @@ -118,7 +118,7 @@ function Resource(options) { * * @type {Request} */ - this.request = defaultValue(options.request, new Request()); + this.request = options.request ?? new Request(); /** * A proxy to be used when loading the resource. @@ -139,10 +139,10 @@ function Resource(options) { * * @type {number} */ - this.retryAttempts = defaultValue(options.retryAttempts, 0); + this.retryAttempts = options.retryAttempts ?? 0; this._retryCount = 0; - const parseUrl = defaultValue(options.parseUrl, true); + const parseUrl = options.parseUrl ?? true; if (parseUrl) { this.parseUrl(options.url, true, true); } else { @@ -664,7 +664,7 @@ Resource.prototype.getDerivedResource = function (options) { resource._retryCount = 0; if (defined(options.url)) { - const preserveQuery = defaultValue(options.preserveQueryParameters, false); + const preserveQuery = options.preserveQueryParameters ?? false; resource.parseUrl(options.url, true, preserveQuery, this._url); } @@ -897,14 +897,11 @@ Resource.fetchBlob = function (options) { * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ Resource.prototype.fetchImage = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const preferImageBitmap = defaultValue(options.preferImageBitmap, false); - const preferBlob = defaultValue(options.preferBlob, false); - const flipY = defaultValue(options.flipY, false); - const skipColorSpaceConversion = defaultValue( - options.skipColorSpaceConversion, - false, - ); + options = options ?? defaultValue.EMPTY_OBJECT; + const preferImageBitmap = options.preferImageBitmap ?? false; + const preferBlob = options.preferBlob ?? false; + const flipY = options.flipY ?? false; + const skipColorSpaceConversion = options.skipColorSpaceConversion ?? false; checkAndResetRequest(this.request); // We try to load the image normally if @@ -1270,7 +1267,7 @@ Resource.fetchXML = function (options) { * @see {@link http://wiki.commonjs.org/wiki/Promises/A|CommonJS Promises/A} */ Resource.prototype.fetchJsonp = function (callbackParameterName) { - callbackParameterName = defaultValue(callbackParameterName, "callback"); + callbackParameterName = callbackParameterName ?? "callback"; checkAndResetRequest(this.request); @@ -1461,7 +1458,7 @@ function decodeDataUriArrayBuffer(isBase64, data) { } function decodeDataUri(dataUriRegexResult, responseType) { - responseType = defaultValue(responseType, ""); + responseType = responseType ?? ""; const mimeType = dataUriRegexResult[1]; const isBase64 = !!dataUriRegexResult[2]; const data = dataUriRegexResult[3]; diff --git a/packages/engine/Source/Core/S2Cell.js b/packages/engine/Source/Core/S2Cell.js index 5b3a0dc31fd9..c721cbb23af4 100644 --- a/packages/engine/Source/Core/S2Cell.js +++ b/packages/engine/Source/Core/S2Cell.js @@ -2,7 +2,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -382,7 +381,7 @@ S2Cell.prototype.getParentAtLevel = function (level) { * @private */ S2Cell.prototype.getCenter = function (ellipsoid) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); + ellipsoid = ellipsoid ?? Ellipsoid.WGS84; let center = getS2Center(this._cellId, this._level); // Normalize XYZ. @@ -411,7 +410,7 @@ S2Cell.prototype.getVertex = function (index, ellipsoid) { } //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); + ellipsoid = ellipsoid ?? Ellipsoid.WGS84; let vertex = getS2Vertex(this._cellId, this._level, index); // Normalize XYZ. diff --git a/packages/engine/Source/Core/ScreenSpaceEventHandler.js b/packages/engine/Source/Core/ScreenSpaceEventHandler.js index 23d7a837ff8e..eef1725fb547 100644 --- a/packages/engine/Source/Core/ScreenSpaceEventHandler.js +++ b/packages/engine/Source/Core/ScreenSpaceEventHandler.js @@ -1,6 +1,5 @@ import AssociativeArray from "./AssociativeArray.js"; import Cartesian2 from "./Cartesian2.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import destroyObject from "./destroyObject.js"; import DeveloperError from "./DeveloperError.js"; @@ -1007,7 +1006,7 @@ function ScreenSpaceEventHandler(element) { this._clickPixelTolerance = 5; this._holdPixelTolerance = 25; - this._element = defaultValue(element, document); + this._element = element ?? document; registerListeners(this); } diff --git a/packages/engine/Source/Core/ShowGeometryInstanceAttribute.js b/packages/engine/Source/Core/ShowGeometryInstanceAttribute.js index ddef78ca7af9..197d65a5b281 100644 --- a/packages/engine/Source/Core/ShowGeometryInstanceAttribute.js +++ b/packages/engine/Source/Core/ShowGeometryInstanceAttribute.js @@ -1,5 +1,4 @@ import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -31,7 +30,7 @@ import DeveloperError from "./DeveloperError.js"; * @see GeometryInstanceAttribute */ function ShowGeometryInstanceAttribute(show) { - show = defaultValue(show, true); + show = show ?? true; /** * The values for the attributes stored in a typed array. diff --git a/packages/engine/Source/Core/SimplePolylineGeometry.js b/packages/engine/Source/Core/SimplePolylineGeometry.js index 355b4ef8f7ea..6558a9019278 100644 --- a/packages/engine/Source/Core/SimplePolylineGeometry.js +++ b/packages/engine/Source/Core/SimplePolylineGeometry.js @@ -87,10 +87,10 @@ function interpolateColors(p0, p1, color0, color1, minDistance, array, offset) { * const geometry = Cesium.SimplePolylineGeometry.createGeometry(polyline); */ function SimplePolylineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; const colors = options.colors; - const colorsPerVertex = defaultValue(options.colorsPerVertex, false); + const colorsPerVertex = options.colorsPerVertex ?? false; //>>includeStart('debug', pragmas.debug); if (!defined(positions) || positions.length < 2) { @@ -109,12 +109,9 @@ function SimplePolylineGeometry(options) { this._colors = colors; this._colorsPerVertex = colorsPerVertex; - this._arcType = defaultValue(options.arcType, ArcType.GEODESIC); - this._granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + this._arcType = options.arcType ?? ArcType.GEODESIC; + this._granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + this._ellipsoid = options.ellipsoid ?? Ellipsoid.default; this._workerName = "createSimplePolylineGeometry"; let numComponents = 1 + positions.length * Cartesian3.packedLength; @@ -146,7 +143,7 @@ SimplePolylineGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -191,7 +188,7 @@ SimplePolylineGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; diff --git a/packages/engine/Source/Core/SphereGeometry.js b/packages/engine/Source/Core/SphereGeometry.js index c01eff6abc76..e8e9b03c1592 100644 --- a/packages/engine/Source/Core/SphereGeometry.js +++ b/packages/engine/Source/Core/SphereGeometry.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import EllipsoidGeometry from "./EllipsoidGeometry.js"; import VertexFormat from "./VertexFormat.js"; @@ -30,7 +29,7 @@ import VertexFormat from "./VertexFormat.js"; * const geometry = Cesium.SphereGeometry.createGeometry(sphere); */ function SphereGeometry(options) { - const radius = defaultValue(options.radius, 1.0); + const radius = options.radius ?? 1.0; const radii = new Cartesian3(radius, radius, radius); const ellipsoidOptions = { radii: radii, diff --git a/packages/engine/Source/Core/SphereOutlineGeometry.js b/packages/engine/Source/Core/SphereOutlineGeometry.js index 62e4374acef7..5c328ff63813 100644 --- a/packages/engine/Source/Core/SphereOutlineGeometry.js +++ b/packages/engine/Source/Core/SphereOutlineGeometry.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import EllipsoidOutlineGeometry from "./EllipsoidOutlineGeometry.js"; @@ -29,7 +28,7 @@ import EllipsoidOutlineGeometry from "./EllipsoidOutlineGeometry.js"; * const geometry = Cesium.SphereOutlineGeometry.createGeometry(sphere); */ function SphereOutlineGeometry(options) { - const radius = defaultValue(options.radius, 1.0); + const radius = options.radius ?? 1.0; const radii = new Cartesian3(radius, radius, radius); const ellipsoidOptions = { radii: radii, diff --git a/packages/engine/Source/Core/Spherical.js b/packages/engine/Source/Core/Spherical.js index 57dca19407fd..8840591d0f17 100644 --- a/packages/engine/Source/Core/Spherical.js +++ b/packages/engine/Source/Core/Spherical.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; /** @@ -18,19 +17,19 @@ function Spherical(clock, cone, magnitude) { * @type {number} * @default 0.0 */ - this.clock = defaultValue(clock, 0.0); + this.clock = clock ?? 0.0; /** * The cone component. * @type {number} * @default 0.0 */ - this.cone = defaultValue(cone, 0.0); + this.cone = cone ?? 0.0; /** * The magnitude component. * @type {number} * @default 1.0 */ - this.magnitude = defaultValue(magnitude, 1.0); + this.magnitude = magnitude ?? 1.0; } /** @@ -131,7 +130,7 @@ Spherical.equals = function (left, right) { * @returns {boolean} true if the first spherical is within the provided epsilon of the second spherical, false otherwise. */ Spherical.equalsEpsilon = function (left, right, epsilon) { - epsilon = defaultValue(epsilon, 0.0); + epsilon = epsilon ?? 0.0; return ( left === right || (defined(left) && diff --git a/packages/engine/Source/Core/Spline.js b/packages/engine/Source/Core/Spline.js index b268ac0076e8..3d7086a824dc 100644 --- a/packages/engine/Source/Core/Spline.js +++ b/packages/engine/Source/Core/Spline.js @@ -1,7 +1,6 @@ import Cartesian3 from "./Cartesian3.js"; import Check from "./Check.js"; import CesiumMath from "./Math.js"; -import defaultValue from "./defaultValue.js"; import DeveloperError from "./DeveloperError.js"; import Quaternion from "./Quaternion.js"; @@ -104,7 +103,7 @@ Spline.prototype.findTimeInterval = function (time, startIndex) { // Take advantage of temporal coherence by checking current, next and previous intervals // for containment of time. - startIndex = defaultValue(startIndex, 0); + startIndex = startIndex ?? 0; if (time >= times[startIndex]) { if (startIndex + 1 < length && time < times[startIndex + 1]) { diff --git a/packages/engine/Source/Core/SteppedSpline.js b/packages/engine/Source/Core/SteppedSpline.js index cbcfcc72c4e5..f8d9f6a76975 100644 --- a/packages/engine/Source/Core/SteppedSpline.js +++ b/packages/engine/Source/Core/SteppedSpline.js @@ -39,7 +39,7 @@ import Spline from "./Spline.js"; * @see MorphWeightSpline */ function SteppedSpline(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const points = options.points; const times = options.times; diff --git a/packages/engine/Source/Core/TaskProcessor.js b/packages/engine/Source/Core/TaskProcessor.js index 760a6921b03a..34adf5695606 100644 --- a/packages/engine/Source/Core/TaskProcessor.js +++ b/packages/engine/Source/Core/TaskProcessor.js @@ -1,6 +1,5 @@ import Uri from "urijs"; import buildModuleUrl from "./buildModuleUrl.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import destroyObject from "./destroyObject.js"; import DeveloperError from "./DeveloperError.js"; @@ -13,10 +12,7 @@ import RuntimeError from "./RuntimeError.js"; function canTransferArrayBuffer() { if (!defined(TaskProcessor._canTransferArrayBuffer)) { const worker = createWorker("transferTypedArrayTest"); - worker.postMessage = defaultValue( - worker.webkitPostMessage, - worker.postMessage, - ); + worker.postMessage = worker.webkitPostMessage ?? worker.postMessage; const value = 99; const array = new Int8Array([value]); @@ -184,10 +180,7 @@ async function getWebAssemblyLoaderConfig(processor, wasmOptions) { */ function TaskProcessor(workerPath, maximumActiveTasks) { this._workerPath = workerPath; - this._maximumActiveTasks = defaultValue( - maximumActiveTasks, - Number.POSITIVE_INFINITY, - ); + this._maximumActiveTasks = maximumActiveTasks ?? Number.POSITIVE_INFINITY; this._activeTasks = 0; this._nextID = 0; this._webAssemblyPromise = undefined; diff --git a/packages/engine/Source/Core/TerrainEncoding.js b/packages/engine/Source/Core/TerrainEncoding.js index f24e08b018e6..69d5455e508d 100644 --- a/packages/engine/Source/Core/TerrainEncoding.js +++ b/packages/engine/Source/Core/TerrainEncoding.js @@ -2,7 +2,6 @@ import AttributeCompression from "./AttributeCompression.js"; import Cartesian2 from "./Cartesian2.js"; import Cartesian3 from "./Cartesian3.js"; import ComponentDatatype from "./ComponentDatatype.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import CesiumMath from "./Math.js"; import Matrix4 from "./Matrix4.js"; @@ -157,30 +156,24 @@ function TerrainEncoding( * The terrain mesh contains a vertical texture coordinate following the Web Mercator projection. * @type {boolean} */ - this.hasWebMercatorT = defaultValue(hasWebMercatorT, false); + this.hasWebMercatorT = hasWebMercatorT ?? false; /** * The terrain mesh contains geodetic surface normals, used for terrain exaggeration. * @type {boolean} */ - this.hasGeodeticSurfaceNormals = defaultValue( - hasGeodeticSurfaceNormals, - false, - ); + this.hasGeodeticSurfaceNormals = hasGeodeticSurfaceNormals ?? false; /** * A scalar used to exaggerate terrain. * @type {number} */ - this.exaggeration = defaultValue(exaggeration, 1.0); + this.exaggeration = exaggeration ?? 1.0; /** * The relative height from which terrain is exaggerated. */ - this.exaggerationRelativeHeight = defaultValue( - exaggerationRelativeHeight, - 0.0, - ); + this.exaggerationRelativeHeight = exaggerationRelativeHeight ?? 0.0; /** * The number of components in each vertex. This value can differ with different quantizations. diff --git a/packages/engine/Source/Core/TerrainMesh.js b/packages/engine/Source/Core/TerrainMesh.js index 462947d42822..68e827d1c266 100644 --- a/packages/engine/Source/Core/TerrainMesh.js +++ b/packages/engine/Source/Core/TerrainMesh.js @@ -1,5 +1,3 @@ -import defaultValue from "./defaultValue.js"; - /** * A mesh plus related metadata for a single tile of terrain. Instances of this type are * usually created from raw {@link TerrainData}. @@ -71,7 +69,7 @@ function TerrainMesh( * may be higher. * @type {number} */ - this.stride = defaultValue(vertexStride, 6); + this.stride = vertexStride ?? 6; /** * The indices describing how the vertices are connected to form triangles. diff --git a/packages/engine/Source/Core/TileProviderError.js b/packages/engine/Source/Core/TileProviderError.js index f549689e47c9..218749f06978 100644 --- a/packages/engine/Source/Core/TileProviderError.js +++ b/packages/engine/Source/Core/TileProviderError.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import formatError from "./formatError.js"; @@ -66,7 +65,7 @@ function TileProviderError( * @type {number} * @default 0 */ - this.timesRetried = defaultValue(timesRetried, 0); + this.timesRetried = timesRetried ?? 0; /** * True if the failed operation should be retried; otherwise, false. The imagery or terrain provider diff --git a/packages/engine/Source/Core/TimeInterval.js b/packages/engine/Source/Core/TimeInterval.js index 03b0a19f0840..396c9f988cc9 100644 --- a/packages/engine/Source/Core/TimeInterval.js +++ b/packages/engine/Source/Core/TimeInterval.js @@ -58,7 +58,7 @@ import JulianDate from "./JulianDate.js"; * const containsDate = Cesium.TimeInterval.contains(timeInterval, dateToCheck); */ function TimeInterval(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * Gets or sets the start time of this interval. * @type {JulianDate} @@ -86,14 +86,14 @@ function TimeInterval(options) { * @type {boolean} * @default true */ - this.isStartIncluded = defaultValue(options.isStartIncluded, true); + this.isStartIncluded = options.isStartIncluded ?? true; /** * Gets or sets whether or not the stop time is included in this interval. * @type {boolean} * @default true */ - this.isStopIncluded = defaultValue(options.isStopIncluded, true); + this.isStopIncluded = options.isStopIncluded ?? true; } Object.defineProperties(TimeInterval.prototype, { @@ -150,8 +150,8 @@ TimeInterval.fromIso8601 = function (options, result) { } const start = JulianDate.fromIso8601(dates[0]); const stop = JulianDate.fromIso8601(dates[1]); - const isStartIncluded = defaultValue(options.isStartIncluded, true); - const isStopIncluded = defaultValue(options.isStopIncluded, true); + const isStartIncluded = options.isStartIncluded ?? true; + const isStopIncluded = options.isStopIncluded ?? true; const data = options.data; if (!defined(result)) { @@ -247,7 +247,7 @@ TimeInterval.equals = function (left, right, dataComparer) { * @returns {boolean} true if the two dates are within epsilon seconds of each other; otherwise false. */ TimeInterval.equalsEpsilon = function (left, right, epsilon, dataComparer) { - epsilon = defaultValue(epsilon, 0); + epsilon = epsilon ?? 0; return ( left === right || diff --git a/packages/engine/Source/Core/TimeIntervalCollection.js b/packages/engine/Source/Core/TimeIntervalCollection.js index 36af68c8dec9..5449170d6296 100644 --- a/packages/engine/Source/Core/TimeIntervalCollection.js +++ b/packages/engine/Source/Core/TimeIntervalCollection.js @@ -277,7 +277,7 @@ TimeIntervalCollection.prototype.indexOf = function (date) { * @returns {TimeInterval|undefined} The first interval in the collection that matches the specified parameters. */ TimeIntervalCollection.prototype.findInterval = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const start = options.start; const stop = options.stop; const isStartIncluded = options.isStartIncluded; @@ -759,10 +759,10 @@ TimeIntervalCollection.fromJulianDateArray = function (options, result) { const length = julianDates.length; const dataCallback = options.dataCallback; - const isStartIncluded = defaultValue(options.isStartIncluded, true); - const isStopIncluded = defaultValue(options.isStopIncluded, true); - const leadingInterval = defaultValue(options.leadingInterval, false); - const trailingInterval = defaultValue(options.trailingInterval, false); + const isStartIncluded = options.isStartIncluded ?? true; + const isStopIncluded = options.isStopIncluded ?? true; + const leadingInterval = options.leadingInterval ?? false; + const trailingInterval = options.trailingInterval ?? false; let interval; // Add a default interval, which will only end up being used up to first interval @@ -1104,7 +1104,7 @@ TimeIntervalCollection.fromIso8601DurationArray = function (options, result) { const epoch = options.epoch; const iso8601Durations = options.iso8601Durations; - const relativeToPrevious = defaultValue(options.relativeToPrevious, false); + const relativeToPrevious = options.relativeToPrevious ?? false; const julianDates = []; let date, previousDate; diff --git a/packages/engine/Source/Core/Tipsify.js b/packages/engine/Source/Core/Tipsify.js index 43c0a831dbf6..61d6fcdae9ac 100644 --- a/packages/engine/Source/Core/Tipsify.js +++ b/packages/engine/Source/Core/Tipsify.js @@ -39,10 +39,10 @@ const Tipsify = {}; * const acmr = Cesium.Tipsify.calculateACMR({indices : indices, maxIndex : maxIndex, cacheSize : cacheSize}); */ Tipsify.calculateACMR = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const indices = options.indices; let maximumIndex = options.maximumIndex; - const cacheSize = defaultValue(options.cacheSize, 24); + const cacheSize = options.cacheSize ?? 24; //>>includeStart('debug', pragmas.debug); if (!defined(indices)) { @@ -117,10 +117,10 @@ Tipsify.calculateACMR = function (options) { * const reorderedIndices = Cesium.Tipsify.tipsify({indices : indices, maxIndex : maxIndex, cacheSize : cacheSize}); */ Tipsify.tipsify = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const indices = options.indices; const maximumIndex = options.maximumIndex; - const cacheSize = defaultValue(options.cacheSize, 24); + const cacheSize = options.cacheSize ?? 24; let cursor; diff --git a/packages/engine/Source/Core/Transforms.js b/packages/engine/Source/Core/Transforms.js index 9aad9ff17ef1..aed56e16a3a5 100644 --- a/packages/engine/Source/Core/Transforms.js +++ b/packages/engine/Source/Core/Transforms.js @@ -3,7 +3,6 @@ import Cartesian3 from "./Cartesian3.js"; import Cartesian4 from "./Cartesian4.js"; import Cartographic from "./Cartographic.js"; import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import EarthOrientationParameters from "./EarthOrientationParameters.js"; @@ -199,7 +198,7 @@ Transforms.localFrameToFixedFrameGenerator = function (firstAxis, secondAxis) { ); } } else { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; ellipsoid.geodeticSurfaceNormal(origin, scratchCalculateCartesian.up); const up = scratchCalculateCartesian.up; @@ -393,10 +392,8 @@ Transforms.headingPitchRollToFixedFrame = function ( Check.typeOf.object("HeadingPitchRoll", headingPitchRoll); //>>includeEnd('debug'); - fixedFrameTransform = defaultValue( - fixedFrameTransform, - Transforms.eastNorthUpToFixedFrame, - ); + fixedFrameTransform = + fixedFrameTransform ?? Transforms.eastNorthUpToFixedFrame; const hprQuaternion = Quaternion.fromHeadingPitchRoll( headingPitchRoll, scratchHPRQuaternion, @@ -487,11 +484,9 @@ Transforms.fixedFrameToHeadingPitchRoll = function ( Check.defined("transform", transform); //>>includeEnd('debug'); - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); - fixedFrameTransform = defaultValue( - fixedFrameTransform, - Transforms.eastNorthUpToFixedFrame, - ); + ellipsoid = ellipsoid ?? Ellipsoid.default; + fixedFrameTransform = + fixedFrameTransform ?? Transforms.eastNorthUpToFixedFrame; if (!defined(result)) { result = new HeadingPitchRoll(); } @@ -1103,10 +1098,11 @@ Transforms.rotationMatrixFromPositionVelocity = function ( } //>>includeEnd('debug'); - const normal = defaultValue( - ellipsoid, - Ellipsoid.default, - ).geodeticSurfaceNormal(position, normalScratch); + const normal = (ellipsoid ?? Ellipsoid.default).geodeticSurfaceNormal( + position, + normalScratch, + ); + let right = Cartesian3.cross(velocity, normal, rightScratch); if (Cartesian3.equalsEpsilon(right, Cartesian3.ZERO, CesiumMath.EPSILON6)) { diff --git a/packages/engine/Source/Core/TranslationRotationScale.js b/packages/engine/Source/Core/TranslationRotationScale.js index 16047008bc6f..508cebdee9dc 100644 --- a/packages/engine/Source/Core/TranslationRotationScale.js +++ b/packages/engine/Source/Core/TranslationRotationScale.js @@ -1,5 +1,4 @@ import Cartesian3 from "./Cartesian3.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Quaternion from "./Quaternion.js"; @@ -22,23 +21,21 @@ function TranslationRotationScale(translation, rotation, scale) { * @type {Cartesian3} * @default Cartesian3.ZERO */ - this.translation = Cartesian3.clone( - defaultValue(translation, defaultTranslation), - ); + this.translation = Cartesian3.clone(translation ?? defaultTranslation); /** * Gets or sets the (x, y, z, w) rotation to apply to the node. * @type {Quaternion} * @default Quaternion.IDENTITY */ - this.rotation = Quaternion.clone(defaultValue(rotation, defaultRotation)); + this.rotation = Quaternion.clone(rotation ?? defaultRotation); /** * Gets or sets the (x, y, z) scaling to apply to the node. * @type {Cartesian3} * @default new Cartesian3(1.0, 1.0, 1.0) */ - this.scale = Cartesian3.clone(defaultValue(scale, defaultScale)); + this.scale = Cartesian3.clone(scale ?? defaultScale); } /** diff --git a/packages/engine/Source/Core/VRTheWorldTerrainProvider.js b/packages/engine/Source/Core/VRTheWorldTerrainProvider.js index c25b7312202a..060b272a62e4 100644 --- a/packages/engine/Source/Core/VRTheWorldTerrainProvider.js +++ b/packages/engine/Source/Core/VRTheWorldTerrainProvider.js @@ -37,7 +37,7 @@ function DataRectangle(rectangle, maxLevel) { * @param {VRTheWorldTerrainProvider.ConstructorOptions} options An object describing initialization options */ function TerrainProviderBuilder(options) { - this.ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + this.ellipsoid = options.ellipsoid ?? Ellipsoid.default; this.tilingScheme = undefined; this.heightmapWidth = undefined; this.heightmapHeight = undefined; @@ -156,7 +156,7 @@ async function requestMetadata(terrainProviderBuilder, resource, provider) { * @see TerrainProvider */ function VRTheWorldTerrainProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._errorEvent = new Event(); @@ -282,7 +282,7 @@ VRTheWorldTerrainProvider.fromUrl = async function (url, options) { Check.defined("url", url); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const terrainProviderBuilder = new TerrainProviderBuilder(options); const resource = Resource.createIfNeeded(url); diff --git a/packages/engine/Source/Core/VertexFormat.js b/packages/engine/Source/Core/VertexFormat.js index b1fd436fb0d3..f2da60b57c99 100644 --- a/packages/engine/Source/Core/VertexFormat.js +++ b/packages/engine/Source/Core/VertexFormat.js @@ -23,7 +23,7 @@ import DeveloperError from "./DeveloperError.js"; * @see Packable */ function VertexFormat(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * When true, the vertex has a 3D position attribute. @@ -35,7 +35,7 @@ function VertexFormat(options) { * * @default false */ - this.position = defaultValue(options.position, false); + this.position = options.position ?? false; /** * When true, the vertex has a normal attribute (normalized), which is commonly used for lighting. @@ -47,7 +47,7 @@ function VertexFormat(options) { * * @default false */ - this.normal = defaultValue(options.normal, false); + this.normal = options.normal ?? false; /** * When true, the vertex has a 2D texture coordinate attribute. @@ -59,7 +59,7 @@ function VertexFormat(options) { * * @default false */ - this.st = defaultValue(options.st, false); + this.st = options.st ?? false; /** * When true, the vertex has a bitangent attribute (normalized), which is used for tangent-space effects like bump mapping. @@ -71,7 +71,7 @@ function VertexFormat(options) { * * @default false */ - this.bitangent = defaultValue(options.bitangent, false); + this.bitangent = options.bitangent ?? false; /** * When true, the vertex has a tangent attribute (normalized), which is used for tangent-space effects like bump mapping. @@ -83,7 +83,7 @@ function VertexFormat(options) { * * @default false */ - this.tangent = defaultValue(options.tangent, false); + this.tangent = options.tangent ?? false; /** * When true, the vertex has an RGB color attribute. @@ -95,7 +95,7 @@ function VertexFormat(options) { * * @default false */ - this.color = defaultValue(options.color, false); + this.color = options.color ?? false; } /** @@ -243,7 +243,7 @@ VertexFormat.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex++] = value.position ? 1.0 : 0.0; array[startingIndex++] = value.normal ? 1.0 : 0.0; @@ -270,7 +270,7 @@ VertexFormat.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; if (!defined(result)) { result = new VertexFormat(); diff --git a/packages/engine/Source/Core/VideoSynchronizer.js b/packages/engine/Source/Core/VideoSynchronizer.js index eb2e165cef17..f42d6a2750e1 100644 --- a/packages/engine/Source/Core/VideoSynchronizer.js +++ b/packages/engine/Source/Core/VideoSynchronizer.js @@ -19,7 +19,7 @@ import JulianDate from "./JulianDate.js"; * @demo {@link https://sandcastle.cesium.com/index.html?src=Video.html|Video Material Demo} */ function VideoSynchronizer(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._clock = undefined; this._element = undefined; @@ -35,7 +35,7 @@ function VideoSynchronizer(options) { * @type {JulianDate} * @default Iso8601.MINIMUM_VALUE */ - this.epoch = defaultValue(options.epoch, Iso8601.MINIMUM_VALUE); + this.epoch = options.epoch ?? Iso8601.MINIMUM_VALUE; /** * Gets or sets the amount of time in seconds the video's currentTime @@ -46,7 +46,7 @@ function VideoSynchronizer(options) { * @type {number} * @default 1.0 */ - this.tolerance = defaultValue(options.tolerance, 1.0); + this.tolerance = options.tolerance ?? 1.0; this._seeking = false; this._seekFunction = undefined; @@ -184,7 +184,7 @@ VideoSynchronizer.prototype._onTick = function (clock) { this._trySetPlaybackRate(clock); const clockTime = clock.currentTime; - const epoch = defaultValue(this.epoch, Iso8601.MINIMUM_VALUE); + const epoch = this.epoch ?? Iso8601.MINIMUM_VALUE; let videoTime = JulianDate.secondsDifference(clockTime, epoch); const duration = element.duration; @@ -206,7 +206,7 @@ VideoSynchronizer.prototype._onTick = function (clock) { //If the playing video's time and the scene's clock time //ever drift too far apart, we want to set the video to match - const tolerance = shouldAnimate ? defaultValue(this.tolerance, 1.0) : 0.001; + const tolerance = shouldAnimate ? (this.tolerance ?? 1.0) : 0.001; if (Math.abs(desiredTime - currentTime) > tolerance) { this._seeking = true; element.currentTime = desiredTime; diff --git a/packages/engine/Source/Core/WallGeometry.js b/packages/engine/Source/Core/WallGeometry.js index 2f713ed2c3cc..a5c5fa62ed37 100644 --- a/packages/engine/Source/Core/WallGeometry.js +++ b/packages/engine/Source/Core/WallGeometry.js @@ -62,7 +62,7 @@ const scratchNormal = new Cartesian3(); * const geometry = Cesium.WallGeometry.createGeometry(wall); */ function WallGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const wallPositions = options.positions; const maximumHeights = options.maximumHeights; @@ -90,12 +90,9 @@ function WallGeometry(options) { } //>>includeEnd('debug'); - const vertexFormat = defaultValue(options.vertexFormat, VertexFormat.DEFAULT); - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + const vertexFormat = options.vertexFormat ?? VertexFormat.DEFAULT; + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; this._positions = wallPositions; this._minimumHeights = minimumHeights; @@ -140,7 +137,7 @@ WallGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -209,7 +206,7 @@ WallGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -303,7 +300,7 @@ WallGeometry.unpack = function (array, startingIndex, result) { * @see WallGeometry#createGeometry */ WallGeometry.fromConstantHeights = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Core/WallOutlineGeometry.js b/packages/engine/Source/Core/WallOutlineGeometry.js index e3a3ff850c1a..4442c57cf642 100644 --- a/packages/engine/Source/Core/WallOutlineGeometry.js +++ b/packages/engine/Source/Core/WallOutlineGeometry.js @@ -53,7 +53,7 @@ const scratchCartesian3Position2 = new Cartesian3(); * const geometry = Cesium.WallOutlineGeometry.createGeometry(wall); */ function WallOutlineGeometry(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const wallPositions = options.positions; const maximumHeights = options.maximumHeights; @@ -81,11 +81,8 @@ function WallOutlineGeometry(options) { } //>>includeEnd('debug'); - const granularity = defaultValue( - options.granularity, - CesiumMath.RADIANS_PER_DEGREE, - ); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + const granularity = options.granularity ?? CesiumMath.RADIANS_PER_DEGREE; + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; this._positions = wallPositions; this._minimumHeights = minimumHeights; @@ -128,7 +125,7 @@ WallOutlineGeometry.pack = function (value, array, startingIndex) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -192,7 +189,7 @@ WallOutlineGeometry.unpack = function (array, startingIndex, result) { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; let i; @@ -277,7 +274,7 @@ WallOutlineGeometry.unpack = function (array, startingIndex, result) { * @see WallOutlineGeometry#createGeometry */ WallOutlineGeometry.fromConstantHeights = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const positions = options.positions; //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Core/WebMercatorProjection.js b/packages/engine/Source/Core/WebMercatorProjection.js index 335eaa54697a..866bdf07e3ca 100644 --- a/packages/engine/Source/Core/WebMercatorProjection.js +++ b/packages/engine/Source/Core/WebMercatorProjection.js @@ -1,6 +1,5 @@ import Cartesian3 from "./Cartesian3.js"; import Cartographic from "./Cartographic.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import Ellipsoid from "./Ellipsoid.js"; @@ -19,7 +18,7 @@ import CesiumMath from "./Math.js"; * @see GeographicProjection */ function WebMercatorProjection(ellipsoid) { - this._ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = ellipsoid ?? Ellipsoid.WGS84; this._semimajorAxis = this._ellipsoid.maximumRadius; this._oneOverSemimajorAxis = 1.0 / this._semimajorAxis; } diff --git a/packages/engine/Source/Core/WebMercatorTilingScheme.js b/packages/engine/Source/Core/WebMercatorTilingScheme.js index f7a81610d418..ee30e31feca1 100644 --- a/packages/engine/Source/Core/WebMercatorTilingScheme.js +++ b/packages/engine/Source/Core/WebMercatorTilingScheme.js @@ -29,17 +29,11 @@ import WebMercatorProjection from "./WebMercatorProjection.js"; * direction, resulting in a square projection. */ function WebMercatorTilingScheme(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); - this._numberOfLevelZeroTilesX = defaultValue( - options.numberOfLevelZeroTilesX, - 1, - ); - this._numberOfLevelZeroTilesY = defaultValue( - options.numberOfLevelZeroTilesY, - 1, - ); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.default; + this._numberOfLevelZeroTilesX = options.numberOfLevelZeroTilesX ?? 1; + this._numberOfLevelZeroTilesY = options.numberOfLevelZeroTilesY ?? 1; this._projection = new WebMercatorProjection(this._ellipsoid); diff --git a/packages/engine/Source/Core/arrayRemoveDuplicates.js b/packages/engine/Source/Core/arrayRemoveDuplicates.js index e77b3aa871be..30fcf6371783 100644 --- a/packages/engine/Source/Core/arrayRemoveDuplicates.js +++ b/packages/engine/Source/Core/arrayRemoveDuplicates.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import CesiumMath from "./Math.js"; @@ -61,7 +60,7 @@ function arrayRemoveDuplicates( return undefined; } - wrapAround = defaultValue(wrapAround, false); + wrapAround = wrapAround ?? false; const storeRemovedIndices = defined(removedIndices); const length = values.length; diff --git a/packages/engine/Source/Core/clone.js b/packages/engine/Source/Core/clone.js index f366c04b1826..0e2365832e58 100644 --- a/packages/engine/Source/Core/clone.js +++ b/packages/engine/Source/Core/clone.js @@ -1,5 +1,3 @@ -import defaultValue from "./defaultValue.js"; - /** * Clones an object, returning a new object containing the same properties. * @@ -14,7 +12,7 @@ function clone(object, deep) { return object; } - deep = defaultValue(deep, false); + deep = deep ?? false; const result = new object.constructor(); for (const propertyName in object) { diff --git a/packages/engine/Source/Core/combine.js b/packages/engine/Source/Core/combine.js index 98d5cf74c6d0..75ea5bca65d0 100644 --- a/packages/engine/Source/Core/combine.js +++ b/packages/engine/Source/Core/combine.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; /** @@ -33,7 +32,7 @@ import defined from "./defined.js"; * @function */ function combine(object1, object2, deep) { - deep = defaultValue(deep, false); + deep = deep ?? false; const result = {}; diff --git a/packages/engine/Source/Core/createWorldBathymetryAsync.js b/packages/engine/Source/Core/createWorldBathymetryAsync.js index b01fa3626571..a6bd72a872ea 100644 --- a/packages/engine/Source/Core/createWorldBathymetryAsync.js +++ b/packages/engine/Source/Core/createWorldBathymetryAsync.js @@ -36,10 +36,10 @@ import defaultValue from "./defaultValue.js"; * */ function createWorldBathymetryAsync(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; return CesiumTerrainProvider.fromIonAssetId(2426648, { - requestVertexNormals: defaultValue(options.requestVertexNormals, false), + requestVertexNormals: options.requestVertexNormals ?? false, }); } export default createWorldBathymetryAsync; diff --git a/packages/engine/Source/Core/createWorldTerrainAsync.js b/packages/engine/Source/Core/createWorldTerrainAsync.js index a251af66f982..303cdd331e52 100644 --- a/packages/engine/Source/Core/createWorldTerrainAsync.js +++ b/packages/engine/Source/Core/createWorldTerrainAsync.js @@ -39,11 +39,11 @@ import Ellipsoid from "./Ellipsoid.js"; * */ function createWorldTerrainAsync(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; return CesiumTerrainProvider.fromIonAssetId(1, { - requestVertexNormals: defaultValue(options.requestVertexNormals, false), - requestWaterMask: defaultValue(options.requestWaterMask, false), + requestVertexNormals: options.requestVertexNormals ?? false, + requestWaterMask: options.requestWaterMask ?? false, ellipsoid: Ellipsoid.WGS84, }); } diff --git a/packages/engine/Source/Core/destroyObject.js b/packages/engine/Source/Core/destroyObject.js index f51c63030298..bf9bf0153a69 100644 --- a/packages/engine/Source/Core/destroyObject.js +++ b/packages/engine/Source/Core/destroyObject.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import DeveloperError from "./DeveloperError.js"; function returnTrue() { @@ -33,10 +32,7 @@ function returnTrue() { * @see DeveloperError */ function destroyObject(object, message) { - message = defaultValue( - message, - "This object was destroyed, i.e., destroy() was called.", - ); + message = message ?? "This object was destroyed, i.e., destroy() was called."; function throwOnDestroyed() { //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Core/getAbsoluteUri.js b/packages/engine/Source/Core/getAbsoluteUri.js index 63f5e7cb9d92..3818b0de6ad2 100644 --- a/packages/engine/Source/Core/getAbsoluteUri.js +++ b/packages/engine/Source/Core/getAbsoluteUri.js @@ -1,5 +1,4 @@ import Uri from "urijs"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -35,7 +34,7 @@ getAbsoluteUri._implementation = function (relative, base, documentObject) { if (typeof documentObject === "undefined") { return relative; } - base = defaultValue(documentObject.baseURI, documentObject.location.href); + base = documentObject.baseURI ?? documentObject.location.href; } const relativeUri = new Uri(relative); diff --git a/packages/engine/Source/Core/getMagic.js b/packages/engine/Source/Core/getMagic.js index a6eeff08fe21..fe7b485f94c8 100644 --- a/packages/engine/Source/Core/getMagic.js +++ b/packages/engine/Source/Core/getMagic.js @@ -1,11 +1,10 @@ -import defaultValue from "./defaultValue.js"; import getStringFromTypedArray from "./getStringFromTypedArray.js"; /** * @private */ function getMagic(uint8Array, byteOffset) { - byteOffset = defaultValue(byteOffset, 0); + byteOffset = byteOffset ?? 0; return getStringFromTypedArray( uint8Array, byteOffset, diff --git a/packages/engine/Source/Core/getStringFromTypedArray.js b/packages/engine/Source/Core/getStringFromTypedArray.js index 2b3c04fe394b..011714f3683f 100644 --- a/packages/engine/Source/Core/getStringFromTypedArray.js +++ b/packages/engine/Source/Core/getStringFromTypedArray.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; import RuntimeError from "./RuntimeError.js"; @@ -31,8 +30,8 @@ function getStringFromTypedArray(uint8Array, byteOffset, byteLength) { } //>>includeEnd('debug'); - byteOffset = defaultValue(byteOffset, 0); - byteLength = defaultValue(byteLength, uint8Array.byteLength - byteOffset); + byteOffset = byteOffset ?? 0; + byteLength = byteLength ?? uint8Array.byteLength - byteOffset; uint8Array = uint8Array.subarray(byteOffset, byteOffset + byteLength); diff --git a/packages/engine/Source/Core/loadImageFromTypedArray.js b/packages/engine/Source/Core/loadImageFromTypedArray.js index 9907028e06e6..ad843360d5ff 100644 --- a/packages/engine/Source/Core/loadImageFromTypedArray.js +++ b/packages/engine/Source/Core/loadImageFromTypedArray.js @@ -1,5 +1,4 @@ import Check from "./Check.js"; -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import Resource from "./Resource.js"; @@ -10,11 +9,8 @@ function loadImageFromTypedArray(options) { const uint8Array = options.uint8Array; const format = options.format; const request = options.request; - const flipY = defaultValue(options.flipY, false); - const skipColorSpaceConversion = defaultValue( - options.skipColorSpaceConversion, - false, - ); + const flipY = options.flipY ?? false; + const skipColorSpaceConversion = options.skipColorSpaceConversion ?? false; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("uint8Array", uint8Array); Check.typeOf.string("format", format); diff --git a/packages/engine/Source/Core/oneTimeWarning.js b/packages/engine/Source/Core/oneTimeWarning.js index 4231bd3eae41..8315f00fb0f0 100644 --- a/packages/engine/Source/Core/oneTimeWarning.js +++ b/packages/engine/Source/Core/oneTimeWarning.js @@ -1,4 +1,3 @@ -import defaultValue from "./defaultValue.js"; import defined from "./defined.js"; import DeveloperError from "./DeveloperError.js"; @@ -35,7 +34,7 @@ function oneTimeWarning(identifier, message) { if (!defined(warnings[identifier])) { warnings[identifier] = true; - console.warn(defaultValue(message, identifier)); + console.warn(message ?? identifier); } } diff --git a/packages/engine/Source/Core/writeTextToCanvas.js b/packages/engine/Source/Core/writeTextToCanvas.js index 3a23c602d7e3..4864638c0330 100644 --- a/packages/engine/Source/Core/writeTextToCanvas.js +++ b/packages/engine/Source/Core/writeTextToCanvas.js @@ -127,16 +127,13 @@ function writeTextToCanvas(text, options) { return undefined; } - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const font = defaultValue(options.font, "10px sans-serif"); - const stroke = defaultValue(options.stroke, false); - const fill = defaultValue(options.fill, true); - const strokeWidth = defaultValue(options.strokeWidth, 1); - const backgroundColor = defaultValue( - options.backgroundColor, - Color.TRANSPARENT, - ); - const padding = defaultValue(options.padding, 0); + options = options ?? defaultValue.EMPTY_OBJECT; + const font = options.font ?? "10px sans-serif"; + const stroke = options.stroke ?? false; + const fill = options.fill ?? true; + const strokeWidth = options.strokeWidth ?? 1; + const backgroundColor = options.backgroundColor ?? Color.TRANSPARENT; + const padding = options.padding ?? 0; const doublePadding = padding * 2.0; const canvas = document.createElement("canvas"); @@ -207,13 +204,13 @@ function writeTextToCanvas(text, options) { } if (stroke) { - const strokeColor = defaultValue(options.strokeColor, Color.BLACK); + const strokeColor = options.strokeColor ?? Color.BLACK; context2D.strokeStyle = strokeColor.toCssColorString(); context2D.strokeText(text, x + padding, y); } if (fill) { - const fillColor = defaultValue(options.fillColor, Color.WHITE); + const fillColor = options.fillColor ?? Color.WHITE; context2D.fillStyle = fillColor.toCssColorString(); context2D.fillText(text, x + padding, y); } diff --git a/packages/engine/Source/DataSources/BillboardGraphics.js b/packages/engine/Source/DataSources/BillboardGraphics.js index 3145f6adb2a9..d5238f45cefd 100644 --- a/packages/engine/Source/DataSources/BillboardGraphics.js +++ b/packages/engine/Source/DataSources/BillboardGraphics.js @@ -93,7 +93,7 @@ function BillboardGraphics(options) { this._splitDirection = undefined; this._splitDirectionSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(BillboardGraphics.prototype, { @@ -390,56 +390,30 @@ BillboardGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this._show, source.show); - this.image = defaultValue(this._image, source.image); - this.scale = defaultValue(this._scale, source.scale); - this.pixelOffset = defaultValue(this._pixelOffset, source.pixelOffset); - this.eyeOffset = defaultValue(this._eyeOffset, source.eyeOffset); - this.horizontalOrigin = defaultValue( - this._horizontalOrigin, - source.horizontalOrigin, - ); - this.verticalOrigin = defaultValue( - this._verticalOrigin, - source.verticalOrigin, - ); - this.heightReference = defaultValue( - this._heightReference, - source.heightReference, - ); - this.color = defaultValue(this._color, source.color); - this.rotation = defaultValue(this._rotation, source.rotation); - this.alignedAxis = defaultValue(this._alignedAxis, source.alignedAxis); - this.sizeInMeters = defaultValue(this._sizeInMeters, source.sizeInMeters); - this.width = defaultValue(this._width, source.width); - this.height = defaultValue(this._height, source.height); - this.scaleByDistance = defaultValue( - this._scaleByDistance, - source.scaleByDistance, - ); - this.translucencyByDistance = defaultValue( - this._translucencyByDistance, - source.translucencyByDistance, - ); - this.pixelOffsetScaleByDistance = defaultValue( - this._pixelOffsetScaleByDistance, - source.pixelOffsetScaleByDistance, - ); - this.imageSubRegion = defaultValue( - this._imageSubRegion, - source.imageSubRegion, - ); - this.distanceDisplayCondition = defaultValue( - this._distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.disableDepthTestDistance = defaultValue( - this._disableDepthTestDistance, - source.disableDepthTestDistance, - ); - this.splitDirection = defaultValue( - this.splitDirection, - source.splitDirection, - ); + this.show = this._show ?? source.show; + this.image = this._image ?? source.image; + this.scale = this._scale ?? source.scale; + this.pixelOffset = this._pixelOffset ?? source.pixelOffset; + this.eyeOffset = this._eyeOffset ?? source.eyeOffset; + this.horizontalOrigin = this._horizontalOrigin ?? source.horizontalOrigin; + this.verticalOrigin = this._verticalOrigin ?? source.verticalOrigin; + this.heightReference = this._heightReference ?? source.heightReference; + this.color = this._color ?? source.color; + this.rotation = this._rotation ?? source.rotation; + this.alignedAxis = this._alignedAxis ?? source.alignedAxis; + this.sizeInMeters = this._sizeInMeters ?? source.sizeInMeters; + this.width = this._width ?? source.width; + this.height = this._height ?? source.height; + this.scaleByDistance = this._scaleByDistance ?? source.scaleByDistance; + this.translucencyByDistance = + this._translucencyByDistance ?? source.translucencyByDistance; + this.pixelOffsetScaleByDistance = + this._pixelOffsetScaleByDistance ?? source.pixelOffsetScaleByDistance; + this.imageSubRegion = this._imageSubRegion ?? source.imageSubRegion; + this.distanceDisplayCondition = + this._distanceDisplayCondition ?? source.distanceDisplayCondition; + this.disableDepthTestDistance = + this._disableDepthTestDistance ?? source.disableDepthTestDistance; + this.splitDirection = this.splitDirection ?? source.splitDirection; }; export default BillboardGraphics; diff --git a/packages/engine/Source/DataSources/BoxGraphics.js b/packages/engine/Source/DataSources/BoxGraphics.js index 05c4893a1b1c..a8e9d77838a0 100644 --- a/packages/engine/Source/DataSources/BoxGraphics.js +++ b/packages/engine/Source/DataSources/BoxGraphics.js @@ -55,8 +55,7 @@ function BoxGraphics(options) { this._shadowsSubscription = undefined; this._distanceDisplayCondition = undefined; this._distanceDisplayConditionSubscription = undefined; - - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(BoxGraphics.prototype, { @@ -193,21 +192,16 @@ BoxGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.dimensions = defaultValue(this.dimensions, source.dimensions); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); + this.show = this.show ?? source.show; + this.dimensions = this.dimensions ?? source.dimensions; + this.heightReference = this.heightReference ?? source.heightReference; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; }; export default BoxGraphics; diff --git a/packages/engine/Source/DataSources/CallbackPositionProperty.js b/packages/engine/Source/DataSources/CallbackPositionProperty.js index 7c56bd377559..99efe9eb795f 100644 --- a/packages/engine/Source/DataSources/CallbackPositionProperty.js +++ b/packages/engine/Source/DataSources/CallbackPositionProperty.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -21,7 +20,7 @@ import PositionProperty from "./PositionProperty.js"; function CallbackPositionProperty(callback, isConstant, referenceFrame) { this._callback = undefined; this._isConstant = undefined; - this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED; this._definitionChanged = new Event(); this.setCallback(callback, isConstant); } diff --git a/packages/engine/Source/DataSources/Cesium3DTilesetGraphics.js b/packages/engine/Source/DataSources/Cesium3DTilesetGraphics.js index 7535fc8518ab..43dd1ebea017 100644 --- a/packages/engine/Source/DataSources/Cesium3DTilesetGraphics.js +++ b/packages/engine/Source/DataSources/Cesium3DTilesetGraphics.js @@ -33,7 +33,7 @@ function Cesium3DTilesetGraphics(options) { this._maximumScreenSpaceError = undefined; this._maximumScreenSpaceErrorSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(Cesium3DTilesetGraphics.prototype, { @@ -102,12 +102,10 @@ Cesium3DTilesetGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.uri = defaultValue(this.uri, source.uri); - this.maximumScreenSpaceError = defaultValue( - this.maximumScreenSpaceError, - source.maximumScreenSpaceError, - ); + this.show = this.show ?? source.show; + this.uri = this.uri ?? source.uri; + this.maximumScreenSpaceError = + this.maximumScreenSpaceError ?? source.maximumScreenSpaceError; }; export default Cesium3DTilesetGraphics; diff --git a/packages/engine/Source/DataSources/CheckerboardMaterialProperty.js b/packages/engine/Source/DataSources/CheckerboardMaterialProperty.js index 0745fbb506c1..8ddf86792037 100644 --- a/packages/engine/Source/DataSources/CheckerboardMaterialProperty.js +++ b/packages/engine/Source/DataSources/CheckerboardMaterialProperty.js @@ -22,7 +22,7 @@ const defaultRepeat = new Cartesian2(2.0, 2.0); * @param {Property|Cartesian2} [options.repeat=new Cartesian2(2.0, 2.0)] A {@link Cartesian2} Property specifying how many times the tiles repeat in each direction. */ function CheckerboardMaterialProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._evenColor = undefined; diff --git a/packages/engine/Source/DataSources/CompositePositionProperty.js b/packages/engine/Source/DataSources/CompositePositionProperty.js index ff50c9e169a5..eb20e0fce51a 100644 --- a/packages/engine/Source/DataSources/CompositePositionProperty.js +++ b/packages/engine/Source/DataSources/CompositePositionProperty.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -16,7 +15,7 @@ import Property from "./Property.js"; * @param {ReferenceFrame} [referenceFrame=ReferenceFrame.FIXED] The reference frame in which the position is defined. */ function CompositePositionProperty(referenceFrame) { - this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED; this._definitionChanged = new Event(); this._composite = new CompositeProperty(); this._composite.definitionChanged.addEventListener( diff --git a/packages/engine/Source/DataSources/ConstantPositionProperty.js b/packages/engine/Source/DataSources/ConstantPositionProperty.js index 946704d563b3..3069f8750fc3 100644 --- a/packages/engine/Source/DataSources/ConstantPositionProperty.js +++ b/packages/engine/Source/DataSources/ConstantPositionProperty.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -20,7 +19,7 @@ import PositionProperty from "./PositionProperty.js"; function ConstantPositionProperty(value, referenceFrame) { this._definitionChanged = new Event(); this._value = Cartesian3.clone(value); - this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED; } Object.defineProperties(ConstantPositionProperty.prototype, { diff --git a/packages/engine/Source/DataSources/CorridorGraphics.js b/packages/engine/Source/DataSources/CorridorGraphics.js index eefe7567d8ff..dc33b2c1b204 100644 --- a/packages/engine/Source/DataSources/CorridorGraphics.js +++ b/packages/engine/Source/DataSources/CorridorGraphics.js @@ -82,7 +82,7 @@ function CorridorGraphics(options) { this._zIndex = undefined; this._zIndexSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(CorridorGraphics.prototype, { @@ -291,38 +291,26 @@ CorridorGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.positions = defaultValue(this.positions, source.positions); - this.width = defaultValue(this.width, source.width); - this.height = defaultValue(this.height, source.height); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.extrudedHeight = defaultValue( - this.extrudedHeight, - source.extrudedHeight, - ); - this.extrudedHeightReference = defaultValue( - this.extrudedHeightReference, - source.extrudedHeightReference, - ); - this.cornerType = defaultValue(this.cornerType, source.cornerType); - this.granularity = defaultValue(this.granularity, source.granularity); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.classificationType = defaultValue( - this.classificationType, - source.classificationType, - ); - this.zIndex = defaultValue(this.zIndex, source.zIndex); + this.show = this.show ?? source.show; + this.positions = this.positions ?? source.positions; + this.width = this.width ?? source.width; + this.height = this.height ?? source.height; + this.heightReference = this.heightReference ?? source.heightReference; + this.extrudedHeight = this.extrudedHeight ?? source.extrudedHeight; + this.extrudedHeightReference = + this.extrudedHeightReference ?? source.extrudedHeightReference; + this.cornerType = this.cornerType ?? source.cornerType; + this.granularity = this.granularity ?? source.granularity; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; + this.classificationType = + this.classificationType ?? source.classificationType; + this.zIndex = this.zIndex ?? source.zIndex; }; export default CorridorGraphics; diff --git a/packages/engine/Source/DataSources/CylinderGraphics.js b/packages/engine/Source/DataSources/CylinderGraphics.js index 370e778a4e5d..e8d44be133da 100644 --- a/packages/engine/Source/DataSources/CylinderGraphics.js +++ b/packages/engine/Source/DataSources/CylinderGraphics.js @@ -66,7 +66,7 @@ function CylinderGraphics(options) { this._distanceDisplayCondition = undefined; this._distanceDisplayConditionSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(CylinderGraphics.prototype, { @@ -238,28 +238,21 @@ CylinderGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.length = defaultValue(this.length, source.length); - this.topRadius = defaultValue(this.topRadius, source.topRadius); - this.bottomRadius = defaultValue(this.bottomRadius, source.bottomRadius); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.numberOfVerticalLines = defaultValue( - this.numberOfVerticalLines, - source.numberOfVerticalLines, - ); - this.slices = defaultValue(this.slices, source.slices); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); + this.show = this.show ?? source.show; + this.length = this.length ?? source.length; + this.topRadius = this.topRadius ?? source.topRadius; + this.bottomRadius = this.bottomRadius ?? source.bottomRadius; + this.heightReference = this.heightReference ?? source.heightReference; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.numberOfVerticalLines = + this.numberOfVerticalLines ?? source.numberOfVerticalLines; + this.slices = this.slices ?? source.slices; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; }; export default CylinderGraphics; diff --git a/packages/engine/Source/DataSources/CzmlDataSource.js b/packages/engine/Source/DataSources/CzmlDataSource.js index ef48b6c9016f..b8d5a19f394c 100644 --- a/packages/engine/Source/DataSources/CzmlDataSource.js +++ b/packages/engine/Source/DataSources/CzmlDataSource.js @@ -180,7 +180,7 @@ function unwrapColorInterval(czmlInterval) { } function unwrapUriInterval(czmlInterval, sourceUri) { - const uri = defaultValue(czmlInterval.uri, czmlInterval); + const uri = czmlInterval.uri ?? czmlInterval; if (defined(sourceUri)) { return sourceUri.getDerivedResource({ url: uri, @@ -521,11 +521,11 @@ function unwrapInterval(type, czmlInterval, sourceUri) { // associations in getPropertyType switch (type) { case ArcType: - return ArcType[defaultValue(czmlInterval.arcType, czmlInterval)]; + return ArcType[czmlInterval.arcType ?? czmlInterval]; case Array: return czmlInterval.array; case Boolean: - return defaultValue(czmlInterval["boolean"], czmlInterval); + return czmlInterval["boolean"] ?? czmlInterval; case BoundingRectangle: return czmlInterval.boundingRectangle; case Cartesian2: @@ -538,70 +538,52 @@ function unwrapInterval(type, czmlInterval, sourceUri) { return unwrapColorInterval(czmlInterval); case ClassificationType: return ClassificationType[ - defaultValue(czmlInterval.classificationType, czmlInterval) + czmlInterval.classificationType ?? czmlInterval ]; case ColorBlendMode: - return ColorBlendMode[ - defaultValue(czmlInterval.colorBlendMode, czmlInterval) - ]; + return ColorBlendMode[czmlInterval.colorBlendMode ?? czmlInterval]; case CornerType: - return CornerType[defaultValue(czmlInterval.cornerType, czmlInterval)]; + return CornerType[czmlInterval.cornerType ?? czmlInterval]; case HeightReference: - return HeightReference[ - defaultValue(czmlInterval.heightReference, czmlInterval) - ]; + return HeightReference[czmlInterval.heightReference ?? czmlInterval]; case HorizontalOrigin: - return HorizontalOrigin[ - defaultValue(czmlInterval.horizontalOrigin, czmlInterval) - ]; + return HorizontalOrigin[czmlInterval.horizontalOrigin ?? czmlInterval]; case Image: return unwrapUriInterval(czmlInterval, sourceUri); case JulianDate: - return JulianDate.fromIso8601( - defaultValue(czmlInterval.date, czmlInterval), - ); + return JulianDate.fromIso8601(czmlInterval.date ?? czmlInterval); case LabelStyle: - return LabelStyle[defaultValue(czmlInterval.labelStyle, czmlInterval)]; + return LabelStyle[czmlInterval.labelStyle ?? czmlInterval]; case Number: - return defaultValue(czmlInterval.number, czmlInterval); + return czmlInterval.number ?? czmlInterval; case NearFarScalar: return czmlInterval.nearFarScalar; case DistanceDisplayCondition: return czmlInterval.distanceDisplayCondition; case Object: - return defaultValue( - defaultValue(czmlInterval.object, czmlInterval.value), - czmlInterval, - ); + return czmlInterval.object ?? czmlInterval.value ?? czmlInterval; case Quaternion: return unwrapQuaternionInterval(czmlInterval); case Rotation: - return defaultValue(czmlInterval.number, czmlInterval); + return czmlInterval.number ?? czmlInterval; case SensorVolumePortionToDisplay: return SensorVolumePortionToDisplay[ - defaultValue(czmlInterval.portionToDisplay, czmlInterval) + czmlInterval.portionToDisplay ?? czmlInterval ]; case ShadowMode: return ShadowMode[ - defaultValue( - defaultValue(czmlInterval.shadowMode, czmlInterval.shadows), - czmlInterval, - ) + czmlInterval.shadowMode ?? czmlInterval.shadows ?? czmlInterval ]; case String: - return defaultValue(czmlInterval.string, czmlInterval); + return czmlInterval.string ?? czmlInterval; case StripeOrientation: - return StripeOrientation[ - defaultValue(czmlInterval.stripeOrientation, czmlInterval) - ]; + return StripeOrientation[czmlInterval.stripeOrientation ?? czmlInterval]; case Rectangle: return unwrapRectangleInterval(czmlInterval); case Uri: return unwrapUriInterval(czmlInterval, sourceUri); case VerticalOrigin: - return VerticalOrigin[ - defaultValue(czmlInterval.verticalOrigin, czmlInterval) - ]; + return VerticalOrigin[czmlInterval.verticalOrigin ?? czmlInterval]; default: throw new RuntimeError(`Unknown CzmlDataSource interval type: ${type}`); } @@ -736,8 +718,8 @@ function processProperty( // not a known value type, bail return; } - packedLength = defaultValue(type.packedLength, 1); - unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1); + packedLength = type.packedLength ?? 1; + unwrappedIntervalLength = unwrappedInterval.length ?? 1; isSampled = !defined(packetData.array) && typeof unwrappedInterval !== "string" && @@ -969,9 +951,9 @@ function processPositionProperty( if (defined(packetData.referenceFrame)) { referenceFrame = ReferenceFrame[packetData.referenceFrame]; } - referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + referenceFrame = referenceFrame ?? ReferenceFrame.FIXED; unwrappedInterval = unwrapCartesianInterval(packetData); - unwrappedIntervalLength = defaultValue(unwrappedInterval.length, 1); + unwrappedIntervalLength = unwrappedInterval.length ?? 1; isSampled = unwrappedIntervalLength > packedLength; } @@ -2674,14 +2656,11 @@ function processDocument(packet, dataSource) { multiplier: clockPacket.multiplier, }; } else { - clock.interval = defaultValue(clockPacket.interval, clock.interval); - clock.currentTime = defaultValue( - clockPacket.currentTime, - clock.currentTime, - ); - clock.range = defaultValue(clockPacket.range, clock.range); - clock.step = defaultValue(clockPacket.step, clock.step); - clock.multiplier = defaultValue(clockPacket.multiplier, clock.multiplier); + clock.interval = clockPacket.interval ?? clock.interval; + clock.currentTime = clockPacket.currentTime ?? clock.currentTime; + clock.range = clockPacket.range ?? clock.range; + clock.step = clockPacket.step ?? clock.step; + clock.multiplier = clockPacket.multiplier ?? clock.multiplier; } } } @@ -4707,16 +4686,11 @@ function updateClock(dataSource) { clock.currentTime = JulianDate.fromIso8601(clockPacket.currentTime); } if (defined(clockPacket.range)) { - clock.clockRange = defaultValue( - ClockRange[clockPacket.range], - ClockRange.LOOP_STOP, - ); + clock.clockRange = ClockRange[clockPacket.range] ?? ClockRange.LOOP_STOP; } if (defined(clockPacket.step)) { - clock.clockStep = defaultValue( - ClockStep[clockPacket.step], - ClockStep.SYSTEM_CLOCK_MULTIPLIER, - ); + clock.clockStep = + ClockStep[clockPacket.step] ?? ClockStep.SYSTEM_CLOCK_MULTIPLIER; } if (defined(clockPacket.multiplier)) { clock.multiplier = clockPacket.multiplier; @@ -4737,7 +4711,7 @@ function load(dataSource, czml, options, clear) { } //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let promise = czml; let sourceUri = options.sourceUri; @@ -4753,7 +4727,7 @@ function load(dataSource, czml, options, clear) { if (typeof czml === "string" || czml instanceof Resource) { czml = Resource.createIfNeeded(czml); promise = czml.fetchJson(); - sourceUri = defaultValue(sourceUri, czml.clone()); + sourceUri = sourceUri ?? czml.clone(); // Add resource credits to our list of credits to display const resourceCredits = dataSource._resourceCredits; @@ -5143,7 +5117,7 @@ CzmlDataSource._processCzml = function ( updaterFunctions, dataSource, ) { - updaterFunctions = defaultValue(updaterFunctions, CzmlDataSource.updaters); + updaterFunctions = updaterFunctions ?? CzmlDataSource.updaters; if (Array.isArray(czml)) { for (let i = 0, len = czml.length; i < len; ++i) { diff --git a/packages/engine/Source/DataSources/DataSourceClock.js b/packages/engine/Source/DataSources/DataSourceClock.js index 58d55e2a3f0f..3a03747a3a2b 100644 --- a/packages/engine/Source/DataSources/DataSourceClock.js +++ b/packages/engine/Source/DataSources/DataSourceClock.js @@ -1,5 +1,4 @@ import Clock from "../Core/Clock.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -137,12 +136,12 @@ DataSourceClock.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.startTime = defaultValue(this.startTime, source.startTime); - this.stopTime = defaultValue(this.stopTime, source.stopTime); - this.currentTime = defaultValue(this.currentTime, source.currentTime); - this.clockRange = defaultValue(this.clockRange, source.clockRange); - this.clockStep = defaultValue(this.clockStep, source.clockStep); - this.multiplier = defaultValue(this.multiplier, source.multiplier); + this.startTime = this.startTime ?? source.startTime; + this.stopTime = this.stopTime ?? source.stopTime; + this.currentTime = this.currentTime ?? source.currentTime; + this.clockRange = this.clockRange ?? source.clockRange; + this.clockStep = this.clockStep ?? source.clockStep; + this.multiplier = this.multiplier ?? source.multiplier; }; /** @@ -154,12 +153,12 @@ DataSourceClock.prototype.getValue = function (result) { if (!defined(result)) { result = new Clock(); } - result.startTime = defaultValue(this.startTime, result.startTime); - result.stopTime = defaultValue(this.stopTime, result.stopTime); - result.currentTime = defaultValue(this.currentTime, result.currentTime); - result.clockRange = defaultValue(this.clockRange, result.clockRange); - result.multiplier = defaultValue(this.multiplier, result.multiplier); - result.clockStep = defaultValue(this.clockStep, result.clockStep); + result.startTime = this.startTime ?? result.startTime; + result.stopTime = this.stopTime ?? result.stopTime; + result.currentTime = this.currentTime ?? result.currentTime; + result.clockRange = this.clockRange ?? result.clockRange; + result.multiplier = this.multiplier ?? result.multiplier; + result.clockStep = this.clockStep ?? result.clockStep; return result; }; export default DataSourceClock; diff --git a/packages/engine/Source/DataSources/DataSourceCollection.js b/packages/engine/Source/DataSources/DataSourceCollection.js index c01bc6d7d7af..88df04ac9898 100644 --- a/packages/engine/Source/DataSources/DataSourceCollection.js +++ b/packages/engine/Source/DataSources/DataSourceCollection.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -107,7 +106,7 @@ DataSourceCollection.prototype.add = function (dataSource) { * false if the data source was not in the collection. */ DataSourceCollection.prototype.remove = function (dataSource, destroy) { - destroy = defaultValue(destroy, false); + destroy = destroy ?? false; const index = this._dataSources.indexOf(dataSource); if (index !== -1) { @@ -130,7 +129,7 @@ DataSourceCollection.prototype.remove = function (dataSource, destroy) { * @param {boolean} [destroy=false] whether to destroy the data sources in addition to removing them. */ DataSourceCollection.prototype.removeAll = function (destroy) { - destroy = defaultValue(destroy, false); + destroy = destroy ?? false; const dataSources = this._dataSources; for (let i = 0, len = dataSources.length; i < len; ++i) { diff --git a/packages/engine/Source/DataSources/DataSourceDisplay.js b/packages/engine/Source/DataSources/DataSourceDisplay.js index cada5c594211..f3c84109dc81 100644 --- a/packages/engine/Source/DataSources/DataSourceDisplay.js +++ b/packages/engine/Source/DataSources/DataSourceDisplay.js @@ -1,7 +1,6 @@ import ApproximateTerrainHeights from "../Core/ApproximateTerrainHeights.js"; import BoundingSphere from "../Core/BoundingSphere.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import EventHelper from "../Core/EventHelper.js"; @@ -68,10 +67,8 @@ function DataSourceDisplay(options) { this._dataSourceCollection = dataSourceCollection; this._scene = scene; - this._visualizersCallback = defaultValue( - options.visualizersCallback, - DataSourceDisplay.defaultVisualizersCallback, - ); + this._visualizersCallback = + options.visualizersCallback ?? DataSourceDisplay.defaultVisualizersCallback; let primitivesAdded = false; const primitives = new PrimitiveCollection(); diff --git a/packages/engine/Source/DataSources/EllipseGraphics.js b/packages/engine/Source/DataSources/EllipseGraphics.js index 3229900640a3..d0390c89348f 100644 --- a/packages/engine/Source/DataSources/EllipseGraphics.js +++ b/packages/engine/Source/DataSources/EllipseGraphics.js @@ -88,7 +88,7 @@ function EllipseGraphics(options) { this._zIndex = undefined; this._zIndexSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(EllipseGraphics.prototype, { @@ -315,43 +315,29 @@ EllipseGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.semiMajorAxis = defaultValue(this.semiMajorAxis, source.semiMajorAxis); - this.semiMinorAxis = defaultValue(this.semiMinorAxis, source.semiMinorAxis); - this.height = defaultValue(this.height, source.height); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.extrudedHeight = defaultValue( - this.extrudedHeight, - source.extrudedHeight, - ); - this.extrudedHeightReference = defaultValue( - this.extrudedHeightReference, - source.extrudedHeightReference, - ); - this.rotation = defaultValue(this.rotation, source.rotation); - this.stRotation = defaultValue(this.stRotation, source.stRotation); - this.granularity = defaultValue(this.granularity, source.granularity); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.numberOfVerticalLines = defaultValue( - this.numberOfVerticalLines, - source.numberOfVerticalLines, - ); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.classificationType = defaultValue( - this.classificationType, - source.classificationType, - ); - this.zIndex = defaultValue(this.zIndex, source.zIndex); + this.show = this.show ?? source.show; + this.semiMajorAxis = this.semiMajorAxis ?? source.semiMajorAxis; + this.semiMinorAxis = this.semiMinorAxis ?? source.semiMinorAxis; + this.height = this.height ?? source.height; + this.heightReference = this.heightReference ?? source.heightReference; + this.extrudedHeight = this.extrudedHeight ?? source.extrudedHeight; + this.extrudedHeightReference = + this.extrudedHeightReference ?? source.extrudedHeightReference; + this.rotation = this.rotation ?? source.rotation; + this.stRotation = this.stRotation ?? source.stRotation; + this.granularity = this.granularity ?? source.granularity; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.numberOfVerticalLines = + this.numberOfVerticalLines ?? source.numberOfVerticalLines; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; + this.classificationType = + this.classificationType ?? source.classificationType; + this.zIndex = this.zIndex ?? source.zIndex; }; export default EllipseGraphics; diff --git a/packages/engine/Source/DataSources/EllipsoidGeometryUpdater.js b/packages/engine/Source/DataSources/EllipsoidGeometryUpdater.js index 2703e2f3fb4a..b7a86fe88740 100644 --- a/packages/engine/Source/DataSources/EllipsoidGeometryUpdater.js +++ b/packages/engine/Source/DataSources/EllipsoidGeometryUpdater.js @@ -2,7 +2,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; import Color from "../Core/Color.js"; import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js"; import DistanceDisplayConditionGeometryInstanceAttribute from "../Core/DistanceDisplayConditionGeometryInstanceAttribute.js"; @@ -446,7 +445,7 @@ DynamicEllipsoidGeometryUpdater.prototype.update = function (time) { ); const material = MaterialProperty.getValue( time, - defaultValue(ellipsoid.material, defaultMaterial), + ellipsoid.material ?? defaultMaterial, this._material, ); diff --git a/packages/engine/Source/DataSources/EllipsoidGraphics.js b/packages/engine/Source/DataSources/EllipsoidGraphics.js index 1d3ed23b6a76..d631961481ea 100644 --- a/packages/engine/Source/DataSources/EllipsoidGraphics.js +++ b/packages/engine/Source/DataSources/EllipsoidGraphics.js @@ -79,7 +79,7 @@ function EllipsoidGraphics(options) { this._distanceDisplayCondition = undefined; this._distanceDisplayConditionSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(EllipsoidGraphics.prototype, { @@ -289,35 +289,24 @@ EllipsoidGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.radii = defaultValue(this.radii, source.radii); - this.innerRadii = defaultValue(this.innerRadii, source.innerRadii); - this.minimumClock = defaultValue(this.minimumClock, source.minimumClock); - this.maximumClock = defaultValue(this.maximumClock, source.maximumClock); - this.minimumCone = defaultValue(this.minimumCone, source.minimumCone); - this.maximumCone = defaultValue(this.maximumCone, source.maximumCone); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.stackPartitions = defaultValue( - this.stackPartitions, - source.stackPartitions, - ); - this.slicePartitions = defaultValue( - this.slicePartitions, - source.slicePartitions, - ); - this.subdivisions = defaultValue(this.subdivisions, source.subdivisions); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); + this.show = this.show ?? source.show; + this.radii = this.radii ?? source.radii; + this.innerRadii = this.innerRadii ?? source.innerRadii; + this.minimumClock = this.minimumClock ?? source.minimumClock; + this.maximumClock = this.maximumClock ?? source.maximumClock; + this.minimumCone = this.minimumCone ?? source.minimumCone; + this.maximumCone = this.maximumCone ?? source.maximumCone; + this.heightReference = this.heightReference ?? source.heightReference; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.stackPartitions = this.stackPartitions ?? source.stackPartitions; + this.slicePartitions = this.slicePartitions ?? source.slicePartitions; + this.subdivisions = this.subdivisions ?? source.subdivisions; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; }; export default EllipsoidGraphics; diff --git a/packages/engine/Source/DataSources/Entity.js b/packages/engine/Source/DataSources/Entity.js index d8c9fab17f9e..0791931faf6e 100644 --- a/packages/engine/Source/DataSources/Entity.js +++ b/packages/engine/Source/DataSources/Entity.js @@ -112,7 +112,7 @@ function createPropertyTypeDescriptor(name, Type) { * @see {@link https://cesium.com/learn/cesiumjs-learn/cesiumjs-creating-entities/|Creating Entities} */ function Entity(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let id = options.id; if (!defined(id)) { @@ -123,7 +123,7 @@ function Entity(options) { this._id = id; this._definitionChanged = new Event(); this._name = options.name; - this._show = defaultValue(options.show, true); + this._show = options.show ?? true; this._trackingReferenceFrame = defaultValue( options.trackingReferenceFrame, TrackingReferenceFrame.AUTODETECT, @@ -618,8 +618,8 @@ Entity.prototype.merge = function (source) { //Name, show, and availability are not Property objects and are currently handled differently. //source.show is intentionally ignored because this.show always has a value. - this.name = defaultValue(this.name, source.name); - this.availability = defaultValue(this.availability, source.availability); + this.name = this.name ?? source.name; + this.availability = this.availability ?? source.availability; const propertyNames = this._propertyNames; const sourcePropertyNames = defined(source._propertyNames) diff --git a/packages/engine/Source/DataSources/EntityCluster.js b/packages/engine/Source/DataSources/EntityCluster.js index f4106792f289..2fd0709d7d55 100644 --- a/packages/engine/Source/DataSources/EntityCluster.js +++ b/packages/engine/Source/DataSources/EntityCluster.js @@ -33,14 +33,14 @@ import KDBush from "kdbush"; * @demo {@link https://sandcastle.cesium.com/index.html?src=Clustering.html|Cesium Sandcastle Clustering Demo} */ function EntityCluster(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - this._enabled = defaultValue(options.enabled, false); - this._pixelRange = defaultValue(options.pixelRange, 80); - this._minimumClusterSize = defaultValue(options.minimumClusterSize, 2); - this._clusterBillboards = defaultValue(options.clusterBillboards, true); - this._clusterLabels = defaultValue(options.clusterLabels, true); - this._clusterPoints = defaultValue(options.clusterPoints, true); + this._enabled = options.enabled ?? false; + this._pixelRange = options.pixelRange ?? 80; + this._minimumClusterSize = options.minimumClusterSize ?? 2; + this._clusterBillboards = options.clusterBillboards ?? true; + this._clusterLabels = options.clusterLabels ?? true; + this._clusterPoints = options.clusterPoints ?? true; this._labelCollection = undefined; this._billboardCollection = undefined; @@ -73,7 +73,7 @@ function EntityCluster(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; } function expandBoundingBox(bbox, pixelRange) { diff --git a/packages/engine/Source/DataSources/EntityView.js b/packages/engine/Source/DataSources/EntityView.js index bc759b53dbd6..3f82e723ff8c 100644 --- a/packages/engine/Source/DataSources/EntityView.js +++ b/packages/engine/Source/DataSources/EntityView.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Ellipsoid from "../Core/Ellipsoid.js"; import HeadingPitchRange from "../Core/HeadingPitchRange.js"; @@ -342,7 +341,7 @@ function EntityView(entity, scene, ellipsoid) { * The ellipsoid to use for orienting the camera. * @type {Ellipsoid} */ - this.ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + this.ellipsoid = ellipsoid ?? Ellipsoid.default; /** * The bounding sphere of the object. diff --git a/packages/engine/Source/DataSources/GeoJsonDataSource.js b/packages/engine/Source/DataSources/GeoJsonDataSource.js index ddc47f936447..e4b743391b5a 100644 --- a/packages/engine/Source/DataSources/GeoJsonDataSource.js +++ b/packages/engine/Source/DataSources/GeoJsonDataSource.js @@ -275,7 +275,7 @@ function createPoint(dataSource, geoJson, crsFunction, coordinates, options) { color = Color.fromCssColorString(cssColor); } - size = defaultValue(sizes[properties["marker-size"]], size); + size = sizes[properties["marker-size"]] ?? size; const markerSymbol = properties["marker-symbol"]; if (defined(markerSymbol)) { symbol = markerSymbol; @@ -914,7 +914,7 @@ function preload(that, data, options, clear) { //>>includeEnd('debug'); DataSource.setLoading(that, true); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; // User specified credit let credit = options.credit; @@ -928,7 +928,7 @@ function preload(that, data, options, clear) { if (typeof data === "string" || data instanceof Resource) { data = Resource.createIfNeeded(data); promise = data.fetchJson(); - sourceUri = defaultValue(sourceUri, data.getUrlComponent()); + sourceUri = sourceUri ?? data.getUrlComponent(); // Add resource credits to our list of credits to display const resourceCredits = that._resourceCredits; @@ -942,20 +942,20 @@ function preload(that, data, options, clear) { } options = { - describe: defaultValue(options.describe, defaultDescribeProperty), - markerSize: defaultValue(options.markerSize, defaultMarkerSize), - markerSymbol: defaultValue(options.markerSymbol, defaultMarkerSymbol), - markerColor: defaultValue(options.markerColor, defaultMarkerColor), + describe: options.describe ?? defaultDescribeProperty, + markerSize: options.markerSize ?? defaultMarkerSize, + markerSymbol: options.markerSymbol ?? defaultMarkerSymbol, + markerColor: options.markerColor ?? defaultMarkerColor, strokeWidthProperty: new ConstantProperty( - defaultValue(options.strokeWidth, defaultStrokeWidth), + options.strokeWidth ?? defaultStrokeWidth, ), strokeMaterialProperty: new ColorMaterialProperty( - defaultValue(options.stroke, defaultStroke), + options.stroke ?? defaultStroke, ), fillMaterialProperty: new ColorMaterialProperty( - defaultValue(options.fill, defaultFill), + options.fill ?? defaultFill, ), - clampToGround: defaultValue(options.clampToGround, defaultClampToGround), + clampToGround: options.clampToGround ?? defaultClampToGround, }; return Promise.resolve(promise) diff --git a/packages/engine/Source/DataSources/GeometryUpdater.js b/packages/engine/Source/DataSources/GeometryUpdater.js index 3361f2835380..9062fc9ed09a 100644 --- a/packages/engine/Source/DataSources/GeometryUpdater.js +++ b/packages/engine/Source/DataSources/GeometryUpdater.js @@ -1,6 +1,5 @@ import Check from "../Core/Check.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -296,7 +295,7 @@ GeometryUpdater.prototype.isOutlineVisible = function (time) { entity.isAvailable(time) && this._showProperty.getValue(time) && this._showOutlineProperty.getValue(time); - return defaultValue(visible, false); + return visible ?? false; }; /** @@ -312,7 +311,7 @@ GeometryUpdater.prototype.isFilled = function (time) { entity.isAvailable(time) && this._showProperty.getValue(time) && this._fillProperty.getValue(time); - return defaultValue(visible, false); + return visible ?? false; }; /** @@ -459,22 +458,18 @@ GeometryUpdater.prototype._onEntityPropertyChanged = function ( return; } - this._materialProperty = defaultValue(geometry.material, defaultMaterial); - this._fillProperty = defaultValue(fillProperty, defaultFill); - this._showProperty = defaultValue(show, defaultShow); - this._showOutlineProperty = defaultValue(geometry.outline, defaultOutline); + this._materialProperty = geometry.material ?? defaultMaterial; + this._fillProperty = fillProperty ?? defaultFill; + this._showProperty = show ?? defaultShow; + this._showOutlineProperty = geometry.outline ?? defaultOutline; this._outlineColorProperty = outlineEnabled - ? defaultValue(geometry.outlineColor, defaultOutlineColor) + ? (geometry.outlineColor ?? defaultOutlineColor) : undefined; - this._shadowsProperty = defaultValue(geometry.shadows, defaultShadows); - this._distanceDisplayConditionProperty = defaultValue( - geometry.distanceDisplayCondition, - defaultDistanceDisplayCondition, - ); - this._classificationTypeProperty = defaultValue( - geometry.classificationType, - defaultClassificationType, - ); + this._shadowsProperty = geometry.shadows ?? defaultShadows; + this._distanceDisplayConditionProperty = + geometry.distanceDisplayCondition ?? defaultDistanceDisplayCondition; + this._classificationTypeProperty = + geometry.classificationType ?? defaultClassificationType; this._fillEnabled = fillEnabled; diff --git a/packages/engine/Source/DataSources/GeometryVisualizer.js b/packages/engine/Source/DataSources/GeometryVisualizer.js index 0c975a9f698e..668663b2039e 100644 --- a/packages/engine/Source/DataSources/GeometryVisualizer.js +++ b/packages/engine/Source/DataSources/GeometryVisualizer.js @@ -1,7 +1,6 @@ import AssociativeArray from "../Core/AssociativeArray.js"; import BoundingSphere from "../Core/BoundingSphere.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import ClassificationType from "../Scene/ClassificationType.js"; @@ -42,8 +41,8 @@ function GeometryVisualizer( Check.defined("entityCollection", entityCollection); //>>includeEnd('debug'); - primitives = defaultValue(primitives, scene.primitives); - groundPrimitives = defaultValue(groundPrimitives, scene.groundPrimitives); + primitives = primitives ?? scene.primitives; + groundPrimitives = groundPrimitives ?? scene.groundPrimitives; this._scene = scene; this._primitives = primitives; diff --git a/packages/engine/Source/DataSources/GpxDataSource.js b/packages/engine/Source/DataSources/GpxDataSource.js index 8f17fb5e6a68..81fa08314d21 100644 --- a/packages/engine/Source/DataSources/GpxDataSource.js +++ b/packages/engine/Source/DataSources/GpxDataSource.js @@ -246,10 +246,7 @@ function processDescription(node, entity) { for (i = 0; i < length; i++) { const infoTypeName = infoTypeNames[i]; const infoType = descriptiveInfoTypes[infoTypeName]; - infoType.value = defaultValue( - queryStringValue(node, infoType.tag, namespaces.gpx), - "", - ); + infoType.value = queryStringValue(node, infoType.tag, namespaces.gpx) ?? ""; if (defined(infoType.value) && infoType.value !== "") { text = `${text}

${infoType.text}: ${infoType.value}

`; } @@ -668,7 +665,7 @@ function metadataChanged(old, current) { } function load(dataSource, entityCollection, data, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let promise = data; if (typeof data === "string" || data instanceof Resource) { data = Resource.createIfNeeded(data); @@ -947,7 +944,7 @@ GpxDataSource.prototype.load = function (data, options) { throw new DeveloperError("data is required."); } - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; DataSource.setLoading(this, true); const oldName = this._name; const that = this; diff --git a/packages/engine/Source/DataSources/GridMaterialProperty.js b/packages/engine/Source/DataSources/GridMaterialProperty.js index 46436b15a928..a2a8fc382bfc 100644 --- a/packages/engine/Source/DataSources/GridMaterialProperty.js +++ b/packages/engine/Source/DataSources/GridMaterialProperty.js @@ -27,7 +27,7 @@ const defaultLineThickness = new Cartesian2(1, 1); * @constructor */ function GridMaterialProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._color = undefined; diff --git a/packages/engine/Source/DataSources/GroundGeometryUpdater.js b/packages/engine/Source/DataSources/GroundGeometryUpdater.js index 1bbdc14788b2..75c12bd02662 100644 --- a/packages/engine/Source/DataSources/GroundGeometryUpdater.js +++ b/packages/engine/Source/DataSources/GroundGeometryUpdater.js @@ -1,5 +1,4 @@ import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import GeometryOffsetAttribute from "../Core/GeometryOffsetAttribute.js"; @@ -111,7 +110,7 @@ GroundGeometryUpdater.prototype._onEntityPropertyChanged = function ( oneTimeWarning(oneTimeWarning.geometryZIndex); } - this._zIndex = defaultValue(geometry.zIndex, defaultZIndex); + this._zIndex = geometry.zIndex ?? defaultZIndex; if (defined(this._terrainOffsetProperty)) { this._terrainOffsetProperty.destroy(); diff --git a/packages/engine/Source/DataSources/ImageMaterialProperty.js b/packages/engine/Source/DataSources/ImageMaterialProperty.js index 2e4122bc0f8f..2b24c9c0906c 100644 --- a/packages/engine/Source/DataSources/ImageMaterialProperty.js +++ b/packages/engine/Source/DataSources/ImageMaterialProperty.js @@ -23,7 +23,7 @@ const defaultColor = Color.WHITE; * @param {Property|boolean} [options.transparent=false] Set to true when the image has transparency (for example, when a png has transparent sections) */ function ImageMaterialProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._image = undefined; diff --git a/packages/engine/Source/DataSources/KmlDataSource.js b/packages/engine/Source/DataSources/KmlDataSource.js index 012387fdd356..49e85e347ad6 100644 --- a/packages/engine/Source/DataSources/KmlDataSource.js +++ b/packages/engine/Source/DataSources/KmlDataSource.js @@ -401,10 +401,8 @@ function loadXmlFromZip(entry, uriResolver) { } function loadDataUriFromZip(entry, uriResolver) { - const mimeType = defaultValue( - MimeTypes.detectFromFilename(entry.filename), - "application/octet-stream", - ); + const mimeType = + MimeTypes.detectFromFilename(entry.filename) ?? "application/octet-stream"; return Promise.resolve(entry.getData(new zip.Data64URIWriter(mimeType))).then( function (dataUri) { uriResolver[entry.filename] = dataUri; @@ -851,8 +849,8 @@ function getIconHref( const palette = href.charAt(21); // Get the icon number - let x = defaultValue(queryNumericValue(iconNode, "x", namespaces.gx), 0); - let y = defaultValue(queryNumericValue(iconNode, "y", namespaces.gx), 0); + let x = queryNumericValue(iconNode, "x", namespaces.gx) ?? 0; + let y = queryNumericValue(iconNode, "y", namespaces.gx) ?? 0; x = Math.min(x / 32, 7); y = 7 - Math.min(y / 32, 7); const iconNum = 8 * y + x; @@ -885,18 +883,15 @@ function getIconHref( ); } - const viewBoundScale = defaultValue( - queryStringValue(iconNode, "viewBoundScale", namespaces.kml), - 1.0, - ); + const viewBoundScale = + queryStringValue(iconNode, "viewBoundScale", namespaces.kml) ?? 1.0; const defaultViewFormat = viewRefreshMode === "onStop" ? "BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]" : ""; - const viewFormat = defaultValue( - queryStringValue(iconNode, "viewFormat", namespaces.kml), - defaultViewFormat, - ); + const viewFormat = + queryStringValue(iconNode, "viewFormat", namespaces.kml) ?? + defaultViewFormat; const httpQuery = queryStringValue(iconNode, "httpQuery", namespaces.kml); if (defined(viewFormat)) { hrefResource.setQueryParameters(queryToObject(cleanupString(viewFormat))); @@ -982,7 +977,7 @@ function processBillboardIcon( //The hotspot origin is the lower left, but we leave //our billboard origin at the center and simply //modify the pixel offset to take this into account - scale = defaultValue(scale, 1.0); + scale = scale ?? 1.0; let xOffset; let yOffset; @@ -1037,14 +1032,10 @@ function applyStyle( label = createDefaultLabel(); targetEntity.label = label; } - label.scale = defaultValue( - queryNumericValue(node, "scale", namespaces.kml), - label.scale, - ); - label.fillColor = defaultValue( - queryColorValue(node, "color", namespaces.kml), - label.fillColor, - ); + label.scale = + queryNumericValue(node, "scale", namespaces.kml) ?? label.scale; + label.fillColor = + queryColorValue(node, "color", namespaces.kml) ?? label.fillColor; label.text = targetEntity.name; } else if (node.localName === "LineStyle") { let polyline = targetEntity.polyline; @@ -1084,27 +1075,19 @@ function applyStyle( polygon = createDefaultPolygon(); targetEntity.polygon = polygon; } - polygon.material = defaultValue( - queryColorValue(node, "color", namespaces.kml), - polygon.material, - ); - polygon.fill = defaultValue( - queryBooleanValue(node, "fill", namespaces.kml), - polygon.fill, - ); - polygon.outline = defaultValue( - queryBooleanValue(node, "outline", namespaces.kml), - polygon.outline, - ); + polygon.material = + queryColorValue(node, "color", namespaces.kml) ?? polygon.material; + polygon.fill = + queryBooleanValue(node, "fill", namespaces.kml) ?? polygon.fill; + polygon.outline = + queryBooleanValue(node, "outline", namespaces.kml) ?? polygon.outline; } else if (node.localName === "BalloonStyle") { - const bgColor = defaultValue( - parseColorString(queryStringValue(node, "bgColor", namespaces.kml)), - Color.WHITE, - ); - const textColor = defaultValue( - parseColorString(queryStringValue(node, "textColor", namespaces.kml)), - Color.BLACK, - ); + const bgColor = + parseColorString(queryStringValue(node, "bgColor", namespaces.kml)) ?? + Color.WHITE; + const textColor = + parseColorString(queryStringValue(node, "textColor", namespaces.kml)) ?? + Color.BLACK; const text = queryStringValue(node, "text", namespaces.kml); //This is purely an internal property used in style processing, @@ -1435,10 +1418,7 @@ function createPositionPropertyFromAltitudeMode( ) { oneTimeWarning( "kml-altitudeMode-unknown", - `KML - Unknown altitudeMode: ${defaultValue( - altitudeMode, - gxAltitudeMode, - )}`, + `KML - Unknown altitudeMode: ${altitudeMode ?? gxAltitudeMode}`, ); } @@ -1471,10 +1451,7 @@ function createPositionPropertyArrayFromAltitudeMode( ) { oneTimeWarning( "kml-altitudeMode-unknown", - `KML - Unknown altitudeMode: ${defaultValue( - altitudeMode, - gxAltitudeMode, - )}`, + `KML - Unknown altitudeMode: ${altitudeMode ?? gxAltitudeMode}`, ); } @@ -1660,7 +1637,7 @@ function processLineStringOrLinearRing( polylineGraphics.material = defined(polyline.material) ? polyline.material.color.getValue(Iso8601.MINIMUM_VALUE) : Color.WHITE; - polylineGraphics.width = defaultValue(polyline.width, 1.0); + polylineGraphics.width = polyline.width ?? 1.0; } else { polylineGraphics.material = Color.WHITE; polylineGraphics.width = 1.0; @@ -2123,27 +2100,24 @@ function processDescription( const extendedData = kmlData.extendedData; const description = queryStringValue(node, "description", namespaces.kml); - const balloonStyle = defaultValue( - entity.balloonStyle, - styleEntity.balloonStyle, - ); + const balloonStyle = entity.balloonStyle ?? styleEntity.balloonStyle; let background = Color.WHITE; let foreground = Color.BLACK; let text = description; if (defined(balloonStyle)) { - background = defaultValue(balloonStyle.bgColor, Color.WHITE); - foreground = defaultValue(balloonStyle.textColor, Color.BLACK); - text = defaultValue(balloonStyle.text, description); + background = balloonStyle.bgColor ?? Color.WHITE; + foreground = balloonStyle.textColor ?? Color.BLACK; + text = balloonStyle.text ?? description; } let value; if (defined(text)) { - text = text.replace("$[name]", defaultValue(entity.name, "")); - text = text.replace("$[description]", defaultValue(description, "")); - text = text.replace("$[address]", defaultValue(kmlData.address, "")); - text = text.replace("$[Snippet]", defaultValue(kmlData.snippet, "")); + text = text.replace("$[name]", entity.name ?? ""); + text = text.replace("$[description]", description ?? ""); + text = text.replace("$[address]", kmlData.address ?? ""); + text = text.replace("$[Snippet]", kmlData.snippet ?? ""); text = text.replace("$[id]", entity.id); //While not explicitly defined by the OGC spec, in Google Earth @@ -2165,7 +2139,7 @@ function processDescription( value = isDisplayName ? value.displayName : value.value; } if (defined(value)) { - text = text.replace(token, defaultValue(value, "")); + text = text.replace(token, value ?? ""); } } } @@ -2179,10 +2153,9 @@ function processDescription( for (i = 0; i < keys.length; i++) { key = keys[i]; value = extendedData[key]; - text += `${defaultValue( - value.displayName, - key, - )}${defaultValue(value.value, "")}`; + text += `${ + value.displayName ?? key + }${value.value ?? ""}`; } text += ""; } @@ -2294,7 +2267,7 @@ function processFeature(dataSource, featureNode, processingData) { "visibility", namespaces.kml, ); - entity.show = ancestryIsVisible(parent) && defaultValue(visibility, true); + entity.show = ancestryIsVisible(parent) && (visibility ?? true); //const open = queryBooleanValue(featureNode, 'open', namespaces.kml); const authorNode = queryFirstNode(featureNode, "author", namespaces.atom); @@ -2454,31 +2427,14 @@ function processTourFlyTo(tour, entryNode, ellipsoid) { function processCamera(featureNode, entity, ellipsoid) { const camera = queryFirstNode(featureNode, "Camera", namespaces.kml); if (defined(camera)) { - const lon = defaultValue( - queryNumericValue(camera, "longitude", namespaces.kml), - 0.0, - ); - const lat = defaultValue( - queryNumericValue(camera, "latitude", namespaces.kml), - 0.0, - ); - const altitude = defaultValue( - queryNumericValue(camera, "altitude", namespaces.kml), - 0.0, - ); + const lon = queryNumericValue(camera, "longitude", namespaces.kml) ?? 0.0; + const lat = queryNumericValue(camera, "latitude", namespaces.kml) ?? 0.0; + const altitude = + queryNumericValue(camera, "altitude", namespaces.kml) ?? 0.0; - const heading = defaultValue( - queryNumericValue(camera, "heading", namespaces.kml), - 0.0, - ); - const tilt = defaultValue( - queryNumericValue(camera, "tilt", namespaces.kml), - 0.0, - ); - const roll = defaultValue( - queryNumericValue(camera, "roll", namespaces.kml), - 0.0, - ); + const heading = queryNumericValue(camera, "heading", namespaces.kml) ?? 0.0; + const tilt = queryNumericValue(camera, "tilt", namespaces.kml) ?? 0.0; + const roll = queryNumericValue(camera, "roll", namespaces.kml) ?? 0.0; const position = Cartesian3.fromDegrees(lon, lat, altitude, ellipsoid); const hpr = HeadingPitchRoll.fromDegrees(heading, tilt - 90.0, roll); @@ -2490,27 +2446,16 @@ function processCamera(featureNode, entity, ellipsoid) { function processLookAt(featureNode, entity, ellipsoid) { const lookAt = queryFirstNode(featureNode, "LookAt", namespaces.kml); if (defined(lookAt)) { - const lon = defaultValue( - queryNumericValue(lookAt, "longitude", namespaces.kml), - 0.0, - ); - const lat = defaultValue( - queryNumericValue(lookAt, "latitude", namespaces.kml), - 0.0, - ); - const altitude = defaultValue( - queryNumericValue(lookAt, "altitude", namespaces.kml), - 0.0, - ); + const lon = queryNumericValue(lookAt, "longitude", namespaces.kml) ?? 0.0; + const lat = queryNumericValue(lookAt, "latitude", namespaces.kml) ?? 0.0; + const altitude = + queryNumericValue(lookAt, "altitude", namespaces.kml) ?? 0.0; let heading = queryNumericValue(lookAt, "heading", namespaces.kml); let tilt = queryNumericValue(lookAt, "tilt", namespaces.kml); - const range = defaultValue( - queryNumericValue(lookAt, "range", namespaces.kml), - 0.0, - ); + const range = queryNumericValue(lookAt, "range", namespaces.kml) ?? 0.0; - tilt = CesiumMath.toRadians(defaultValue(tilt, 0.0)); - heading = CesiumMath.toRadians(defaultValue(heading, 0.0)); + tilt = CesiumMath.toRadians(tilt ?? 0.0); + heading = CesiumMath.toRadians(heading ?? 0.0); const hpr = new HeadingPitchRange( heading, @@ -2909,7 +2854,7 @@ function processNetworkLinkQueryString( let centerCartesian; let centerCartographic; - bbox = defaultValue(bbox, zeroRectangle); + bbox = bbox ?? zeroRectangle; if (defined(canvas)) { scratchCartesian2.x = canvas.clientWidth * 0.5; scratchCartesian2.y = canvas.clientHeight * 0.5; @@ -3096,18 +3041,15 @@ function processNetworkLink(dataSource, node, processingData, deferredLoading) { ); return; } - viewBoundScale = defaultValue( - queryStringValue(link, "viewBoundScale", namespaces.kml), - 1.0, - ); + viewBoundScale = + queryStringValue(link, "viewBoundScale", namespaces.kml) ?? 1.0; const defaultViewFormat = viewRefreshMode === "onStop" ? "BBOX=[bboxWest],[bboxSouth],[bboxEast],[bboxNorth]" : ""; - const viewFormat = defaultValue( - queryStringValue(link, "viewFormat", namespaces.kml), - defaultViewFormat, - ); + const viewFormat = + queryStringValue(link, "viewFormat", namespaces.kml) ?? + defaultViewFormat; const httpQuery = queryStringValue(link, "httpQuery", namespaces.kml); if (defined(viewFormat)) { href.setQueryParameters(queryToObject(cleanupString(viewFormat))); @@ -3156,10 +3098,8 @@ function processNetworkLink(dataSource, node, processingData, deferredLoading) { "refreshMode", namespaces.kml, ); - let refreshInterval = defaultValue( - queryNumericValue(link, "refreshInterval", namespaces.kml), - 0, - ); + let refreshInterval = + queryNumericValue(link, "refreshInterval", namespaces.kml) ?? 0; if ( (refreshMode === "onInterval" && refreshInterval > 0) || refreshMode === "onExpire" || @@ -3188,23 +3128,18 @@ function processNetworkLink(dataSource, node, processingData, deferredLoading) { let minRefreshPeriod = 0; if (hasNetworkLinkControl) { networkLinkInfo.cookie = queryToObject( - defaultValue( - queryStringValue( - networkLinkControl, - "cookie", - namespaces.kml, - ), - "", - ), + queryStringValue( + networkLinkControl, + "cookie", + namespaces.kml, + ) ?? "", ); - minRefreshPeriod = defaultValue( + minRefreshPeriod = queryNumericValue( networkLinkControl, "minRefreshPeriod", namespaces.kml, - ), - 0, - ); + ) ?? 0; } if (refreshMode === "onInterval") { @@ -3246,10 +3181,8 @@ function processNetworkLink(dataSource, node, processingData, deferredLoading) { } else if (defined(dataSource.camera)) { // Only allow onStop refreshes if we have a camera networkLinkInfo.refreshMode = RefreshMode.STOP; - networkLinkInfo.time = defaultValue( - queryNumericValue(link, "viewRefreshTime", namespaces.kml), - 0, - ); + networkLinkInfo.time = + queryNumericValue(link, "viewRefreshTime", namespaces.kml) ?? 0; } else { oneTimeWarning( "kml-refrehMode-onStop-noCamera", @@ -3422,7 +3355,7 @@ function loadKmz( } function load(dataSource, entityCollection, data, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let sourceUri = options.sourceUri; const uriResolver = options.uriResolver; const context = options.context; @@ -3432,7 +3365,7 @@ function load(dataSource, entityCollection, data, options) { if (typeof data === "string" || data instanceof Resource) { data = Resource.createIfNeeded(data); promise = data.fetchBlob(); - sourceUri = defaultValue(sourceUri, data.clone()); + sourceUri = sourceUri ?? data.clone(); // Add resource credits to our list of credits to display const resourceCredits = dataSource._resourceCredits; @@ -3444,7 +3377,7 @@ function load(dataSource, entityCollection, data, options) { } } } else { - sourceUri = defaultValue(sourceUri, Resource.DEFAULT.clone()); + sourceUri = sourceUri ?? Resource.DEFAULT.clone(); } sourceUri = Resource.createIfNeeded(sourceUri); @@ -3600,7 +3533,7 @@ function load(dataSource, entityCollection, data, options) { * ); */ function KmlDataSource(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const camera = options.camera; const canvas = options.canvas; @@ -3647,7 +3580,7 @@ function KmlDataSource(options) { : Rectangle.clone(Rectangle.MAX_VALUE), }; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.default; // User specified credit let credit = options.credit; @@ -3673,7 +3606,7 @@ function KmlDataSource(options) { * @returns {Promise} A promise that will resolve to a new KmlDataSource instance once the KML is loaded. */ KmlDataSource.load = function (data, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const dataSource = new KmlDataSource(options); return dataSource.load(data, options); }; @@ -3848,12 +3781,12 @@ KmlDataSource.prototype.load = function (data, options) { } //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; DataSource.setLoading(this, true); const oldName = this._name; this._name = undefined; - this._clampToGround = defaultValue(options.clampToGround, false); + this._clampToGround = options.clampToGround ?? false; const that = this; return load(this, this._entityCollection, data, options) @@ -3983,19 +3916,14 @@ function getNetworkLinkUpdateCallback( return; } networkLink.cookie = queryToObject( - defaultValue( - queryStringValue(networkLinkControl, "cookie", namespaces.kml), - "", - ), + queryStringValue(networkLinkControl, "cookie", namespaces.kml) ?? "", ); - minRefreshPeriod = defaultValue( + minRefreshPeriod = queryNumericValue( networkLinkControl, "minRefreshPeriod", namespaces.kml, - ), - 0, - ); + ) ?? 0; } const now = JulianDate.now(); @@ -4204,7 +4132,7 @@ KmlDataSource.prototype.update = function (time) { const href = networkLink.href.clone(); href.setQueryParameters(networkLink.cookie); - const ellipsoid = defaultValue(that._ellipsoid, Ellipsoid.default); + const ellipsoid = that._ellipsoid ?? Ellipsoid.default; processNetworkLinkQueryString( href, that.camera, diff --git a/packages/engine/Source/DataSources/LabelGraphics.js b/packages/engine/Source/DataSources/LabelGraphics.js index 3067bb8934ad..710d73b65d67 100644 --- a/packages/engine/Source/DataSources/LabelGraphics.js +++ b/packages/engine/Source/DataSources/LabelGraphics.js @@ -93,7 +93,7 @@ function LabelGraphics(options) { this._disableDepthTestDistance = undefined; this._disableDepthTestDistanceSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(LabelGraphics.prototype, { @@ -372,59 +372,30 @@ LabelGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.text = defaultValue(this.text, source.text); - this.font = defaultValue(this.font, source.font); - this.style = defaultValue(this.style, source.style); - this.scale = defaultValue(this.scale, source.scale); - this.showBackground = defaultValue( - this.showBackground, - source.showBackground, - ); - this.backgroundColor = defaultValue( - this.backgroundColor, - source.backgroundColor, - ); - this.backgroundPadding = defaultValue( - this.backgroundPadding, - source.backgroundPadding, - ); - this.pixelOffset = defaultValue(this.pixelOffset, source.pixelOffset); - this.eyeOffset = defaultValue(this.eyeOffset, source.eyeOffset); - this.horizontalOrigin = defaultValue( - this.horizontalOrigin, - source.horizontalOrigin, - ); - this.verticalOrigin = defaultValue( - this.verticalOrigin, - source.verticalOrigin, - ); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.fillColor = defaultValue(this.fillColor, source.fillColor); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.translucencyByDistance = defaultValue( - this.translucencyByDistance, - source.translucencyByDistance, - ); - this.pixelOffsetScaleByDistance = defaultValue( - this.pixelOffsetScaleByDistance, - source.pixelOffsetScaleByDistance, - ); - this.scaleByDistance = defaultValue( - this.scaleByDistance, - source.scaleByDistance, - ); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.disableDepthTestDistance = defaultValue( - this.disableDepthTestDistance, - source.disableDepthTestDistance, - ); + this.show = this.show ?? source.show; + this.text = this.text ?? source.text; + this.font = this.font ?? source.font; + this.style = this.style ?? source.style; + this.scale = this.scale ?? source.scale; + this.showBackground = this.showBackground ?? source.showBackground; + this.backgroundColor = this.backgroundColor ?? source.backgroundColor; + this.backgroundPadding = this.backgroundPadding ?? source.backgroundPadding; + this.pixelOffset = this.pixelOffset ?? source.pixelOffset; + this.eyeOffset = this.eyeOffset ?? source.eyeOffset; + this.horizontalOrigin = this.horizontalOrigin ?? source.horizontalOrigin; + this.verticalOrigin = this.verticalOrigin ?? source.verticalOrigin; + this.heightReference = this.heightReference ?? source.heightReference; + this.fillColor = this.fillColor ?? source.fillColor; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.translucencyByDistance = + this.translucencyByDistance ?? source.translucencyByDistance; + this.pixelOffsetScaleByDistance = + this.pixelOffsetScaleByDistance ?? source.pixelOffsetScaleByDistance; + this.scaleByDistance = this.scaleByDistance ?? source.scaleByDistance; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; + this.disableDepthTestDistance = + this.disableDepthTestDistance ?? source.disableDepthTestDistance; }; export default LabelGraphics; diff --git a/packages/engine/Source/DataSources/LabelVisualizer.js b/packages/engine/Source/DataSources/LabelVisualizer.js index ebd4daa3cf5a..14bcf0a5331b 100644 --- a/packages/engine/Source/DataSources/LabelVisualizer.js +++ b/packages/engine/Source/DataSources/LabelVisualizer.js @@ -2,7 +2,6 @@ import AssociativeArray from "../Core/AssociativeArray.js"; import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -283,7 +282,7 @@ LabelVisualizer.prototype.getBoundingSphere = function (entity, result) { const label = item.label; result.center = Cartesian3.clone( - defaultValue(label._clampedPosition, label.position), + label._clampedPosition ?? label.position, result.center, ); result.radius = 0; diff --git a/packages/engine/Source/DataSources/ModelGraphics.js b/packages/engine/Source/DataSources/ModelGraphics.js index 8320768fa319..dc076b0ac32c 100644 --- a/packages/engine/Source/DataSources/ModelGraphics.js +++ b/packages/engine/Source/DataSources/ModelGraphics.js @@ -114,7 +114,7 @@ function ModelGraphics(options) { this._customShader = undefined; this._customShaderSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(ModelGraphics.prototype, { @@ -382,65 +382,28 @@ ModelGraphics.prototype.merge = function (source) { throw new DeveloperError("source is required."); } //>>includeEnd('debug'); - - this.show = defaultValue(this.show, source.show); - this.uri = defaultValue(this.uri, source.uri); - this.scale = defaultValue(this.scale, source.scale); - this.enableVerticalExaggeration = defaultValue( - this.enableVerticalExaggeration, - source.enableVerticalExaggeration, - ); - this.minimumPixelSize = defaultValue( - this.minimumPixelSize, - source.minimumPixelSize, - ); - this.maximumScale = defaultValue(this.maximumScale, source.maximumScale); - this.incrementallyLoadTextures = defaultValue( - this.incrementallyLoadTextures, - source.incrementallyLoadTextures, - ); - this.runAnimations = defaultValue(this.runAnimations, source.runAnimations); - this.clampAnimations = defaultValue( - this.clampAnimations, - source.clampAnimations, - ); - this.shadows = defaultValue(this.shadows, source.shadows); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.silhouetteColor = defaultValue( - this.silhouetteColor, - source.silhouetteColor, - ); - this.silhouetteSize = defaultValue( - this.silhouetteSize, - source.silhouetteSize, - ); - this.color = defaultValue(this.color, source.color); - this.colorBlendMode = defaultValue( - this.colorBlendMode, - source.colorBlendMode, - ); - this.colorBlendAmount = defaultValue( - this.colorBlendAmount, - source.colorBlendAmount, - ); - this.imageBasedLightingFactor = defaultValue( - this.imageBasedLightingFactor, - source.imageBasedLightingFactor, - ); - - this.lightColor = defaultValue(this.lightColor, source.lightColor); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.clippingPlanes = defaultValue( - this.clippingPlanes, - source.clippingPlanes, - ); - this.customShader = defaultValue(this.customShader, source.customShader); + this.show = this.show ?? source.show; + this.uri = this.uri ?? source.uri; + this.scale = this.scale ?? source.scale; + this.enableVerticalExaggeration = this.enableVerticalExaggeration ?? source.enableVerticalExaggeration; + this.minimumPixelSize = this.minimumPixelSize ?? source.minimumPixelSize; + this.maximumScale = this.maximumScale ?? source.maximumScale; + this.incrementallyLoadTextures = this.incrementallyLoadTextures ?? source.incrementallyLoadTextures; + this.runAnimations = this.runAnimations ?? source.runAnimations; + this.clampAnimations = this.clampAnimations ?? source.clampAnimations; + this.shadows = this.shadows ?? source.shadows; + this.heightReference = this.heightReference ?? source.heightReference; + this.silhouetteColor = this.silhouetteColor ?? source.silhouetteColor; + this.silhouetteSize = this.silhouetteSize ?? source.silhouetteSize; + this.color = this.color ?? source.color; + this.colorBlendMode = this.colorBlendMode ?? source.colorBlendMode; + this.colorBlendAmount = this.colorBlendAmount ?? source.colorBlendAmount; + this.imageBasedLightingFactor = this.imageBasedLightingFactor ?? source.imageBasedLightingFactor; + this.lightColor = this.lightColor ?? source.lightColor; + this.distanceDisplayCondition = this.distanceDisplayCondition ?? + source.distanceDisplayCondition; + this.clippingPlanes = this.clippingPlanes ??source.clippingPlanes; + this.customShader = this.customShader ?? source.customShader; const sourceNodeTransformations = source.nodeTransformations; if (defined(sourceNodeTransformations)) { diff --git a/packages/engine/Source/DataSources/ModelVisualizer.js b/packages/engine/Source/DataSources/ModelVisualizer.js index 42d1bd177592..58037e72a0db 100644 --- a/packages/engine/Source/DataSources/ModelVisualizer.js +++ b/packages/engine/Source/DataSources/ModelVisualizer.js @@ -4,7 +4,6 @@ import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -450,7 +449,7 @@ ModelVisualizer.prototype.getBoundingSphere = function (entity, result) { } const scene = this._scene; - const ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.default); + const ellipsoid = scene.ellipsoid ?? Ellipsoid.default; const hasHeightReference = model.heightReference !== HeightReference.NONE; if (hasHeightReference) { diff --git a/packages/engine/Source/DataSources/NodeTransformationProperty.js b/packages/engine/Source/DataSources/NodeTransformationProperty.js index 8d0f121fb957..323b949787c5 100644 --- a/packages/engine/Source/DataSources/NodeTransformationProperty.js +++ b/packages/engine/Source/DataSources/NodeTransformationProperty.js @@ -19,7 +19,7 @@ const defaultNodeTransformation = new TranslationRotationScale(); * @param {Property|Cartesian3} [options.scale=new Cartesian3(1.0, 1.0, 1.0)] A {@link Cartesian3} Property specifying the (x, y, z) scaling to apply to the node. */ function NodeTransformationProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._translation = undefined; diff --git a/packages/engine/Source/DataSources/PathGraphics.js b/packages/engine/Source/DataSources/PathGraphics.js index 8cc59662726a..6e72f467c7ba 100644 --- a/packages/engine/Source/DataSources/PathGraphics.js +++ b/packages/engine/Source/DataSources/PathGraphics.js @@ -44,7 +44,7 @@ function PathGraphics(options) { this._distanceDisplayCondition = undefined; this._distanceDisplayConditionSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(PathGraphics.prototype, { @@ -149,15 +149,13 @@ PathGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.leadTime = defaultValue(this.leadTime, source.leadTime); - this.trailTime = defaultValue(this.trailTime, source.trailTime); - this.width = defaultValue(this.width, source.width); - this.resolution = defaultValue(this.resolution, source.resolution); - this.material = defaultValue(this.material, source.material); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); + this.show = this.show ?? source.show; + this.leadTime = this.leadTime ?? source.leadTime; + this.trailTime = this.trailTime ?? source.trailTime; + this.width = this.width ?? source.width; + this.resolution = this.resolution ?? source.resolution; + this.material = this.material ?? source.material; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; }; export default PathGraphics; diff --git a/packages/engine/Source/DataSources/PlaneGraphics.js b/packages/engine/Source/DataSources/PlaneGraphics.js index bf938525c17e..85a1a8c33e2c 100644 --- a/packages/engine/Source/DataSources/PlaneGraphics.js +++ b/packages/engine/Source/DataSources/PlaneGraphics.js @@ -55,7 +55,7 @@ function PlaneGraphics(options) { this._distanceDisplayCondition = undefined; this._distanceDisplayConditionSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(PlaneGraphics.prototype, { @@ -193,18 +193,16 @@ PlaneGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.plane = defaultValue(this.plane, source.plane); - this.dimensions = defaultValue(this.dimensions, source.dimensions); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); + this.show = this.show ?? source.show; + this.plane = this.plane ?? source.plane; + this.dimensions = this.dimensions ?? source.dimensions; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; }; export default PlaneGraphics; diff --git a/packages/engine/Source/DataSources/PointGraphics.js b/packages/engine/Source/DataSources/PointGraphics.js index 1a38dabfac98..67328395aee6 100644 --- a/packages/engine/Source/DataSources/PointGraphics.js +++ b/packages/engine/Source/DataSources/PointGraphics.js @@ -55,7 +55,7 @@ function PointGraphics(options) { this._splitDirection = undefined; this._splitDirectionSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(PointGraphics.prototype, { @@ -204,35 +204,20 @@ PointGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.pixelSize = defaultValue(this.pixelSize, source.pixelSize); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.color = defaultValue(this.color, source.color); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.scaleByDistance = defaultValue( - this.scaleByDistance, - source.scaleByDistance, - ); - this.translucencyByDistance = defaultValue( - this._translucencyByDistance, - source.translucencyByDistance, - ); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.disableDepthTestDistance = defaultValue( - this.disableDepthTestDistance, - source.disableDepthTestDistance, - ); - - this.splitDirection = defaultValue( - this.splitDirection, - source.splitDirection, - ); + this.show = this.show ?? source.show; + this.pixelSize = this.pixelSize ?? source.pixelSize; + this.heightReference = this.heightReference ?? source.heightReference; + this.color = this.color ?? source.color; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.scaleByDistance = this.scaleByDistance ?? source.scaleByDistance; + this.translucencyByDistance = + this._translucencyByDistance ?? source.translucencyByDistance; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; + this.disableDepthTestDistance = + this.disableDepthTestDistance ?? source.disableDepthTestDistance; + + this.splitDirection = this.splitDirection ?? source.splitDirection; }; export default PointGraphics; diff --git a/packages/engine/Source/DataSources/PolygonGraphics.js b/packages/engine/Source/DataSources/PolygonGraphics.js index d6897a82810a..0ba76dbb8700 100644 --- a/packages/engine/Source/DataSources/PolygonGraphics.js +++ b/packages/engine/Source/DataSources/PolygonGraphics.js @@ -104,7 +104,7 @@ function PolygonGraphics(options) { this._textureCoordinates = undefined; this._textureCoordinatesSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(PolygonGraphics.prototype, { @@ -353,48 +353,31 @@ PolygonGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.hierarchy = defaultValue(this.hierarchy, source.hierarchy); - this.height = defaultValue(this.height, source.height); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.extrudedHeight = defaultValue( - this.extrudedHeight, - source.extrudedHeight, - ); - this.extrudedHeightReference = defaultValue( - this.extrudedHeightReference, - source.extrudedHeightReference, - ); - this.stRotation = defaultValue(this.stRotation, source.stRotation); - this.granularity = defaultValue(this.granularity, source.granularity); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.perPositionHeight = defaultValue( - this.perPositionHeight, - source.perPositionHeight, - ); - this.closeTop = defaultValue(this.closeTop, source.closeTop); - this.closeBottom = defaultValue(this.closeBottom, source.closeBottom); - this.arcType = defaultValue(this.arcType, source.arcType); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.classificationType = defaultValue( - this.classificationType, - source.classificationType, - ); - this.zIndex = defaultValue(this.zIndex, source.zIndex); - this.textureCoordinates = defaultValue( - this.textureCoordinates, - source.textureCoordinates, - ); + this.show = this.show ?? source.show; + this.hierarchy = this.hierarchy ?? source.hierarchy; + this.height = this.height ?? source.height; + this.heightReference = this.heightReference ?? source.heightReference; + this.extrudedHeight = this.extrudedHeight ?? source.extrudedHeight; + this.extrudedHeightReference = + this.extrudedHeightReference ?? source.extrudedHeightReference; + this.stRotation = this.stRotation ?? source.stRotation; + this.granularity = this.granularity ?? source.granularity; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.perPositionHeight = this.perPositionHeight ?? source.perPositionHeight; + this.closeTop = this.closeTop ?? source.closeTop; + this.closeBottom = this.closeBottom ?? source.closeBottom; + this.arcType = this.arcType ?? source.arcType; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; + this.classificationType = + this.classificationType ?? source.classificationType; + this.zIndex = this.zIndex ?? source.zIndex; + this.textureCoordinates = + this.textureCoordinates ?? source.textureCoordinates; }; export default PolygonGraphics; diff --git a/packages/engine/Source/DataSources/PolylineDashMaterialProperty.js b/packages/engine/Source/DataSources/PolylineDashMaterialProperty.js index f724520f22fc..c63b2fcebcc3 100644 --- a/packages/engine/Source/DataSources/PolylineDashMaterialProperty.js +++ b/packages/engine/Source/DataSources/PolylineDashMaterialProperty.js @@ -23,7 +23,7 @@ const defaultDashPattern = 255.0; * @param {Property|number} [options.dashPattern=255.0] A numeric Property specifying a 16 bit pattern for the dash */ function PolylineDashMaterialProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._color = undefined; diff --git a/packages/engine/Source/DataSources/PolylineGeometryUpdater.js b/packages/engine/Source/DataSources/PolylineGeometryUpdater.js index 8776e44ada01..ee2734001752 100644 --- a/packages/engine/Source/DataSources/PolylineGeometryUpdater.js +++ b/packages/engine/Source/DataSources/PolylineGeometryUpdater.js @@ -3,7 +3,6 @@ import BoundingSphere from "../Core/BoundingSphere.js"; import Check from "../Core/Check.js"; import Color from "../Core/Color.js"; import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -347,7 +346,7 @@ PolylineGeometryUpdater.prototype.isFilled = function (time) { this._fillEnabled && entity.isAvailable(time) && this._showProperty.getValue(time); - return defaultValue(visible, false); + return visible ?? false; }; /** @@ -511,22 +510,18 @@ PolylineGeometryUpdater.prototype._onEntityPropertyChanged = function ( } const zIndex = polyline.zIndex; - const material = defaultValue(polyline.material, defaultMaterial); + const material = polyline.material ?? defaultMaterial; const isColorMaterial = material instanceof ColorMaterialProperty; this._materialProperty = material; this._depthFailMaterialProperty = polyline.depthFailMaterial; - this._showProperty = defaultValue(show, defaultShow); - this._shadowsProperty = defaultValue(polyline.shadows, defaultShadows); - this._distanceDisplayConditionProperty = defaultValue( - polyline.distanceDisplayCondition, - defaultDistanceDisplayCondition, - ); - this._classificationTypeProperty = defaultValue( - polyline.classificationType, - defaultClassificationType, - ); + this._showProperty = show ?? defaultShow; + this._shadowsProperty = polyline.shadows ?? defaultShadows; + this._distanceDisplayConditionProperty = + polyline.distanceDisplayCondition ?? defaultDistanceDisplayCondition; + this._classificationTypeProperty = + polyline.classificationType ?? defaultClassificationType; this._fillEnabled = true; - this._zIndex = defaultValue(zIndex, defaultZIndex); + this._zIndex = zIndex ?? defaultZIndex; const width = polyline.width; const arcType = polyline.arcType; diff --git a/packages/engine/Source/DataSources/PolylineGlowMaterialProperty.js b/packages/engine/Source/DataSources/PolylineGlowMaterialProperty.js index 7cdb799d6f23..c7d6662d62d0 100644 --- a/packages/engine/Source/DataSources/PolylineGlowMaterialProperty.js +++ b/packages/engine/Source/DataSources/PolylineGlowMaterialProperty.js @@ -21,7 +21,7 @@ const defaultTaperPower = 1.0; * @param {Property|number} [options.taperPower=1.0] A numeric Property specifying the strength of the tapering effect, as a percentage of the total line length. If 1.0 or higher, no taper effect is used. */ function PolylineGlowMaterialProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._color = undefined; diff --git a/packages/engine/Source/DataSources/PolylineGraphics.js b/packages/engine/Source/DataSources/PolylineGraphics.js index dccb69badc04..58dbace0b7b2 100644 --- a/packages/engine/Source/DataSources/PolylineGraphics.js +++ b/packages/engine/Source/DataSources/PolylineGraphics.js @@ -64,7 +64,7 @@ function PolylineGraphics(options) { this._zIndex = undefined; this._zIndexSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(PolylineGraphics.prototype, { @@ -223,26 +223,19 @@ PolylineGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.positions = defaultValue(this.positions, source.positions); - this.width = defaultValue(this.width, source.width); - this.granularity = defaultValue(this.granularity, source.granularity); - this.material = defaultValue(this.material, source.material); - this.depthFailMaterial = defaultValue( - this.depthFailMaterial, - source.depthFailMaterial, - ); - this.arcType = defaultValue(this.arcType, source.arcType); - this.clampToGround = defaultValue(this.clampToGround, source.clampToGround); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.classificationType = defaultValue( - this.classificationType, - source.classificationType, - ); - this.zIndex = defaultValue(this.zIndex, source.zIndex); + this.show = this.show ?? source.show; + this.positions = this.positions ?? source.positions; + this.width = this.width ?? source.width; + this.granularity = this.granularity ?? source.granularity; + this.material = this.material ?? source.material; + this.depthFailMaterial = this.depthFailMaterial ?? source.depthFailMaterial; + this.arcType = this.arcType ?? source.arcType; + this.clampToGround = this.clampToGround ?? source.clampToGround; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; + this.classificationType = + this.classificationType ?? source.classificationType; + this.zIndex = this.zIndex ?? source.zIndex; }; export default PolylineGraphics; diff --git a/packages/engine/Source/DataSources/PolylineOutlineMaterialProperty.js b/packages/engine/Source/DataSources/PolylineOutlineMaterialProperty.js index 8ca6563a6049..2d52452fb01b 100644 --- a/packages/engine/Source/DataSources/PolylineOutlineMaterialProperty.js +++ b/packages/engine/Source/DataSources/PolylineOutlineMaterialProperty.js @@ -21,7 +21,7 @@ const defaultOutlineWidth = 1.0; * @param {Property|number} [options.outlineWidth=1.0] A numeric Property specifying the width of the outline, in pixels. */ function PolylineOutlineMaterialProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._color = undefined; diff --git a/packages/engine/Source/DataSources/PolylineVisualizer.js b/packages/engine/Source/DataSources/PolylineVisualizer.js index 8cf4745b0f73..99c96065337d 100644 --- a/packages/engine/Source/DataSources/PolylineVisualizer.js +++ b/packages/engine/Source/DataSources/PolylineVisualizer.js @@ -1,7 +1,6 @@ import AssociativeArray from "../Core/AssociativeArray.js"; import BoundingSphere from "../Core/BoundingSphere.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import ClassificationType from "../Scene/ClassificationType.js"; @@ -89,8 +88,8 @@ function PolylineVisualizer( Check.defined("entityCollection", entityCollection); //>>includeEnd('debug'); - groundPrimitives = defaultValue(groundPrimitives, scene.groundPrimitives); - primitives = defaultValue(primitives, scene.primitives); + groundPrimitives = groundPrimitives ?? scene.groundPrimitives; + primitives = primitives ?? scene.primitives; this._scene = scene; this._primitives = primitives; diff --git a/packages/engine/Source/DataSources/PolylineVolumeGraphics.js b/packages/engine/Source/DataSources/PolylineVolumeGraphics.js index dc4abc23d478..98bf80f7bf7d 100644 --- a/packages/engine/Source/DataSources/PolylineVolumeGraphics.js +++ b/packages/engine/Source/DataSources/PolylineVolumeGraphics.js @@ -63,7 +63,7 @@ function PolylineVolumeGraphics(options) { this._distanceDisplayCondition = undefined; this._distanceDisplayConditionSubsription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(PolylineVolumeGraphics.prototype, { @@ -218,20 +218,18 @@ PolylineVolumeGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.positions = defaultValue(this.positions, source.positions); - this.shape = defaultValue(this.shape, source.shape); - this.cornerType = defaultValue(this.cornerType, source.cornerType); - this.granularity = defaultValue(this.granularity, source.granularity); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); + this.show = this.show ?? source.show; + this.positions = this.positions ?? source.positions; + this.shape = this.shape ?? source.shape; + this.cornerType = this.cornerType ?? source.cornerType; + this.granularity = this.granularity ?? source.granularity; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; }; export default PolylineVolumeGraphics; diff --git a/packages/engine/Source/DataSources/PositionPropertyArray.js b/packages/engine/Source/DataSources/PositionPropertyArray.js index b8bdc8394731..13ffe88103df 100644 --- a/packages/engine/Source/DataSources/PositionPropertyArray.js +++ b/packages/engine/Source/DataSources/PositionPropertyArray.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -21,7 +20,7 @@ function PositionPropertyArray(value, referenceFrame) { this._value = undefined; this._definitionChanged = new Event(); this._eventHelper = new EventHelper(); - this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED; this.setValue(value); } diff --git a/packages/engine/Source/DataSources/Property.js b/packages/engine/Source/DataSources/Property.js index 2833df6cef06..dadc855e963b 100644 --- a/packages/engine/Source/DataSources/Property.js +++ b/packages/engine/Source/DataSources/Property.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -113,7 +112,7 @@ Property.getValueOrUndefined = function (property, time, result) { */ Property.getValueOrDefault = function (property, time, valueDefault, result) { return defined(property) - ? defaultValue(property.getValue(time, result), valueDefault) + ? (property.getValue(time, result) ?? valueDefault) : valueDefault; }; diff --git a/packages/engine/Source/DataSources/PropertyBag.js b/packages/engine/Source/DataSources/PropertyBag.js index 01f2e34efae0..1dff6f3fa838 100644 --- a/packages/engine/Source/DataSources/PropertyBag.js +++ b/packages/engine/Source/DataSources/PropertyBag.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -121,7 +120,7 @@ PropertyBag.prototype.addProperty = function ( createPropertyDescriptor( propertyName, true, - defaultValue(createPropertyCallback, createConstantProperty), + createPropertyCallback ?? createConstantProperty, ), ); diff --git a/packages/engine/Source/DataSources/RectangleGraphics.js b/packages/engine/Source/DataSources/RectangleGraphics.js index b2cedf2fd4b9..0aee4136b271 100644 --- a/packages/engine/Source/DataSources/RectangleGraphics.js +++ b/packages/engine/Source/DataSources/RectangleGraphics.js @@ -82,7 +82,7 @@ function RectangleGraphics(options) { this._zIndex = undefined; this._zIndexSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(RectangleGraphics.prototype, { @@ -292,38 +292,26 @@ RectangleGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.coordinates = defaultValue(this.coordinates, source.coordinates); - this.height = defaultValue(this.height, source.height); - this.heightReference = defaultValue( - this.heightReference, - source.heightReference, - ); - this.extrudedHeight = defaultValue( - this.extrudedHeight, - source.extrudedHeight, - ); - this.extrudedHeightReference = defaultValue( - this.extrudedHeightReference, - source.extrudedHeightReference, - ); - this.rotation = defaultValue(this.rotation, source.rotation); - this.stRotation = defaultValue(this.stRotation, source.stRotation); - this.granularity = defaultValue(this.granularity, source.granularity); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); - this.classificationType = defaultValue( - this.classificationType, - source.classificationType, - ); - this.zIndex = defaultValue(this.zIndex, source.zIndex); + this.show = this.show ?? source.show; + this.coordinates = this.coordinates ?? source.coordinates; + this.height = this.height ?? source.height; + this.heightReference = this.heightReference ?? source.heightReference; + this.extrudedHeight = this.extrudedHeight ?? source.extrudedHeight; + this.extrudedHeightReference = + this.extrudedHeightReference ?? source.extrudedHeightReference; + this.rotation = this.rotation ?? source.rotation; + this.stRotation = this.stRotation ?? source.stRotation; + this.granularity = this.granularity ?? source.granularity; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; + this.classificationType = + this.classificationType ?? source.classificationType; + this.zIndex = this.zIndex ?? source.zIndex; }; export default RectangleGraphics; diff --git a/packages/engine/Source/DataSources/Rotation.js b/packages/engine/Source/DataSources/Rotation.js index 9e337dd463fb..96260e83b313 100644 --- a/packages/engine/Source/DataSources/Rotation.js +++ b/packages/engine/Source/DataSources/Rotation.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import CesiumMath from "../Core/Math.js"; @@ -56,7 +55,7 @@ const Rotation = { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex] = value; return array; @@ -77,7 +76,7 @@ const Rotation = { } //>>includeEnd('debug'); - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; return array[startingIndex]; }, @@ -105,8 +104,8 @@ const Rotation = { result = []; } - startingIndex = defaultValue(startingIndex, 0); - lastIndex = defaultValue(lastIndex, packedArray.length); + startingIndex = startingIndex ?? 0; + lastIndex = lastIndex ?? packedArray.length; let previousValue; for (let i = 0, len = lastIndex - startingIndex + 1; i < len; i++) { diff --git a/packages/engine/Source/DataSources/SampledPositionProperty.js b/packages/engine/Source/DataSources/SampledPositionProperty.js index c8cc2c53a7d6..84857990adc1 100644 --- a/packages/engine/Source/DataSources/SampledPositionProperty.js +++ b/packages/engine/Source/DataSources/SampledPositionProperty.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -20,7 +19,7 @@ import SampledProperty from "./SampledProperty.js"; * @param {number} [numberOfDerivatives=0] The number of derivatives that accompany each position; i.e. velocity, acceleration, etc... */ function SampledPositionProperty(referenceFrame, numberOfDerivatives) { - numberOfDerivatives = defaultValue(numberOfDerivatives, 0); + numberOfDerivatives = numberOfDerivatives ?? 0; let derivativeTypes; if (numberOfDerivatives > 0) { @@ -33,7 +32,7 @@ function SampledPositionProperty(referenceFrame, numberOfDerivatives) { this._numberOfDerivatives = numberOfDerivatives; this._property = new SampledProperty(Cartesian3, derivativeTypes); this._definitionChanged = new Event(); - this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED; this._property._definitionChanged.addEventListener(function () { this._definitionChanged.raiseEvent(this); diff --git a/packages/engine/Source/DataSources/SampledProperty.js b/packages/engine/Source/DataSources/SampledProperty.js index 803555188725..c9622e83c3c4 100644 --- a/packages/engine/Source/DataSources/SampledProperty.js +++ b/packages/engine/Source/DataSources/SampledProperty.js @@ -1,6 +1,5 @@ import binarySearch from "../Core/binarySearch.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -11,11 +10,11 @@ import LinearApproximation from "../Core/LinearApproximation.js"; const PackableNumber = { packedLength: 1, pack: function (value, array, startingIndex) { - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; array[startingIndex] = value; }, unpack: function (array, startingIndex, result) { - startingIndex = defaultValue(startingIndex, 0); + startingIndex = startingIndex ?? 0; return array[startingIndex]; }, }; @@ -166,10 +165,8 @@ function SampledProperty(type, derivativeTypes) { innerType = PackableNumber; } let packedLength = innerType.packedLength; - let packedInterpolationLength = defaultValue( - innerType.packedInterpolationLength, - packedLength, - ); + let packedInterpolationLength = + innerType.packedInterpolationLength ?? packedLength; let inputOrder = 0; let innerDerivativeTypes; @@ -183,10 +180,8 @@ function SampledProperty(type, derivativeTypes) { } const derivativePackedLength = derivativeType.packedLength; packedLength += derivativePackedLength; - packedInterpolationLength += defaultValue( - derivativeType.packedInterpolationLength, - derivativePackedLength, - ); + packedInterpolationLength += + derivativeType.packedInterpolationLength ?? derivativePackedLength; innerDerivativeTypes[i] = derivativeType; } inputOrder = length; diff --git a/packages/engine/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js b/packages/engine/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js index 10cf346cf058..9b946b750542 100644 --- a/packages/engine/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js +++ b/packages/engine/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js @@ -1,7 +1,6 @@ import AssociativeArray from "../Core/AssociativeArray.js"; import Color from "../Core/Color.js"; import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js"; import DistanceDisplayConditionGeometryInstanceAttribute from "../Core/DistanceDisplayConditionGeometryInstanceAttribute.js"; @@ -340,7 +339,7 @@ function StaticGroundPolylinePerMaterialBatch( this._items = []; this._orderedGroundPrimitives = orderedGroundPrimitives; this._classificationType = classificationType; - this._asynchronous = defaultValue(asynchronous, true); + this._asynchronous = asynchronous ?? true; } StaticGroundPolylinePerMaterialBatch.prototype.add = function (time, updater) { diff --git a/packages/engine/Source/DataSources/StripeMaterialProperty.js b/packages/engine/Source/DataSources/StripeMaterialProperty.js index e071a4c571e4..f9444da55f13 100644 --- a/packages/engine/Source/DataSources/StripeMaterialProperty.js +++ b/packages/engine/Source/DataSources/StripeMaterialProperty.js @@ -26,7 +26,7 @@ const defaultRepeat = 1; * @param {Property|number} [options.repeat=1] A numeric Property specifying how many times the stripes repeat. */ function StripeMaterialProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._definitionChanged = new Event(); this._orientation = undefined; diff --git a/packages/engine/Source/DataSources/TimeIntervalCollectionPositionProperty.js b/packages/engine/Source/DataSources/TimeIntervalCollectionPositionProperty.js index 80e81e17f5e7..09b547b3e095 100644 --- a/packages/engine/Source/DataSources/TimeIntervalCollectionPositionProperty.js +++ b/packages/engine/Source/DataSources/TimeIntervalCollectionPositionProperty.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -23,7 +22,7 @@ function TimeIntervalCollectionPositionProperty(referenceFrame) { TimeIntervalCollectionPositionProperty.prototype._intervalsChanged, this, ); - this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED); + this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED; } Object.defineProperties(TimeIntervalCollectionPositionProperty.prototype, { diff --git a/packages/engine/Source/DataSources/VelocityOrientationProperty.js b/packages/engine/Source/DataSources/VelocityOrientationProperty.js index 0a0ef6d2527d..3f60f74a7413 100644 --- a/packages/engine/Source/DataSources/VelocityOrientationProperty.js +++ b/packages/engine/Source/DataSources/VelocityOrientationProperty.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Ellipsoid from "../Core/Ellipsoid.js"; import Event from "../Core/Event.js"; @@ -35,7 +34,7 @@ function VelocityOrientationProperty(position, ellipsoid) { this._ellipsoid = undefined; this._definitionChanged = new Event(); - this.ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + this.ellipsoid = ellipsoid ?? Ellipsoid.default; const that = this; this._velocityVectorProperty.definitionChanged.addEventListener(function () { diff --git a/packages/engine/Source/DataSources/VelocityVectorProperty.js b/packages/engine/Source/DataSources/VelocityVectorProperty.js index a700d1e01f34..8562a5e5f06c 100644 --- a/packages/engine/Source/DataSources/VelocityVectorProperty.js +++ b/packages/engine/Source/DataSources/VelocityVectorProperty.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.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"; @@ -31,7 +30,7 @@ function VelocityVectorProperty(position, normalize) { this._position = undefined; this._subscription = undefined; this._definitionChanged = new Event(); - this._normalize = defaultValue(normalize, true); + this._normalize = normalize ?? true; this.position = position; } diff --git a/packages/engine/Source/DataSources/WallGraphics.js b/packages/engine/Source/DataSources/WallGraphics.js index 247669354a38..2b6b05fb3f00 100644 --- a/packages/engine/Source/DataSources/WallGraphics.js +++ b/packages/engine/Source/DataSources/WallGraphics.js @@ -63,7 +63,7 @@ function WallGraphics(options) { this._distanceDisplayCondition = undefined; this._distanceDisplayConditionSubscription = undefined; - this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT)); + this.merge(options ?? defaultValue.EMPTY_OBJECT); } Object.defineProperties(WallGraphics.prototype, { @@ -219,26 +219,18 @@ WallGraphics.prototype.merge = function (source) { } //>>includeEnd('debug'); - this.show = defaultValue(this.show, source.show); - this.positions = defaultValue(this.positions, source.positions); - this.minimumHeights = defaultValue( - this.minimumHeights, - source.minimumHeights, - ); - this.maximumHeights = defaultValue( - this.maximumHeights, - source.maximumHeights, - ); - this.granularity = defaultValue(this.granularity, source.granularity); - this.fill = defaultValue(this.fill, source.fill); - this.material = defaultValue(this.material, source.material); - this.outline = defaultValue(this.outline, source.outline); - this.outlineColor = defaultValue(this.outlineColor, source.outlineColor); - this.outlineWidth = defaultValue(this.outlineWidth, source.outlineWidth); - this.shadows = defaultValue(this.shadows, source.shadows); - this.distanceDisplayCondition = defaultValue( - this.distanceDisplayCondition, - source.distanceDisplayCondition, - ); + this.show = this.show ?? source.show; + this.positions = this.positions ?? source.positions; + this.minimumHeights = this.minimumHeights ?? source.minimumHeights; + this.maximumHeights = this.maximumHeights ?? source.maximumHeights; + this.granularity = this.granularity ?? source.granularity; + this.fill = this.fill ?? source.fill; + this.material = this.material ?? source.material; + this.outline = this.outline ?? source.outline; + this.outlineColor = this.outlineColor ?? source.outlineColor; + this.outlineWidth = this.outlineWidth ?? source.outlineWidth; + this.shadows = this.shadows ?? source.shadows; + this.distanceDisplayCondition = + this.distanceDisplayCondition ?? source.distanceDisplayCondition; }; export default WallGraphics; diff --git a/packages/engine/Source/DataSources/createPropertyDescriptor.js b/packages/engine/Source/DataSources/createPropertyDescriptor.js index 82b45b5d95b4..5f3051593690 100644 --- a/packages/engine/Source/DataSources/createPropertyDescriptor.js +++ b/packages/engine/Source/DataSources/createPropertyDescriptor.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import ConstantProperty from "./ConstantProperty.js"; @@ -65,8 +64,8 @@ function createPropertyDescriptor(name, configurable, createPropertyCallback) { name, `_${name.toString()}`, `_${name.toString()}Subscription`, - defaultValue(configurable, false), - defaultValue(createPropertyCallback, createConstantProperty), + configurable ?? false, + createPropertyCallback ?? createConstantProperty, ); } export default createPropertyDescriptor; diff --git a/packages/engine/Source/DataSources/exportKml.js b/packages/engine/Source/DataSources/exportKml.js index 3a0eff321c2b..66e3a8c08414 100644 --- a/packages/engine/Source/DataSources/exportKml.js +++ b/packages/engine/Source/DataSources/exportKml.js @@ -145,7 +145,7 @@ ValueGetter.prototype.get = function (property, defaultVal, result) { : property; } - return defaultValue(value, defaultVal); + return value ?? defaultVal; }; ValueGetter.prototype.getColor = function (property, defaultVal) { @@ -274,9 +274,9 @@ IdManager.prototype.get = function (id) { * */ function exportKml(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const entities = options.entities; - const kmz = defaultValue(options.kmz, false); + const kmz = options.kmz ?? false; //>>includeStart('debug', pragmas.debug); if (!defined(entities)) { @@ -372,11 +372,8 @@ exportKml._createState = function (options) { const time = defined(options.time) ? options.time : entityAvailability.start; // Figure out how we will sample dynamic position properties - let defaultAvailability = defaultValue( - options.defaultAvailability, - entityAvailability, - ); - const sampleDuration = defaultValue(options.sampleDuration, 60); + let defaultAvailability = options.defaultAvailability ?? entityAvailability; + const sampleDuration = options.sampleDuration ?? 60; // Make sure we don't have infinite availability if we need to sample if (defaultAvailability.start === Iso8601.MINIMUM_VALUE) { @@ -405,7 +402,7 @@ exportKml._createState = function (options) { const kmlDoc = document.implementation.createDocument(kmlNamespace, "kml"); return { kmlDoc: kmlDoc, - ellipsoid: defaultValue(options.ellipsoid, Ellipsoid.default), + ellipsoid: options.ellipsoid ?? Ellipsoid.default, idManager: new IdManager(), styleCache: styleCache, externalFileHandler: externalFileHandler, @@ -591,7 +588,7 @@ function createPoint(state, entity, geometries, styles) { const ellipsoid = state.ellipsoid; const valueGetter = state.valueGetter; - const pointGraphics = defaultValue(entity.billboard, entity.point); + const pointGraphics = entity.billboard ?? entity.point; if (!defined(pointGraphics) && !defined(entity.path)) { return; } @@ -642,7 +639,7 @@ function createTracks(state, entity, pointGraphics, geometries, styles) { intervals = entityPositionProperty.intervals; useEntityPositionProperty = false; } else { - intervals = defaultValue(entity.availability, state.defaultAvailability); + intervals = entity.availability ?? state.defaultAvailability; } const isModel = pointGraphics instanceof ModelGraphics; @@ -888,7 +885,7 @@ function createIconStyleFromBillboard(state, billboardGraphics) { const pixelOffset = valueGetter.get(billboardGraphics.pixelOffset); if (defined(pixelOffset)) { - scale = defaultValue(scale, 1.0); + scale = scale ?? 1.0; Cartesian2.divideByScalar(pixelOffset, scale, pixelOffset); @@ -1475,7 +1472,7 @@ function createBasicElementWithText( elementValue, namespace, ) { - elementValue = defaultValue(elementValue, ""); + elementValue = elementValue ?? ""; if (typeof elementValue === "boolean") { elementValue = elementValue ? "1" : "0"; diff --git a/packages/engine/Source/Renderer/Buffer.js b/packages/engine/Source/Renderer/Buffer.js index 27c1be7a8aa6..6c4364a560c0 100644 --- a/packages/engine/Source/Renderer/Buffer.js +++ b/packages/engine/Source/Renderer/Buffer.js @@ -12,7 +12,7 @@ import BufferUsage from "./BufferUsage.js"; * @private */ function Buffer(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); @@ -243,7 +243,7 @@ Buffer.prototype._getBuffer = function () { }; Buffer.prototype.copyFromArrayView = function (arrayView, offsetInBytes) { - offsetInBytes = defaultValue(offsetInBytes, 0); + offsetInBytes = offsetInBytes ?? 0; //>>includeStart('debug', pragmas.debug); Check.defined("arrayView", arrayView); @@ -341,8 +341,8 @@ Buffer.prototype.getBufferData = function ( destinationOffset, length, ) { - sourceOffset = defaultValue(sourceOffset, 0); - destinationOffset = defaultValue(destinationOffset, 0); + sourceOffset = sourceOffset ?? 0; + destinationOffset = destinationOffset ?? 0; //>>includeStart('debug', pragmas.debug); if (!this._webgl2) { diff --git a/packages/engine/Source/Renderer/ClearCommand.js b/packages/engine/Source/Renderer/ClearCommand.js index 2bd832ddea92..2ecb06e77ca4 100644 --- a/packages/engine/Source/Renderer/ClearCommand.js +++ b/packages/engine/Source/Renderer/ClearCommand.js @@ -8,7 +8,7 @@ import defaultValue from "../Core/defaultValue.js"; * @constructor */ function ClearCommand(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The value to clear the color buffer to. When undefined, the color buffer is not cleared. diff --git a/packages/engine/Source/Renderer/ComputeCommand.js b/packages/engine/Source/Renderer/ComputeCommand.js index 0979b648c908..2eac2fd373ff 100644 --- a/packages/engine/Source/Renderer/ComputeCommand.js +++ b/packages/engine/Source/Renderer/ComputeCommand.js @@ -8,7 +8,7 @@ import Pass from "./Pass.js"; * @constructor */ function ComputeCommand(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The vertex array. If none is provided, a viewport quad will be used. @@ -84,7 +84,7 @@ function ComputeCommand(options) { * @type {boolean} * @default false */ - this.persists = defaultValue(options.persists, false); + this.persists = options.persists ?? false; /** * The pass when to render. Always compute pass. diff --git a/packages/engine/Source/Renderer/Context.js b/packages/engine/Source/Renderer/Context.js index abfe2a5dd59a..e7f085bbc709 100644 --- a/packages/engine/Source/Renderer/Context.js +++ b/packages/engine/Source/Renderer/Context.js @@ -48,15 +48,13 @@ function Context(canvas, options) { requestWebgl1, webgl: webglOptions = {}, allowTextureFilterAnisotropic = true, - } = defaultValue(options, {}); + } = options ?? {}; // Override select WebGL defaults - webglOptions.alpha = defaultValue(webglOptions.alpha, false); // WebGL default is true - webglOptions.stencil = defaultValue(webglOptions.stencil, true); // WebGL default is false - webglOptions.powerPreference = defaultValue( - webglOptions.powerPreference, - "high-performance", - ); // WebGL default is "default" + webglOptions.alpha = webglOptions.alpha ?? false; // WebGL default is true + webglOptions.stencil = webglOptions.stencil ?? true; // WebGL default is false + webglOptions.powerPreference = + webglOptions.powerPreference ?? "high-performance"; // WebGL default is "default" const glContext = defined(getWebGLStub) ? getWebGLStub(canvas, webglOptions) @@ -1241,8 +1239,8 @@ function bindFramebuffer(context, framebuffer) { const defaultClearCommand = new ClearCommand(); Context.prototype.clear = function (clearCommand, passState) { - clearCommand = defaultValue(clearCommand, defaultClearCommand); - passState = defaultValue(passState, this._defaultPassState); + clearCommand = clearCommand ?? defaultClearCommand; + passState = passState ?? this._defaultPassState; const gl = this._gl; let bitmask = 0; @@ -1275,14 +1273,11 @@ Context.prototype.clear = function (clearCommand, passState) { bitmask |= gl.STENCIL_BUFFER_BIT; } - const rs = defaultValue(clearCommand.renderState, this._defaultRenderState); + const rs = clearCommand.renderState ?? this._defaultRenderState; applyRenderState(this, rs, passState, true); // The command's framebuffer takes presidence over the pass' framebuffer, e.g., for off-screen rendering. - const framebuffer = defaultValue( - clearCommand.framebuffer, - passState.framebuffer, - ); + const framebuffer = clearCommand.framebuffer ?? passState.framebuffer; bindFramebuffer(this, framebuffer); gl.clear(bitmask); @@ -1343,7 +1338,7 @@ function continueDraw(context, drawCommand, shaderProgram, uniformMap) { } //>>includeEnd('debug'); - context._us.model = defaultValue(drawCommand._modelMatrix, Matrix4.IDENTITY); + context._us.model = drawCommand._modelMatrix ?? Matrix4.IDENTITY; shaderProgram._setUniforms( uniformMap, context._us, @@ -1408,18 +1403,12 @@ Context.prototype.draw = function ( Check.defined("drawCommand.shaderProgram", drawCommand._shaderProgram); //>>includeEnd('debug'); - passState = defaultValue(passState, this._defaultPassState); + passState = passState ?? this._defaultPassState; // The command's framebuffer takes precedence over the pass' framebuffer, e.g., for off-screen rendering. - const framebuffer = defaultValue( - drawCommand._framebuffer, - passState.framebuffer, - ); - const renderState = defaultValue( - drawCommand._renderState, - this._defaultRenderState, - ); - shaderProgram = defaultValue(shaderProgram, drawCommand._shaderProgram); - uniformMap = defaultValue(uniformMap, drawCommand._uniformMap); + const framebuffer = drawCommand._framebuffer ?? passState.framebuffer; + const renderState = drawCommand._renderState ?? this._defaultRenderState; + shaderProgram = shaderProgram ?? drawCommand._shaderProgram; + uniformMap = uniformMap ?? drawCommand._uniformMap; beginDraw(this, framebuffer, passState, shaderProgram, renderState); continueDraw(this, drawCommand, shaderProgram, uniformMap); @@ -1460,11 +1449,11 @@ Context.prototype.endFrame = function () { Context.prototype.readPixels = function (readState) { const gl = this._gl; - readState = defaultValue(readState, defaultValue.EMPTY_OBJECT); - const x = Math.max(defaultValue(readState.x, 0), 0); - const y = Math.max(defaultValue(readState.y, 0), 0); - const width = defaultValue(readState.width, gl.drawingBufferWidth); - const height = defaultValue(readState.height, gl.drawingBufferHeight); + readState = readState ?? defaultValue.EMPTY_OBJECT; + const x = Math.max(readState.x ?? 0, 0); + const y = Math.max(readState.y ?? 0, 0); + const width = readState.width ?? gl.drawingBufferWidth; + const height = readState.height ?? gl.drawingBufferHeight; const framebuffer = readState.framebuffer; //>>includeStart('debug', pragmas.debug); @@ -1546,7 +1535,7 @@ Context.prototype.createViewportQuadCommand = function ( fragmentShaderSource, overrides, ) { - overrides = defaultValue(overrides, defaultValue.EMPTY_OBJECT); + overrides = overrides ?? defaultValue.EMPTY_OBJECT; return new DrawCommand({ vertexArray: this.getViewportQuadVertexArray(), diff --git a/packages/engine/Source/Renderer/CubeMap.js b/packages/engine/Source/Renderer/CubeMap.js index 7526ed2b42a4..d007e7df85ac 100644 --- a/packages/engine/Source/Renderer/CubeMap.js +++ b/packages/engine/Source/Renderer/CubeMap.js @@ -69,7 +69,7 @@ import VertexArray from "./VertexArray.js"; * @private */ function CubeMap(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); @@ -314,7 +314,7 @@ CubeMap.faceNames = function () { * @private */ function loadFace(cubeMapFace, source, mipLevel) { - mipLevel = defaultValue(mipLevel, 0); + mipLevel = mipLevel ?? 0; const targetFace = cubeMapFace._targetFace; const size = Math.max(Math.floor(cubeMapFace._size / 2 ** mipLevel), 1); const pixelFormat = cubeMapFace._pixelFormat; @@ -572,7 +572,7 @@ CubeMap.prototype.loadMipmaps = function (source, skipColorSpaceConversion) { } //>>includeEnd('debug'); - skipColorSpaceConversion = defaultValue(skipColorSpaceConversion, false); + skipColorSpaceConversion = skipColorSpaceConversion ?? false; const gl = this._context._gl; const texture = this._texture; const textureTarget = this._textureTarget; @@ -622,7 +622,7 @@ CubeMap.prototype.loadMipmaps = function (source, skipColorSpaceConversion) { * }); */ CubeMap.prototype.generateMipmap = function (hint) { - hint = defaultValue(hint, MipmapHint.DONT_CARE); + hint = hint ?? MipmapHint.DONT_CARE; //>>includeStart('debug', pragmas.debug); if (this._size > 1 && !CesiumMath.isPowerOfTwo(this._size)) { diff --git a/packages/engine/Source/Renderer/CubeMapFace.js b/packages/engine/Source/Renderer/CubeMapFace.js index fcd31230b240..e5aad54c06ec 100644 --- a/packages/engine/Source/Renderer/CubeMapFace.js +++ b/packages/engine/Source/Renderer/CubeMapFace.js @@ -1,5 +1,4 @@ import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import PixelFormat from "../Core/PixelFormat.js"; @@ -273,12 +272,12 @@ CubeMapFace.prototype.copyFromFramebuffer = function ( width, height, ) { - xOffset = defaultValue(xOffset, 0); - yOffset = defaultValue(yOffset, 0); - framebufferXOffset = defaultValue(framebufferXOffset, 0); - framebufferYOffset = defaultValue(framebufferYOffset, 0); - width = defaultValue(width, this._size); - height = defaultValue(height, this._size); + xOffset = xOffset ?? 0; + yOffset = yOffset ?? 0; + framebufferXOffset = framebufferXOffset ?? 0; + framebufferYOffset = framebufferYOffset ?? 0; + width = width ?? this._size; + height = height ?? this._size; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals("xOffset", xOffset, 0); diff --git a/packages/engine/Source/Renderer/DrawCommand.js b/packages/engine/Source/Renderer/DrawCommand.js index acdcaccc317e..6c1cc41331e6 100644 --- a/packages/engine/Source/Renderer/DrawCommand.js +++ b/packages/engine/Source/Renderer/DrawCommand.js @@ -22,19 +22,16 @@ const Flags = { * @private */ function DrawCommand(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._boundingVolume = options.boundingVolume; this._orientedBoundingBox = options.orientedBoundingBox; this._modelMatrix = options.modelMatrix; - this._primitiveType = defaultValue( - options.primitiveType, - PrimitiveType.TRIANGLES, - ); + this._primitiveType = options.primitiveType ?? PrimitiveType.TRIANGLES; this._vertexArray = options.vertexArray; this._count = options.count; - this._offset = defaultValue(options.offset, 0); - this._instanceCount = defaultValue(options.instanceCount, 0); + this._offset = options.offset ?? 0; + this._instanceCount = options.instanceCount ?? 0; this._shaderProgram = options.shaderProgram; this._uniformMap = options.uniformMap; this._renderState = options.renderState; @@ -48,23 +45,15 @@ function DrawCommand(options) { // Set initial flags. this._flags = 0; - this.cull = defaultValue(options.cull, true); - this.occlude = defaultValue(options.occlude, true); - this.executeInClosestFrustum = defaultValue( - options.executeInClosestFrustum, - false, - ); - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); - this.castShadows = defaultValue(options.castShadows, false); - this.receiveShadows = defaultValue(options.receiveShadows, false); - this.pickOnly = defaultValue(options.pickOnly, false); - this.depthForTranslucentClassification = defaultValue( - options.depthForTranslucentClassification, - false, - ); + this.cull = options.cull ?? true; + this.occlude = options.occlude ?? true; + this.executeInClosestFrustum = options.executeInClosestFrustum ?? false; + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; + this.castShadows = options.castShadows ?? false; + this.receiveShadows = options.receiveShadows ?? false; + this.pickOnly = options.pickOnly ?? false; + this.depthForTranslucentClassification = + options.depthForTranslucentClassification ?? false; this.dirty = true; this.lastDirtyTime = 0; diff --git a/packages/engine/Source/Renderer/Framebuffer.js b/packages/engine/Source/Renderer/Framebuffer.js index 36745f24cb5d..1fda50dc83ec 100644 --- a/packages/engine/Source/Renderer/Framebuffer.js +++ b/packages/engine/Source/Renderer/Framebuffer.js @@ -82,7 +82,7 @@ function attachRenderbuffer(framebuffer, attachment, renderbuffer) { * @constructor */ function Framebuffer(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const context = options.context; //>>includeStart('debug', pragmas.debug); @@ -115,7 +115,7 @@ function Framebuffer(options) { * * @see Framebuffer#destroy */ - this.destroyAttachments = defaultValue(options.destroyAttachments, true); + this.destroyAttachments = options.destroyAttachments ?? true; // Throw if a texture and renderbuffer are attached to the same point. This won't // cause a WebGL error (because only one will be attached), but is likely a developer error. diff --git a/packages/engine/Source/Renderer/FramebufferManager.js b/packages/engine/Source/Renderer/FramebufferManager.js index d9e5a8a64493..628cfdde6a13 100644 --- a/packages/engine/Source/Renderer/FramebufferManager.js +++ b/packages/engine/Source/Renderer/FramebufferManager.js @@ -32,20 +32,14 @@ import PixelFormat from "../Core/PixelFormat.js"; * @constructor */ function FramebufferManager(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - this._numSamples = defaultValue(options.numSamples, 1); - this._colorAttachmentsLength = defaultValue( - options.colorAttachmentsLength, - 1, - ); - - this._color = defaultValue(options.color, true); - this._depth = defaultValue(options.depth, false); - this._depthStencil = defaultValue(options.depthStencil, false); - this._supportsDepthTexture = defaultValue( - options.supportsDepthTexture, - false, - ); + options = options ?? defaultValue.EMPTY_OBJECT; + this._numSamples = options.numSamples ?? 1; + this._colorAttachmentsLength = options.colorAttachmentsLength ?? 1; + + this._color = options.color ?? true; + this._depth = options.depth ?? false; + this._depthStencil = options.depthStencil ?? false; + this._supportsDepthTexture = options.supportsDepthTexture ?? false; //>>includeStart('debug', pragmas.debug); if (!this._color && !this._depth && !this._depthStencil) { throw new DeveloperError( @@ -59,14 +53,8 @@ function FramebufferManager(options) { } //>>includeEnd('debug'); - this._createColorAttachments = defaultValue( - options.createColorAttachments, - true, - ); - this._createDepthAttachments = defaultValue( - options.createDepthAttachments, - true, - ); + this._createColorAttachments = options.createColorAttachments ?? true; + this._createDepthAttachments = options.createDepthAttachments ?? true; this._pixelDatatype = options.pixelDatatype; this._pixelFormat = options.pixelFormat; @@ -118,7 +106,7 @@ FramebufferManager.prototype.isDirty = function ( pixelDatatype, pixelFormat, ) { - numSamples = defaultValue(numSamples, 1); + numSamples = numSamples ?? 1; const dimensionChanged = this._width !== width || this._height !== height; const samplesChanged = this._numSamples !== numSamples; const pixelChanged = @@ -152,17 +140,15 @@ FramebufferManager.prototype.update = function ( throw new DeveloperError("width and height must be defined."); } //>>includeEnd('debug'); - numSamples = context.msaa ? defaultValue(numSamples, 1) : 1; - pixelDatatype = defaultValue( - pixelDatatype, - this._color - ? defaultValue(this._pixelDatatype, PixelDatatype.UNSIGNED_BYTE) - : undefined, - ); - pixelFormat = defaultValue( - pixelFormat, - this._color ? defaultValue(this._pixelFormat, PixelFormat.RGBA) : undefined, - ); + numSamples = context.msaa ? (numSamples ?? 1) : 1; + pixelDatatype = + pixelDatatype ?? + (this._color + ? (this._pixelDatatype ?? PixelDatatype.UNSIGNED_BYTE) + : undefined); + pixelFormat = + pixelFormat ?? + (this._color ? (this._pixelFormat ?? PixelFormat.RGBA) : undefined); if (this.isDirty(width, height, numSamples, pixelDatatype, pixelFormat)) { this.destroy(); @@ -274,7 +260,7 @@ FramebufferManager.prototype.update = function ( }; FramebufferManager.prototype.getColorTexture = function (index) { - index = defaultValue(index, 0); + index = index ?? 0; //>>includeStart('debug', pragmas.debug); if (index >= this._colorAttachmentsLength) { throw new DeveloperError( @@ -286,7 +272,7 @@ FramebufferManager.prototype.getColorTexture = function (index) { }; FramebufferManager.prototype.setColorTexture = function (texture, index) { - index = defaultValue(index, 0); + index = index ?? 0; //>>includeStart('debug', pragmas.debug); if (this._createColorAttachments) { throw new DeveloperError( @@ -304,7 +290,7 @@ FramebufferManager.prototype.setColorTexture = function (texture, index) { }; FramebufferManager.prototype.getColorRenderbuffer = function (index) { - index = defaultValue(index, 0); + index = index ?? 0; //>>includeStart('debug', pragmas.debug); if (index >= this._colorAttachmentsLength) { throw new DeveloperError( @@ -319,7 +305,7 @@ FramebufferManager.prototype.setColorRenderbuffer = function ( renderbuffer, index, ) { - index = defaultValue(index, 0); + index = index ?? 0; //>>includeStart('debug', pragmas.debug); if (this._createColorAttachments) { throw new DeveloperError( diff --git a/packages/engine/Source/Renderer/MultisampleFramebuffer.js b/packages/engine/Source/Renderer/MultisampleFramebuffer.js index 7990b5f1abfa..4ede3f667bcc 100644 --- a/packages/engine/Source/Renderer/MultisampleFramebuffer.js +++ b/packages/engine/Source/Renderer/MultisampleFramebuffer.js @@ -29,7 +29,7 @@ import Framebuffer from "./Framebuffer.js"; * @constructor */ function MultisampleFramebuffer(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { context, diff --git a/packages/engine/Source/Renderer/RenderState.js b/packages/engine/Source/Renderer/RenderState.js index a4a7d8f863d3..73b0066467d4 100644 --- a/packages/engine/Source/Renderer/RenderState.js +++ b/packages/engine/Source/Renderer/RenderState.js @@ -89,122 +89,94 @@ function validateStencilOperation(stencilOperation) { * @private */ function RenderState(renderState) { - const rs = defaultValue(renderState, defaultValue.EMPTY_OBJECT); - const cull = defaultValue(rs.cull, defaultValue.EMPTY_OBJECT); - const polygonOffset = defaultValue( - rs.polygonOffset, - defaultValue.EMPTY_OBJECT, - ); - const scissorTest = defaultValue(rs.scissorTest, defaultValue.EMPTY_OBJECT); - const scissorTestRectangle = defaultValue( - scissorTest.rectangle, - defaultValue.EMPTY_OBJECT, - ); - const depthRange = defaultValue(rs.depthRange, defaultValue.EMPTY_OBJECT); - const depthTest = defaultValue(rs.depthTest, defaultValue.EMPTY_OBJECT); - const colorMask = defaultValue(rs.colorMask, defaultValue.EMPTY_OBJECT); - const blending = defaultValue(rs.blending, defaultValue.EMPTY_OBJECT); - const blendingColor = defaultValue(blending.color, defaultValue.EMPTY_OBJECT); - const stencilTest = defaultValue(rs.stencilTest, defaultValue.EMPTY_OBJECT); - const stencilTestFrontOperation = defaultValue( - stencilTest.frontOperation, - defaultValue.EMPTY_OBJECT, - ); - const stencilTestBackOperation = defaultValue( - stencilTest.backOperation, - defaultValue.EMPTY_OBJECT, - ); - const sampleCoverage = defaultValue( - rs.sampleCoverage, - defaultValue.EMPTY_OBJECT, - ); + const rs = renderState ?? defaultValue.EMPTY_OBJECT; + const cull = rs.cull ?? defaultValue.EMPTY_OBJECT; + const polygonOffset = rs.polygonOffset ?? defaultValue.EMPTY_OBJECT; + const scissorTest = rs.scissorTest ?? defaultValue.EMPTY_OBJECT; + const scissorTestRectangle = + scissorTest.rectangle ?? defaultValue.EMPTY_OBJECT; + const depthRange = rs.depthRange ?? defaultValue.EMPTY_OBJECT; + const depthTest = rs.depthTest ?? defaultValue.EMPTY_OBJECT; + const colorMask = rs.colorMask ?? defaultValue.EMPTY_OBJECT; + const blending = rs.blending ?? defaultValue.EMPTY_OBJECT; + const blendingColor = blending.color ?? defaultValue.EMPTY_OBJECT; + const stencilTest = rs.stencilTest ?? defaultValue.EMPTY_OBJECT; + const stencilTestFrontOperation = + stencilTest.frontOperation ?? defaultValue.EMPTY_OBJECT; + const stencilTestBackOperation = + stencilTest.backOperation ?? defaultValue.EMPTY_OBJECT; + const sampleCoverage = rs.sampleCoverage ?? defaultValue.EMPTY_OBJECT; const viewport = rs.viewport; - this.frontFace = defaultValue(rs.frontFace, WindingOrder.COUNTER_CLOCKWISE); + this.frontFace = rs.frontFace ?? WindingOrder.COUNTER_CLOCKWISE; this.cull = { - enabled: defaultValue(cull.enabled, false), - face: defaultValue(cull.face, WebGLConstants.BACK), + enabled: cull.enabled ?? false, + face: cull.face ?? WebGLConstants.BACK, }; - this.lineWidth = defaultValue(rs.lineWidth, 1.0); + this.lineWidth = rs.lineWidth ?? 1.0; this.polygonOffset = { - enabled: defaultValue(polygonOffset.enabled, false), - factor: defaultValue(polygonOffset.factor, 0), - units: defaultValue(polygonOffset.units, 0), + enabled: polygonOffset.enabled ?? false, + factor: polygonOffset.factor ?? 0, + units: polygonOffset.units ?? 0, }; this.scissorTest = { - enabled: defaultValue(scissorTest.enabled, false), + enabled: scissorTest.enabled ?? false, rectangle: BoundingRectangle.clone(scissorTestRectangle), }; this.depthRange = { - near: defaultValue(depthRange.near, 0), - far: defaultValue(depthRange.far, 1), + near: depthRange.near ?? 0, + far: depthRange.far ?? 1, }; this.depthTest = { - enabled: defaultValue(depthTest.enabled, false), - func: defaultValue(depthTest.func, WebGLConstants.LESS), // func, because function is a JavaScript keyword + enabled: depthTest.enabled ?? false, + func: depthTest.func ?? WebGLConstants.LESS, // func, because function is a JavaScript keyword }; this.colorMask = { - red: defaultValue(colorMask.red, true), - green: defaultValue(colorMask.green, true), - blue: defaultValue(colorMask.blue, true), - alpha: defaultValue(colorMask.alpha, true), + red: colorMask.red ?? true, + green: colorMask.green ?? true, + blue: colorMask.blue ?? true, + alpha: colorMask.alpha ?? true, }; - this.depthMask = defaultValue(rs.depthMask, true); - this.stencilMask = defaultValue(rs.stencilMask, ~0); + this.depthMask = rs.depthMask ?? true; + this.stencilMask = rs.stencilMask ?? ~0; this.blending = { - enabled: defaultValue(blending.enabled, false), + enabled: blending.enabled ?? false, color: new Color( - defaultValue(blendingColor.red, 0.0), - defaultValue(blendingColor.green, 0.0), - defaultValue(blendingColor.blue, 0.0), - defaultValue(blendingColor.alpha, 0.0), - ), - equationRgb: defaultValue(blending.equationRgb, WebGLConstants.FUNC_ADD), - equationAlpha: defaultValue( - blending.equationAlpha, - WebGLConstants.FUNC_ADD, - ), - functionSourceRgb: defaultValue( - blending.functionSourceRgb, - WebGLConstants.ONE, - ), - functionSourceAlpha: defaultValue( - blending.functionSourceAlpha, - WebGLConstants.ONE, - ), - functionDestinationRgb: defaultValue( - blending.functionDestinationRgb, - WebGLConstants.ZERO, - ), - functionDestinationAlpha: defaultValue( - blending.functionDestinationAlpha, - WebGLConstants.ZERO, + blendingColor.red ?? 0.0, + blendingColor.green ?? 0.0, + blendingColor.blue ?? 0.0, + blendingColor.alpha ?? 0.0, ), + equationRgb: blending.equationRgb ?? WebGLConstants.FUNC_ADD, + equationAlpha: blending.equationAlpha ?? WebGLConstants.FUNC_ADD, + functionSourceRgb: blending.functionSourceRgb ?? WebGLConstants.ONE, + functionSourceAlpha: blending.functionSourceAlpha ?? WebGLConstants.ONE, + functionDestinationRgb: + blending.functionDestinationRgb ?? WebGLConstants.ZERO, + functionDestinationAlpha: + blending.functionDestinationAlpha ?? WebGLConstants.ZERO, }; this.stencilTest = { - enabled: defaultValue(stencilTest.enabled, false), - frontFunction: defaultValue( - stencilTest.frontFunction, - WebGLConstants.ALWAYS, - ), - backFunction: defaultValue(stencilTest.backFunction, WebGLConstants.ALWAYS), - reference: defaultValue(stencilTest.reference, 0), - mask: defaultValue(stencilTest.mask, ~0), + enabled: stencilTest.enabled ?? false, + frontFunction: stencilTest.frontFunction ?? WebGLConstants.ALWAYS, + backFunction: stencilTest.backFunction ?? WebGLConstants.ALWAYS, + reference: stencilTest.reference ?? 0, + mask: stencilTest.mask ?? ~0, frontOperation: { - fail: defaultValue(stencilTestFrontOperation.fail, WebGLConstants.KEEP), - zFail: defaultValue(stencilTestFrontOperation.zFail, WebGLConstants.KEEP), - zPass: defaultValue(stencilTestFrontOperation.zPass, WebGLConstants.KEEP), + fail: stencilTestFrontOperation.fail ?? WebGLConstants.KEEP, + zFail: stencilTestFrontOperation.zFail ?? WebGLConstants.KEEP, + zPass: stencilTestFrontOperation.zPass ?? WebGLConstants.KEEP, }, backOperation: { - fail: defaultValue(stencilTestBackOperation.fail, WebGLConstants.KEEP), - zFail: defaultValue(stencilTestBackOperation.zFail, WebGLConstants.KEEP), - zPass: defaultValue(stencilTestBackOperation.zPass, WebGLConstants.KEEP), + fail: stencilTestBackOperation.fail ?? WebGLConstants.KEEP, + zFail: stencilTestBackOperation.zFail ?? WebGLConstants.KEEP, + zPass: stencilTestBackOperation.zPass ?? WebGLConstants.KEEP, }, }; this.sampleCoverage = { - enabled: defaultValue(sampleCoverage.enabled, false), - value: defaultValue(sampleCoverage.value, 1.0), - invert: defaultValue(sampleCoverage.invert, false), + enabled: sampleCoverage.enabled ?? false, + value: sampleCoverage.value ?? 1.0, + invert: sampleCoverage.invert ?? false, }; this.viewport = defined(viewport) ? new BoundingRectangle( @@ -737,7 +709,7 @@ function applySampleCoverage(gl, renderState) { const scratchViewport = new BoundingRectangle(); function applyViewport(gl, renderState, passState) { - let viewport = defaultValue(renderState.viewport, passState.viewport); + let viewport = renderState.viewport ?? passState.viewport; if (!defined(viewport)) { viewport = scratchViewport; viewport.width = passState.context.drawingBufferWidth; diff --git a/packages/engine/Source/Renderer/Renderbuffer.js b/packages/engine/Source/Renderer/Renderbuffer.js index 74f672159e20..8c8209d159cb 100644 --- a/packages/engine/Source/Renderer/Renderbuffer.js +++ b/packages/engine/Source/Renderer/Renderbuffer.js @@ -10,7 +10,7 @@ import RenderbufferFormat from "./RenderbufferFormat.js"; * @private */ function Renderbuffer(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); @@ -20,12 +20,12 @@ function Renderbuffer(options) { const gl = context._gl; const maximumRenderbufferSize = ContextLimits.maximumRenderbufferSize; - const format = defaultValue(options.format, RenderbufferFormat.RGBA4); + const format = options.format ?? RenderbufferFormat.RGBA4; const width = defined(options.width) ? options.width : gl.drawingBufferWidth; const height = defined(options.height) ? options.height : gl.drawingBufferHeight; - const numSamples = defaultValue(options.numSamples, 1); + const numSamples = options.numSamples ?? 1; //>>includeStart('debug', pragmas.debug); if (!RenderbufferFormat.validate(format)) { diff --git a/packages/engine/Source/Renderer/Sampler.js b/packages/engine/Source/Renderer/Sampler.js index 0fc66755101e..5bd2487ad111 100644 --- a/packages/engine/Source/Renderer/Sampler.js +++ b/packages/engine/Source/Renderer/Sampler.js @@ -10,7 +10,7 @@ import TextureWrap from "./TextureWrap.js"; * @private */ function Sampler(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { wrapS = TextureWrap.CLAMP_TO_EDGE, diff --git a/packages/engine/Source/Renderer/ShaderBuilder.js b/packages/engine/Source/Renderer/ShaderBuilder.js index 95fd920d5769..3f6469258d91 100644 --- a/packages/engine/Source/Renderer/ShaderBuilder.js +++ b/packages/engine/Source/Renderer/ShaderBuilder.js @@ -1,7 +1,6 @@ import Check from "../Core/Check.js"; import clone from "../Core/clone.js"; import defined from "../Core/defined.js"; -import defaultValue from "../Core/defaultValue.js"; import DeveloperError from "../Core/DeveloperError.js"; import ShaderDestination from "./ShaderDestination.js"; import ShaderProgram from "./ShaderProgram.js"; @@ -122,7 +121,7 @@ ShaderBuilder.prototype.addDefine = function (identifier, value, destination) { Check.typeOf.string("identifier", identifier); //>>includeEnd('debug'); - destination = defaultValue(destination, ShaderDestination.BOTH); + destination = destination ?? ShaderDestination.BOTH; // The ShaderSource created in build() will add the #define part let line = identifier; @@ -281,7 +280,7 @@ ShaderBuilder.prototype.addUniform = function (type, identifier, destination) { Check.typeOf.string("identifier", identifier); //>>includeEnd('debug'); - destination = defaultValue(destination, ShaderDestination.BOTH); + destination = destination ?? ShaderDestination.BOTH; const line = `uniform ${type} ${identifier};`; if (ShaderDestination.includesVertexShader(destination)) { diff --git a/packages/engine/Source/Renderer/ShaderProgram.js b/packages/engine/Source/Renderer/ShaderProgram.js index e8e180328599..00e3ad6e6112 100644 --- a/packages/engine/Source/Renderer/ShaderProgram.js +++ b/packages/engine/Source/Renderer/ShaderProgram.js @@ -63,7 +63,7 @@ function ShaderProgram(options) { } ShaderProgram.fromCache = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); @@ -73,7 +73,7 @@ ShaderProgram.fromCache = function (options) { }; ShaderProgram.replaceCache = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); diff --git a/packages/engine/Source/Renderer/ShaderSource.js b/packages/engine/Source/Renderer/ShaderSource.js index 7f72eac0afd5..2d26379de6a1 100644 --- a/packages/engine/Source/Renderer/ShaderSource.js +++ b/packages/engine/Source/Renderer/ShaderSource.js @@ -329,7 +329,7 @@ function combineShader(shaderSource, isFragmentShader, context) { * @private */ function ShaderSource(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const pickColorQualifier = options.pickColorQualifier; //>>includeStart('debug', pragmas.debug); @@ -347,7 +347,7 @@ function ShaderSource(options) { this.defines = defined(options.defines) ? options.defines.slice(0) : []; this.sources = defined(options.sources) ? options.sources.slice(0) : []; this.pickColorQualifier = pickColorQualifier; - this.includeBuiltIns = defaultValue(options.includeBuiltIns, true); + this.includeBuiltIns = options.includeBuiltIns ?? true; } ShaderSource.prototype.clone = function () { diff --git a/packages/engine/Source/Renderer/Texture.js b/packages/engine/Source/Renderer/Texture.js index 8d9135fb7764..3de89ca2655a 100644 --- a/packages/engine/Source/Renderer/Texture.js +++ b/packages/engine/Source/Renderer/Texture.js @@ -42,7 +42,7 @@ import TextureMinificationFilter from "./TextureMinificationFilter.js"; * @private */ function Texture(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); @@ -612,7 +612,7 @@ Texture.create = function (options) { * @private */ Texture.fromFramebuffer = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); @@ -985,12 +985,12 @@ Texture.prototype.copyFromFramebuffer = function ( width, height, ) { - xOffset = defaultValue(xOffset, 0); - yOffset = defaultValue(yOffset, 0); - framebufferXOffset = defaultValue(framebufferXOffset, 0); - framebufferYOffset = defaultValue(framebufferYOffset, 0); - width = defaultValue(width, this._width); - height = defaultValue(height, this._height); + xOffset = xOffset ?? 0; + yOffset = yOffset ?? 0; + framebufferXOffset = framebufferXOffset ?? 0; + framebufferYOffset = framebufferYOffset ?? 0; + width = width ?? this._width; + height = height ?? this._height; //>>includeStart('debug', pragmas.debug); if (PixelFormat.isDepthFormat(this._pixelFormat)) { @@ -1068,7 +1068,7 @@ Texture.prototype.copyFromFramebuffer = function ( * @exception {DeveloperError} This texture was destroyed, i.e., destroy() was called. */ Texture.prototype.generateMipmap = function (hint) { - hint = defaultValue(hint, MipmapHint.DONT_CARE); + hint = hint ?? MipmapHint.DONT_CARE; //>>includeStart('debug', pragmas.debug); if (PixelFormat.isDepthFormat(this._pixelFormat)) { diff --git a/packages/engine/Source/Renderer/UniformState.js b/packages/engine/Source/Renderer/UniformState.js index a1573dbd722e..6a72cc180c99 100644 --- a/packages/engine/Source/Renderer/UniformState.js +++ b/packages/engine/Source/Renderer/UniformState.js @@ -4,7 +4,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Cartesian4 from "../Core/Cartesian4.js"; import Cartographic from "../Core/Cartographic.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Ellipsoid from "../Core/Ellipsoid.js"; import EncodedCartesian3 from "../Core/EncodedCartesian3.js"; @@ -1173,7 +1172,7 @@ Object.defineProperties(UniformState.prototype, { */ ellipsoid: { get: function () { - return defaultValue(this._ellipsoid, Ellipsoid.default); + return this._ellipsoid ?? Ellipsoid.default; }, }, }); @@ -1440,7 +1439,7 @@ UniformState.prototype.update = function (frameState) { setSunAndMoonDirections(this, frameState); - const light = defaultValue(frameState.light, defaultLight); + const light = frameState.light ?? defaultLight; if (light instanceof SunLight) { this._lightDirectionWC = Cartesian3.clone( this._sunDirectionWC, @@ -1491,17 +1490,13 @@ UniformState.prototype.update = function (frameState) { : undefined; this._brdfLut = brdfLut; - this._environmentMap = defaultValue( - frameState.environmentMap, - frameState.context.defaultCubeMap, - ); + this._environmentMap = + frameState.environmentMap ?? frameState.context.defaultCubeMap; // IE 11 doesn't optimize out uniforms that are #ifdef'd out. So undefined values for the spherical harmonic // coefficients cause a crash. - this._sphericalHarmonicCoefficients = defaultValue( - frameState.sphericalHarmonicCoefficients, - EMPTY_ARRAY, - ); + this._sphericalHarmonicCoefficients = + frameState.sphericalHarmonicCoefficients ?? EMPTY_ARRAY; this._specularEnvironmentMaps = frameState.specularEnvironmentMaps; this._specularEnvironmentMapsMaximumLOD = frameState.specularEnvironmentMapsMaximumLOD; diff --git a/packages/engine/Source/Renderer/VertexArray.js b/packages/engine/Source/Renderer/VertexArray.js index a33cafc1068c..ecbd7ef2c4b7 100644 --- a/packages/engine/Source/Renderer/VertexArray.js +++ b/packages/engine/Source/Renderer/VertexArray.js @@ -88,19 +88,16 @@ function addAttribute(attributes, attribute, index, context) { // Shallow copy the attribute; we do not want to copy the vertex buffer. const attr = { - index: defaultValue(attribute.index, index), - enabled: defaultValue(attribute.enabled, true), + index: attribute.index ?? index, + enabled: attribute.enabled ?? true, vertexBuffer: attribute.vertexBuffer, value: hasValue ? attribute.value.slice(0) : undefined, componentsPerAttribute: componentsPerAttribute, - componentDatatype: defaultValue( - attribute.componentDatatype, - ComponentDatatype.FLOAT, - ), - normalize: defaultValue(attribute.normalize, false), - offsetInBytes: defaultValue(attribute.offsetInBytes, 0), - strideInBytes: defaultValue(attribute.strideInBytes, 0), - instanceDivisor: defaultValue(attribute.instanceDivisor, 0), + componentDatatype: attribute.componentDatatype ?? ComponentDatatype.FLOAT, + normalize: attribute.normalize ?? false, + offsetInBytes: attribute.offsetInBytes ?? 0, + strideInBytes: attribute.strideInBytes ?? 0, + instanceDivisor: attribute.instanceDivisor ?? 0, }; if (hasVertexBuffer) { @@ -287,7 +284,7 @@ function bind(gl, attributes, indexBuffer) { * @private */ function VertexArray(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); @@ -571,25 +568,20 @@ function interleaveAttributes(attributes) { * @see ShaderProgram */ VertexArray.fromGeometry = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.context", options.context); //>>includeEnd('debug'); const context = options.context; - const geometry = defaultValue(options.geometry, defaultValue.EMPTY_OBJECT); + const geometry = options.geometry ?? defaultValue.EMPTY_OBJECT; - const bufferUsage = defaultValue( - options.bufferUsage, - BufferUsage.DYNAMIC_DRAW, - ); + const bufferUsage = options.bufferUsage ?? BufferUsage.DYNAMIC_DRAW; - const attributeLocations = defaultValue( - options.attributeLocations, - defaultValue.EMPTY_OBJECT, - ); - const interleave = defaultValue(options.interleave, false); + const attributeLocations = + options.attributeLocations ?? defaultValue.EMPTY_OBJECT; + const interleave = options.interleave ?? false; const createdVAAttributes = options.vertexArrayAttributes; let name; diff --git a/packages/engine/Source/Renderer/VertexArrayFacade.js b/packages/engine/Source/Renderer/VertexArrayFacade.js index 4779a69c140d..120f9006dd5e 100644 --- a/packages/engine/Source/Renderer/VertexArrayFacade.js +++ b/packages/engine/Source/Renderer/VertexArrayFacade.js @@ -1,6 +1,5 @@ import Check from "../Core/Check.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -21,7 +20,7 @@ function VertexArrayFacade(context, attributes, sizeInVertices, instanced) { //>>includeEnd('debug'); const attrs = VertexArrayFacade._verifyAttributes(attributes); - sizeInVertices = defaultValue(sizeInVertices, 0); + sizeInVertices = sizeInVertices ?? 0; const precreatedAttributes = []; const attributesByUsage = {}; let attributesForUsage; @@ -86,7 +85,7 @@ function VertexArrayFacade(context, attributes, sizeInVertices, instanced) { } this._size = 0; - this._instanced = defaultValue(instanced, false); + this._instanced = instanced ?? false; this._precreated = precreatedAttributes; this._context = context; @@ -103,18 +102,15 @@ VertexArrayFacade._verifyAttributes = function (attributes) { const attribute = attributes[i]; const attr = { - index: defaultValue(attribute.index, i), - enabled: defaultValue(attribute.enabled, true), + index: attribute.index ?? i, + enabled: attribute.enabled ?? true, componentsPerAttribute: attribute.componentsPerAttribute, - componentDatatype: defaultValue( - attribute.componentDatatype, - ComponentDatatype.FLOAT, - ), - normalize: defaultValue(attribute.normalize, false), + componentDatatype: attribute.componentDatatype ?? ComponentDatatype.FLOAT, + normalize: attribute.normalize ?? false, // There will be either a vertexBuffer or an [optional] usage. vertexBuffer: attribute.vertexBuffer, - usage: defaultValue(attribute.usage, BufferUsage.STATIC_DRAW), + usage: attribute.usage ?? BufferUsage.STATIC_DRAW, }; attrs.push(attr); diff --git a/packages/engine/Source/Scene/Appearance.js b/packages/engine/Source/Scene/Appearance.js index 597e89308fd9..bed0c85e555b 100644 --- a/packages/engine/Source/Scene/Appearance.js +++ b/packages/engine/Source/Scene/Appearance.js @@ -31,7 +31,7 @@ import CullFace from "./CullFace.js"; * @demo {@link https://sandcastle.cesium.com/index.html?src=Geometry%20and%20Appearances.html|Geometry and Appearances Demo} */ function Appearance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The material used to determine the fragment color. Unlike other {@link Appearance} @@ -50,12 +50,12 @@ function Appearance(options) { * * @default true */ - this.translucent = defaultValue(options.translucent, true); + this.translucent = options.translucent ?? true; this._vertexShaderSource = options.vertexShaderSource; this._fragmentShaderSource = options.fragmentShaderSource; this._renderState = options.renderState; - this._closed = defaultValue(options.closed, false); + this._closed = options.closed ?? false; } Object.defineProperties(Appearance.prototype, { diff --git a/packages/engine/Source/Scene/ArcGisMapServerImageryProvider.js b/packages/engine/Source/Scene/ArcGisMapServerImageryProvider.js index d1b97d8f6365..585409873d1d 100644 --- a/packages/engine/Source/Scene/ArcGisMapServerImageryProvider.js +++ b/packages/engine/Source/Scene/ArcGisMapServerImageryProvider.js @@ -70,14 +70,13 @@ import DeveloperError from "../Core/DeveloperError.js"; * @param {ArcGisMapServerImageryProvider.ConstructorOptions} options An object describing initialization options */ function ImageryProviderBuilder(options) { - this.useTiles = defaultValue(options.usePreCachedTilesIfAvailable, true); + this.useTiles = options.usePreCachedTilesIfAvailable ?? true; const ellipsoid = options.ellipsoid; - this.tilingScheme = defaultValue( - options.tilingScheme, - new GeographicTilingScheme({ ellipsoid: ellipsoid }), - ); - this.rectangle = defaultValue(options.rectangle, this.tilingScheme.rectangle); + this.tilingScheme = + options.tilingScheme ?? + new GeographicTilingScheme({ ellipsoid: ellipsoid }); + this.rectangle = options.rectangle ?? this.tilingScheme.rectangle; this.ellipsoid = ellipsoid; let credit = options.credit; @@ -88,8 +87,8 @@ function ImageryProviderBuilder(options) { this.tileCredits = undefined; this.tileDiscardPolicy = options.tileDiscardPolicy; - this.tileWidth = defaultValue(options.tileWidth, 256); - this.tileHeight = defaultValue(options.tileHeight, 256); + this.tileWidth = options.tileWidth ?? 256; + this.tileHeight = options.tileHeight ?? 256; this.maximumLevel = options.maximumLevel; } @@ -300,7 +299,7 @@ async function requestMetadata(resource, imageryProviderBuilder) { */ function ArcGisMapServerImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; @@ -314,18 +313,14 @@ function ArcGisMapServerImageryProvider(options) { this._defaultMagnificationFilter = undefined; this._tileDiscardPolicy = options.tileDiscardPolicy; - this._tileWidth = defaultValue(options.tileWidth, 256); - this._tileHeight = defaultValue(options.tileHeight, 256); + this._tileWidth = options.tileWidth ?? 256; + this._tileHeight = options.tileHeight ?? 256; this._maximumLevel = options.maximumLevel; - this._tilingScheme = defaultValue( - options.tilingScheme, - new GeographicTilingScheme({ ellipsoid: options.ellipsoid }), - ); - this._useTiles = defaultValue(options.usePreCachedTilesIfAvailable, true); - this._rectangle = defaultValue( - options.rectangle, - this._tilingScheme.rectangle, - ); + this._tilingScheme = + options.tilingScheme ?? + new GeographicTilingScheme({ ellipsoid: options.ellipsoid }); + this._useTiles = options.usePreCachedTilesIfAvailable ?? true; + this._rectangle = options.rectangle ?? this._tilingScheme.rectangle; this._layers = options.layers; this._credit = options.credit; this._tileCredits = undefined; @@ -343,7 +338,7 @@ function ArcGisMapServerImageryProvider(options) { * @type {boolean} * @default true */ - this.enablePickFeatures = defaultValue(options.enablePickFeatures, true); + this.enablePickFeatures = options.enablePickFeatures ?? true; this._errorEvent = new Event(); } @@ -383,17 +378,14 @@ ArcGisMapServerImageryProvider.fromBasemapType = async function ( Check.defined("style", style); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let accessToken; let server; let warningCredit; switch (style) { case ArcGisBaseMapType.SATELLITE: { - accessToken = defaultValue( - options.token, - ArcGisMapService.defaultAccessToken, - ); + accessToken = options.token ?? ArcGisMapService.defaultAccessToken; server = Resource.createIfNeeded( ArcGisMapService.defaultWorldImageryServer, ); @@ -407,10 +399,7 @@ ArcGisMapServerImageryProvider.fromBasemapType = async function ( break; case ArcGisBaseMapType.OCEANS: { - accessToken = defaultValue( - options.token, - ArcGisMapService.defaultAccessToken, - ); + accessToken = options.token ?? ArcGisMapService.defaultAccessToken; server = Resource.createIfNeeded( ArcGisMapService.defaultWorldOceanServer, ); @@ -424,10 +413,7 @@ ArcGisMapServerImageryProvider.fromBasemapType = async function ( break; case ArcGisBaseMapType.HILLSHADE: { - accessToken = defaultValue( - options.token, - ArcGisMapService.defaultAccessToken, - ); + accessToken = options.token ?? ArcGisMapService.defaultAccessToken; server = Resource.createIfNeeded( ArcGisMapService.defaultWorldHillshadeServer, ); @@ -712,7 +698,7 @@ ArcGisMapServerImageryProvider.fromUrl = async function (url, options) { Check.defined("url", url); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resource = Resource.createIfNeeded(url); resource.appendForwardSlash(); @@ -726,7 +712,7 @@ ArcGisMapServerImageryProvider.fromUrl = async function (url, options) { const provider = new ArcGisMapServerImageryProvider(options); provider._resource = resource; const imageryProviderBuilder = new ImageryProviderBuilder(options); - const useTiles = defaultValue(options.usePreCachedTilesIfAvailable, true); + const useTiles = options.usePreCachedTilesIfAvailable ?? true; if (useTiles) { await requestMetadata(resource, imageryProviderBuilder); } diff --git a/packages/engine/Source/Scene/B3dmParser.js b/packages/engine/Source/Scene/B3dmParser.js index c5021877894e..e76e6e21ee0d 100644 --- a/packages/engine/Source/Scene/B3dmParser.js +++ b/packages/engine/Source/Scene/B3dmParser.js @@ -1,5 +1,4 @@ import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import deprecationWarning from "../Core/deprecationWarning.js"; import getJsonFromTypedArray from "../Core/getJsonFromTypedArray.js"; import RuntimeError from "../Core/RuntimeError.js"; @@ -25,7 +24,7 @@ const sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; * @returns {object} Returns an object with the batch length, feature table (binary and json), batch table (binary and json) and glTF parts of the b3dm. */ B3dmParser.parse = function (arrayBuffer, byteOffset) { - const byteStart = defaultValue(byteOffset, 0); + const byteStart = byteOffset ?? 0; //>>includeStart('debug', pragmas.debug); Check.defined("arrayBuffer", arrayBuffer); //>>includeEnd('debug'); @@ -96,7 +95,7 @@ B3dmParser.parse = function (arrayBuffer, byteOffset) { let featureTableJson; if (featureTableJsonByteLength === 0) { featureTableJson = { - BATCH_LENGTH: defaultValue(batchLength, 0), + BATCH_LENGTH: batchLength ?? 0, }; } else { featureTableJson = getJsonFromTypedArray( diff --git a/packages/engine/Source/Scene/BatchTableHierarchy.js b/packages/engine/Source/Scene/BatchTableHierarchy.js index 49927f76aa5d..037e339ef72c 100644 --- a/packages/engine/Source/Scene/BatchTableHierarchy.js +++ b/packages/engine/Source/Scene/BatchTableHierarchy.js @@ -4,7 +4,6 @@ import clone from "../Core/clone.js"; import combine from "../Core/combine.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; import defined from "../Core/defined.js"; -import defaultValue from "../Core/defaultValue.js"; import DeveloperError from "../Core/DeveloperError.js"; import getBinaryAccessor from "./getBinaryAccessor.js"; import RuntimeError from "../Core/RuntimeError.js"; @@ -74,10 +73,8 @@ function initialize(hierarchy, hierarchyJson, binaryBody) { let byteLength = 0; if (defined(classIds.byteOffset)) { - classIds.componentType = defaultValue( - classIds.componentType, - ComponentDatatype.UNSIGNED_SHORT, - ); + classIds.componentType = + classIds.componentType ?? ComponentDatatype.UNSIGNED_SHORT; classIds.type = AttributeType.SCALAR; binaryAccessor = getBinaryAccessor(classIds); classIds = binaryAccessor.createArrayBufferView( @@ -91,10 +88,8 @@ function initialize(hierarchy, hierarchyJson, binaryBody) { let parentIndexes; if (defined(parentCounts)) { if (defined(parentCounts.byteOffset)) { - parentCounts.componentType = defaultValue( - parentCounts.componentType, - ComponentDatatype.UNSIGNED_SHORT, - ); + parentCounts.componentType = + parentCounts.componentType ?? ComponentDatatype.UNSIGNED_SHORT; parentCounts.type = AttributeType.SCALAR; binaryAccessor = getBinaryAccessor(parentCounts); parentCounts = binaryAccessor.createArrayBufferView( @@ -115,10 +110,8 @@ function initialize(hierarchy, hierarchyJson, binaryBody) { } if (defined(parentIds) && defined(parentIds.byteOffset)) { - parentIds.componentType = defaultValue( - parentIds.componentType, - ComponentDatatype.UNSIGNED_SHORT, - ); + parentIds.componentType = + parentIds.componentType ?? ComponentDatatype.UNSIGNED_SHORT; parentIds.type = AttributeType.SCALAR; binaryAccessor = getBinaryAccessor(parentIds); parentIds = binaryAccessor.createArrayBufferView( diff --git a/packages/engine/Source/Scene/Billboard.js b/packages/engine/Source/Scene/Billboard.js index d06129800960..2c6626132c02 100644 --- a/packages/engine/Source/Scene/Billboard.js +++ b/packages/engine/Source/Scene/Billboard.js @@ -93,7 +93,7 @@ import SplitDirection from "./SplitDirection.js"; * @demo {@link https://sandcastle.cesium.com/index.html?src=Billboards.html|Cesium Sandcastle Billboard Demo} */ function Billboard(options, billboardCollection) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if ( @@ -155,49 +155,32 @@ function Billboard(options, billboardCollection) { ); } - this._show = defaultValue(options.show, true); - this._position = Cartesian3.clone( - defaultValue(options.position, Cartesian3.ZERO), - ); + this._show = options.show ?? true; + this._position = Cartesian3.clone(options.position ?? Cartesian3.ZERO); this._actualPosition = Cartesian3.clone(this._position); // For columbus view and 2D - this._pixelOffset = Cartesian2.clone( - defaultValue(options.pixelOffset, Cartesian2.ZERO), - ); + this._pixelOffset = Cartesian2.clone(options.pixelOffset ?? Cartesian2.ZERO); this._translate = new Cartesian2(0.0, 0.0); // used by labels for glyph vertex translation - this._eyeOffset = Cartesian3.clone( - defaultValue(options.eyeOffset, Cartesian3.ZERO), - ); - this._heightReference = defaultValue( - options.heightReference, - HeightReference.NONE, - ); - this._verticalOrigin = defaultValue( - options.verticalOrigin, - VerticalOrigin.CENTER, - ); - this._horizontalOrigin = defaultValue( - options.horizontalOrigin, - HorizontalOrigin.CENTER, - ); - this._scale = defaultValue(options.scale, 1.0); - this._color = Color.clone(defaultValue(options.color, Color.WHITE)); - this._rotation = defaultValue(options.rotation, 0.0); - this._alignedAxis = Cartesian3.clone( - defaultValue(options.alignedAxis, Cartesian3.ZERO), - ); + this._eyeOffset = Cartesian3.clone(options.eyeOffset ?? Cartesian3.ZERO); + this._heightReference = options.heightReference ?? HeightReference.NONE; + this._verticalOrigin = options.verticalOrigin ?? VerticalOrigin.CENTER; + this._horizontalOrigin = options.horizontalOrigin ?? HorizontalOrigin.CENTER; + this._scale = options.scale ?? 1.0; + this._color = Color.clone(options.color ?? Color.WHITE); + this._rotation = options.rotation ?? 0.0; + this._alignedAxis = Cartesian3.clone(options.alignedAxis ?? Cartesian3.ZERO); this._width = options.width; this._height = options.height; this._scaleByDistance = scaleByDistance; this._translucencyByDistance = translucencyByDistance; this._pixelOffsetScaleByDistance = pixelOffsetScaleByDistance; - this._sizeInMeters = defaultValue(options.sizeInMeters, false); + this._sizeInMeters = options.sizeInMeters ?? false; this._distanceDisplayCondition = distanceDisplayCondition; this._disableDepthTestDistance = options.disableDepthTestDistance; this._id = options.id; - this._collection = defaultValue(options.collection, billboardCollection); + this._collection = options.collection ?? billboardCollection; this._pickId = undefined; - this._pickPrimitive = defaultValue(options._pickPrimitive, this); + this._pickPrimitive = options._pickPrimitive ?? this; this._billboardCollection = billboardCollection; this._dirty = false; this._index = -1; //Used only by BillboardCollection @@ -246,17 +229,12 @@ function Billboard(options, billboardCollection) { this._mode = SceneMode.SCENE3D; this._clusterShow = true; - this._outlineColor = Color.clone( - defaultValue(options.outlineColor, Color.BLACK), - ); - this._outlineWidth = defaultValue(options.outlineWidth, 0.0); + this._outlineColor = Color.clone(options.outlineColor ?? Color.BLACK); + this._outlineWidth = options.outlineWidth ?? 0.0; this._updateClamping(); - this._splitDirection = defaultValue( - options.splitDirection, - SplitDirection.NONE, - ); + this._splitDirection = options.splitDirection ?? SplitDirection.NONE; } const SHOW_INDEX = (Billboard.SHOW_INDEX = 0); @@ -779,7 +757,7 @@ Object.defineProperties(Billboard.prototype, { */ width: { get: function () { - return defaultValue(this._width, this._imageWidth); + return this._width ?? this._imageWidth; }, set: function (value) { //>>includeStart('debug', pragmas.debug); @@ -801,7 +779,7 @@ Object.defineProperties(Billboard.prototype, { */ height: { get: function () { - return defaultValue(this._height, this._imageHeight); + return this._height ?? this._imageHeight; }, set: function (value) { //>>includeStart('debug', pragmas.debug); @@ -1132,7 +1110,7 @@ Billboard._updateClamping = function (collection, owner) { return; } - const ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.default); + const ellipsoid = scene.ellipsoid ?? Ellipsoid.default; const mode = scene.frameState.mode; diff --git a/packages/engine/Source/Scene/BillboardCollection.js b/packages/engine/Source/Scene/BillboardCollection.js index 54da7f40943d..da4ffc21a8aa 100644 --- a/packages/engine/Source/Scene/BillboardCollection.js +++ b/packages/engine/Source/Scene/BillboardCollection.js @@ -143,7 +143,7 @@ const attributeLocationsInstanced = { * }); */ function BillboardCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._scene = options.scene; this._batchTable = options.batchTable; @@ -211,7 +211,7 @@ function BillboardCollection(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * The 4x4 transformation matrix that transforms each billboard in this collection from model to world coordinates. @@ -245,9 +245,7 @@ function BillboardCollection(options) { * * @see Transforms.eastNorthUpToFixedFrame */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY); /** @@ -260,10 +258,7 @@ function BillboardCollection(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * This property is for debugging only; it is not for production use nor is it optimized. @@ -275,10 +270,7 @@ function BillboardCollection(options) { * * @default false */ - this.debugShowTextureAtlas = defaultValue( - options.debugShowTextureAtlas, - false, - ); + this.debugShowTextureAtlas = options.debugShowTextureAtlas ?? false; /** * The billboard blending option. The default is used for rendering both opaque and translucent billboards. @@ -288,10 +280,7 @@ function BillboardCollection(options) { * @type {BlendOption} * @default BlendOption.OPAQUE_AND_TRANSLUCENT */ - this.blendOption = defaultValue( - options.blendOption, - BlendOption.OPAQUE_AND_TRANSLUCENT, - ); + this.blendOption = options.blendOption ?? BlendOption.OPAQUE_AND_TRANSLUCENT; this._blendOption = undefined; this._mode = SceneMode.SCENE3D; @@ -1102,9 +1091,7 @@ function writeCompressedAttrib1( } const textureWidth = billboardCollection._textureAtlas.texture.width; - const imageWidth = Math.round( - defaultValue(billboard.width, textureWidth * width), - ); + const imageWidth = Math.round(billboard.width ?? textureWidth * width); billboardCollection._maxSize = Math.max( billboardCollection._maxSize, imageWidth, @@ -1178,17 +1165,12 @@ function writeCompressedAttrib2( } const dimensions = billboardCollection._textureAtlas.texture.dimensions; - const imageHeight = Math.round( - defaultValue(billboard.height, dimensions.y * height), - ); + const imageHeight = Math.round(billboard.height ?? dimensions.y * height); billboardCollection._maxSize = Math.max( billboardCollection._maxSize, imageHeight, ); - let labelHorizontalOrigin = defaultValue( - billboard._labelHorizontalOrigin, - -2, - ); + let labelHorizontalOrigin = billboard._labelHorizontalOrigin ?? -2; labelHorizontalOrigin += 2; const compressed3 = imageHeight * LEFT_SHIFT2 + labelHorizontalOrigin; @@ -1415,16 +1397,12 @@ function writeCompressedAttribute3( } imageHeight = Math.round( - defaultValue( - billboard.height, + billboard.height ?? billboardCollection._textureAtlas.texture.dimensions.y * height, - ), ); const textureWidth = billboardCollection._textureAtlas.texture.width; - imageWidth = Math.round( - defaultValue(billboard.width, textureWidth * width), - ); + imageWidth = Math.round(billboard.width ?? textureWidth * width); } else { imageWidth = billboard._labelDimensions.x; imageHeight = billboard._labelDimensions.y; diff --git a/packages/engine/Source/Scene/BingMapsImageryProvider.js b/packages/engine/Source/Scene/BingMapsImageryProvider.js index f97598184ffe..dc0cac1144a8 100644 --- a/packages/engine/Source/Scene/BingMapsImageryProvider.js +++ b/packages/engine/Source/Scene/BingMapsImageryProvider.js @@ -205,7 +205,7 @@ async function requestMetadata( * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} */ function BingMapsImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; @@ -218,9 +218,9 @@ function BingMapsImageryProvider(options) { this._defaultMinificationFilter = undefined; this._defaultMagnificationFilter = undefined; - this._mapStyle = defaultValue(options.mapStyle, BingMapsStyle.AERIAL); + this._mapStyle = options.mapStyle ?? BingMapsStyle.AERIAL; this._mapLayer = options.mapLayer; - this._culture = defaultValue(options.culture, ""); + this._culture = options.culture ?? ""; this._key = options.key; this._tileDiscardPolicy = options.tileDiscardPolicy; @@ -471,7 +471,7 @@ Object.defineProperties(BingMapsImageryProvider.prototype, { * @exception {RuntimeError} metadata does not specify one resource in resourceSets */ BingMapsImageryProvider.fromUrl = async function (url, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("url", url); @@ -495,7 +495,7 @@ BingMapsImageryProvider.fromUrl = async function (url, options) { tileProtocol = documentProtocol === "http:" ? "http" : "https"; } - const mapStyle = defaultValue(options.mapStyle, BingMapsStyle.AERIAL); + const mapStyle = options.mapStyle ?? BingMapsStyle.AERIAL; const resource = Resource.createIfNeeded(url); resource.appendForwardSlash(); diff --git a/packages/engine/Source/Scene/BoxEmitter.js b/packages/engine/Source/Scene/BoxEmitter.js index 15e0eaf293d4..c37291da3236 100644 --- a/packages/engine/Source/Scene/BoxEmitter.js +++ b/packages/engine/Source/Scene/BoxEmitter.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import CesiumMath from "../Core/Math.js"; const defaultDimensions = new Cartesian3(1.0, 1.0, 1.0); @@ -15,7 +14,7 @@ const defaultDimensions = new Cartesian3(1.0, 1.0, 1.0); * @param {Cartesian3} dimensions The width, height and depth dimensions of the box. */ function BoxEmitter(dimensions) { - dimensions = defaultValue(dimensions, defaultDimensions); + dimensions = dimensions ?? defaultDimensions; //>>includeStart('debug', pragmas.debug); Check.defined("dimensions", dimensions); diff --git a/packages/engine/Source/Scene/BufferLoader.js b/packages/engine/Source/Scene/BufferLoader.js index bc4075c8f827..459ac74e90fe 100644 --- a/packages/engine/Source/Scene/BufferLoader.js +++ b/packages/engine/Source/Scene/BufferLoader.js @@ -24,7 +24,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @private */ function BufferLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const typedArray = options.typedArray; const resource = options.resource; const cacheKey = options.cacheKey; diff --git a/packages/engine/Source/Scene/Camera.js b/packages/engine/Source/Scene/Camera.js index f24e257cef63..6b12d67b656c 100644 --- a/packages/engine/Source/Scene/Camera.js +++ b/packages/engine/Source/Scene/Camera.js @@ -1485,11 +1485,8 @@ const scratchHpr = new HeadingPitchRoll(); * }); */ Camera.prototype.setView = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - let orientation = defaultValue( - options.orientation, - defaultValue.EMPTY_OBJECT, - ); + options = options ?? defaultValue.EMPTY_OBJECT; + let orientation = options.orientation ?? defaultValue.EMPTY_OBJECT; const mode = this._mode; if (mode === SceneMode.MORPHING) { @@ -1500,11 +1497,10 @@ Camera.prototype.setView = function (options) { this._setTransform(options.endTransform); } - let convert = defaultValue(options.convert, true); - let destination = defaultValue( - options.destination, - Cartesian3.clone(this.positionWC, scratchSetViewCartesian), - ); + let convert = options.convert ?? true; + let destination = + options.destination ?? + Cartesian3.clone(this.positionWC, scratchSetViewCartesian); if (defined(destination) && defined(destination.west)) { destination = this.getRectangleCameraCoordinates( destination, @@ -1528,9 +1524,9 @@ Camera.prototype.setView = function (options) { ); } - scratchHpr.heading = defaultValue(orientation.heading, 0.0); - scratchHpr.pitch = defaultValue(orientation.pitch, -CesiumMath.PI_OVER_TWO); - scratchHpr.roll = defaultValue(orientation.roll, 0.0); + scratchHpr.heading = orientation.heading ?? 0.0; + scratchHpr.pitch = orientation.pitch ?? -CesiumMath.PI_OVER_TWO; + scratchHpr.roll = orientation.roll ?? 0.0; if (mode === SceneMode.SCENE3D) { setView3D(this, destination, scratchHpr); @@ -1803,7 +1799,7 @@ Camera.prototype.move = function (direction, amount) { * @see Camera#moveBackward */ Camera.prototype.moveForward = function (amount) { - amount = defaultValue(amount, this.defaultMoveAmount); + amount = amount ?? this.defaultMoveAmount; if (this._mode === SceneMode.SCENE2D) { // 2D mode @@ -1824,7 +1820,7 @@ Camera.prototype.moveForward = function (amount) { * @see Camera#moveForward */ Camera.prototype.moveBackward = function (amount) { - amount = defaultValue(amount, this.defaultMoveAmount); + amount = amount ?? this.defaultMoveAmount; if (this._mode === SceneMode.SCENE2D) { // 2D mode @@ -1843,7 +1839,7 @@ Camera.prototype.moveBackward = function (amount) { * @see Camera#moveDown */ Camera.prototype.moveUp = function (amount) { - amount = defaultValue(amount, this.defaultMoveAmount); + amount = amount ?? this.defaultMoveAmount; this.move(this.up, amount); }; @@ -1856,7 +1852,7 @@ Camera.prototype.moveUp = function (amount) { * @see Camera#moveUp */ Camera.prototype.moveDown = function (amount) { - amount = defaultValue(amount, this.defaultMoveAmount); + amount = amount ?? this.defaultMoveAmount; this.move(this.up, -amount); }; @@ -1868,7 +1864,7 @@ Camera.prototype.moveDown = function (amount) { * @see Camera#moveLeft */ Camera.prototype.moveRight = function (amount) { - amount = defaultValue(amount, this.defaultMoveAmount); + amount = amount ?? this.defaultMoveAmount; this.move(this.right, amount); }; @@ -1881,7 +1877,7 @@ Camera.prototype.moveRight = function (amount) { * @see Camera#moveRight */ Camera.prototype.moveLeft = function (amount) { - amount = defaultValue(amount, this.defaultMoveAmount); + amount = amount ?? this.defaultMoveAmount; this.move(this.right, -amount); }; @@ -1894,7 +1890,7 @@ Camera.prototype.moveLeft = function (amount) { * @see Camera#lookRight */ Camera.prototype.lookLeft = function (amount) { - amount = defaultValue(amount, this.defaultLookAmount); + amount = amount ?? this.defaultLookAmount; // only want view of map to change in 3D mode, 2D visual is incorrect when look changes if (this._mode !== SceneMode.SCENE2D) { @@ -1911,7 +1907,7 @@ Camera.prototype.lookLeft = function (amount) { * @see Camera#lookLeft */ Camera.prototype.lookRight = function (amount) { - amount = defaultValue(amount, this.defaultLookAmount); + amount = amount ?? this.defaultLookAmount; // only want view of map to change in 3D mode, 2D visual is incorrect when look changes if (this._mode !== SceneMode.SCENE2D) { @@ -1928,7 +1924,7 @@ Camera.prototype.lookRight = function (amount) { * @see Camera#lookDown */ Camera.prototype.lookUp = function (amount) { - amount = defaultValue(amount, this.defaultLookAmount); + amount = amount ?? this.defaultLookAmount; // only want view of map to change in 3D mode, 2D visual is incorrect when look changes if (this._mode !== SceneMode.SCENE2D) { @@ -1945,7 +1941,7 @@ Camera.prototype.lookUp = function (amount) { * @see Camera#lookUp */ Camera.prototype.lookDown = function (amount) { - amount = defaultValue(amount, this.defaultLookAmount); + amount = amount ?? this.defaultLookAmount; // only want view of map to change in 3D mode, 2D visual is incorrect when look changes if (this._mode !== SceneMode.SCENE2D) { @@ -1973,7 +1969,7 @@ Camera.prototype.look = function (axis, angle) { } //>>includeEnd('debug'); - const turnAngle = defaultValue(angle, this.defaultLookAmount); + const turnAngle = angle ?? this.defaultLookAmount; const quaternion = Quaternion.fromAxisAngle( axis, -turnAngle, @@ -1998,7 +1994,7 @@ Camera.prototype.look = function (axis, angle) { * @see Camera#twistRight */ Camera.prototype.twistLeft = function (amount) { - amount = defaultValue(amount, this.defaultLookAmount); + amount = amount ?? this.defaultLookAmount; this.look(this.direction, amount); }; @@ -2010,7 +2006,7 @@ Camera.prototype.twistLeft = function (amount) { * @see Camera#twistLeft */ Camera.prototype.twistRight = function (amount) { - amount = defaultValue(amount, this.defaultLookAmount); + amount = amount ?? this.defaultLookAmount; this.look(this.direction, -amount); }; @@ -2035,7 +2031,7 @@ Camera.prototype.rotate = function (axis, angle) { } //>>includeEnd('debug'); - const turnAngle = defaultValue(angle, this.defaultRotateAmount); + const turnAngle = angle ?? this.defaultRotateAmount; const quaternion = Quaternion.fromAxisAngle( axis, -turnAngle, @@ -2060,7 +2056,7 @@ Camera.prototype.rotate = function (axis, angle) { * @see Camera#rotate */ Camera.prototype.rotateDown = function (angle) { - angle = defaultValue(angle, this.defaultRotateAmount); + angle = angle ?? this.defaultRotateAmount; rotateVertical(this, angle); }; @@ -2073,7 +2069,7 @@ Camera.prototype.rotateDown = function (angle) { * @see Camera#rotate */ Camera.prototype.rotateUp = function (angle) { - angle = defaultValue(angle, this.defaultRotateAmount); + angle = angle ?? this.defaultRotateAmount; rotateVertical(this, -angle); }; @@ -2146,7 +2142,7 @@ function rotateVertical(camera, angle) { * @see Camera#rotate */ Camera.prototype.rotateRight = function (angle) { - angle = defaultValue(angle, this.defaultRotateAmount); + angle = angle ?? this.defaultRotateAmount; rotateHorizontal(this, -angle); }; @@ -2159,7 +2155,7 @@ Camera.prototype.rotateRight = function (angle) { * @see Camera#rotate */ Camera.prototype.rotateLeft = function (angle) { - angle = defaultValue(angle, this.defaultRotateAmount); + angle = angle ?? this.defaultRotateAmount; rotateHorizontal(this, angle); }; @@ -2256,7 +2252,7 @@ function zoom3D(camera, amount) { * @see Camera#zoomOut */ Camera.prototype.zoomIn = function (amount) { - amount = defaultValue(amount, this.defaultZoomAmount); + amount = amount ?? this.defaultZoomAmount; if (this._mode === SceneMode.SCENE2D) { zoom2D(this, amount); } else { @@ -2273,7 +2269,7 @@ Camera.prototype.zoomIn = function (amount) { * @see Camera#zoomIn */ Camera.prototype.zoomOut = function (amount) { - amount = defaultValue(amount, this.defaultZoomAmount); + amount = amount ?? this.defaultZoomAmount; if (this._mode === SceneMode.SCENE2D) { zoom2D(this, -amount); } else { @@ -2345,7 +2341,7 @@ Camera.prototype.lookAt = function (target, offset) { //>>includeEnd('debug'); const scene = this._scene; - const ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.default); + const ellipsoid = scene.ellipsoid ?? Ellipsoid.default; const transform = Transforms.eastNorthUpToFixedFrame( target, @@ -2840,7 +2836,7 @@ Camera.prototype.getRectangleCameraCoordinates = function (rectangle, result) { const pickEllipsoid3DRay = new Ray(); function pickEllipsoid3D(camera, windowPosition, ellipsoid, result) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; const ray = camera.getPickRay(windowPosition, pickEllipsoid3DRay); const intersection = IntersectionTests.rayEllipsoid(ray, ellipsoid); if (!intersection) { @@ -2920,7 +2916,7 @@ Camera.prototype.pickEllipsoid = function (windowPosition, ellipsoid, result) { result = new Cartesian3(); } - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; if (this._mode === SceneMode.SCENE3D) { result = pickEllipsoid3D(this, windowPosition, ellipsoid, result); @@ -3363,7 +3359,7 @@ Camera.prototype.completeFlight = function () { * }); */ Camera.prototype.flyTo = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let destination = options.destination; //>>includeStart('debug', pragmas.debug); if (!defined(destination)) { @@ -3386,10 +3382,7 @@ Camera.prototype.flyTo = function (options) { ); } - let orientation = defaultValue( - options.orientation, - defaultValue.EMPTY_OBJECT, - ); + let orientation = options.orientation ?? defaultValue.EMPTY_OBJECT; if (defined(orientation.direction)) { orientation = directionUpToHeadingPitchRoll( this, @@ -3607,7 +3600,7 @@ Camera.prototype.flyToBoundingSphere = function (boundingSphere, options) { } //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const scene2D = this._mode === SceneMode.SCENE2D || this._mode === SceneMode.COLUMBUS_VIEW; this._setTransform(Matrix4.IDENTITY); @@ -3633,7 +3626,7 @@ Camera.prototype.flyToBoundingSphere = function (boundingSphere, options) { } const scene = this._scene; - const ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.default); + const ellipsoid = scene.ellipsoid ?? Ellipsoid.default; const transform = Transforms.eastNorthUpToFixedFrame( boundingSphere.center, @@ -3823,7 +3816,7 @@ function addToResult(x, y, index, camera, ellipsoid, computedHorizonQuad) { * @returns {Rectangle|undefined} The visible rectangle or undefined if the ellipsoid isn't visible at all. */ Camera.prototype.computeViewRectangle = function (ellipsoid, result) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; const cullingVolume = this.frustum.computeCullingVolume( this.positionWC, this.directionWC, diff --git a/packages/engine/Source/Scene/CameraFlightPath.js b/packages/engine/Source/Scene/CameraFlightPath.js index 3490f72f497f..465ea7565d64 100644 --- a/packages/engine/Source/Scene/CameraFlightPath.js +++ b/packages/engine/Source/Scene/CameraFlightPath.js @@ -404,7 +404,7 @@ function wrapCallback(controller, cb) { } CameraFlightPath.createTween = function (scene, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let destination = options.destination; //>>includeStart('debug', pragmas.debug); @@ -421,7 +421,7 @@ CameraFlightPath.createTween = function (scene, options) { return emptyFlight(); } - const convert = defaultValue(options.convert, true); + const convert = options.convert ?? true; const projection = scene.mapProjection; const ellipsoid = projection.ellipsoid; const maximumHeight = options.maximumHeight; @@ -449,9 +449,9 @@ CameraFlightPath.createTween = function (scene, options) { duration = Math.min(duration, 3.0); } - const heading = defaultValue(options.heading, 0.0); - const pitch = defaultValue(options.pitch, -CesiumMath.PI_OVER_TWO); - const roll = defaultValue(options.roll, 0.0); + const heading = options.heading ?? 0.0; + const pitch = options.pitch ?? -CesiumMath.PI_OVER_TWO; + const roll = options.roll ?? 0.0; const controller = scene.screenSpaceCameraController; controller.enableInputs = false; diff --git a/packages/engine/Source/Scene/Cesium3DContentGroup.js b/packages/engine/Source/Scene/Cesium3DContentGroup.js index bacacd718626..8d2e9919ed21 100644 --- a/packages/engine/Source/Scene/Cesium3DContentGroup.js +++ b/packages/engine/Source/Scene/Cesium3DContentGroup.js @@ -16,7 +16,7 @@ import defaultValue from "../Core/defaultValue.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function Cesium3DContentGroup(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.metadata", options.metadata); //>>includeEnd('debug'); diff --git a/packages/engine/Source/Scene/Cesium3DTile.js b/packages/engine/Source/Scene/Cesium3DTile.js index 53e21c781f15..a523d681822e 100644 --- a/packages/engine/Source/Scene/Cesium3DTile.js +++ b/packages/engine/Source/Scene/Cesium3DTile.js @@ -3,7 +3,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Color from "../Core/Color.js"; import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js"; import CullingVolume from "../Core/CullingVolume.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import deprecationWarning from "../Core/deprecationWarning.js"; import destroyObject from "../Core/destroyObject.js"; @@ -579,7 +578,7 @@ Object.defineProperties(Cesium3DTile.prototype, { */ contentBoundingVolume: { get: function () { - return defaultValue(this._contentBoundingVolume, this._boundingVolume); + return this._contentBoundingVolume ?? this._boundingVolume; }, }, @@ -918,7 +917,7 @@ Cesium3DTile.prototype.getScreenSpaceError = function ( progressiveResolutionHeightFraction, ) { const tileset = this._tileset; - const heightFraction = defaultValue(progressiveResolutionHeightFraction, 1.0); + const heightFraction = progressiveResolutionHeightFraction ?? 1.0; const parentGeometricError = defined(this.parent) ? this.parent.geometricError : tileset._scaledGeometricError; @@ -1947,7 +1946,7 @@ Cesium3DTile.prototype.updateTransform = function ( parentTransform, frameState, ) { - parentTransform = defaultValue(parentTransform, Matrix4.IDENTITY); + parentTransform = parentTransform ?? Matrix4.IDENTITY; const computedTransform = Matrix4.multiplyTransformation( parentTransform, this.transform, diff --git a/packages/engine/Source/Scene/Cesium3DTileBatchTable.js b/packages/engine/Source/Scene/Cesium3DTileBatchTable.js index 5bb9f4f3ac42..13a52e90e127 100644 --- a/packages/engine/Source/Scene/Cesium3DTileBatchTable.js +++ b/packages/engine/Source/Scene/Cesium3DTileBatchTable.js @@ -3,7 +3,6 @@ import Check from "../Core/Check.js"; import clone from "../Core/clone.js"; import Color from "../Core/Color.js"; import combine from "../Core/combine.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import deprecationWarning from "../Core/deprecationWarning.js"; import destroyObject from "../Core/destroyObject.js"; @@ -48,7 +47,7 @@ function Cesium3DTileBatchTable( if (defined(batchTableJson)) { extensions = batchTableJson.extensions; } - this._extensions = defaultValue(extensions, {}); + this._extensions = extensions ?? {}; const properties = initializeProperties(batchTableJson); this._properties = properties; @@ -266,13 +265,11 @@ Cesium3DTileBatchTable.prototype.applyStyle = function (style) { for (let i = 0; i < length; ++i) { const feature = content.getFeature(i); const color = defined(style.color) - ? defaultValue( - style.color.evaluateColor(feature, scratchColor), - DEFAULT_COLOR_VALUE, - ) + ? (style.color.evaluateColor(feature, scratchColor) ?? + DEFAULT_COLOR_VALUE) : DEFAULT_COLOR_VALUE; const show = defined(style.show) - ? defaultValue(style.show.evaluate(feature), DEFAULT_SHOW_VALUE) + ? (style.show.evaluate(feature) ?? DEFAULT_SHOW_VALUE) : DEFAULT_SHOW_VALUE; this.setColor(i, color); this.setShow(i, show); @@ -851,9 +848,8 @@ Cesium3DTileBatchTable.prototype.getUniformMapCallback = function () { const batchUniformMap = { tile_batchTexture: function () { // PERFORMANCE_IDEA: we could also use a custom shader that avoids the texture read. - return defaultValue( - that._batchTexture.batchTexture, - that._batchTexture.defaultTexture, + return ( + that._batchTexture.batchTexture ?? that._batchTexture.defaultTexture ); }, tile_textureDimensions: function () { diff --git a/packages/engine/Source/Scene/Cesium3DTileFeatureTable.js b/packages/engine/Source/Scene/Cesium3DTileFeatureTable.js index a691d9ec1792..1a1714dc956a 100644 --- a/packages/engine/Source/Scene/Cesium3DTileFeatureTable.js +++ b/packages/engine/Source/Scene/Cesium3DTileFeatureTable.js @@ -1,5 +1,4 @@ import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; /** @@ -55,8 +54,8 @@ Cesium3DTileFeatureTable.prototype.getGlobalProperty = function ( } if (defined(jsonValue.byteOffset)) { - componentType = defaultValue(componentType, ComponentDatatype.UNSIGNED_INT); - componentLength = defaultValue(componentLength, 1); + componentType = componentType ?? ComponentDatatype.UNSIGNED_INT; + componentLength = componentLength ?? 1; return getTypedArrayFromBinary( this, semantic, diff --git a/packages/engine/Source/Scene/Cesium3DTilePointFeature.js b/packages/engine/Source/Scene/Cesium3DTilePointFeature.js index 52ab3f469fbb..027ec0e690e2 100644 --- a/packages/engine/Source/Scene/Cesium3DTilePointFeature.js +++ b/packages/engine/Source/Scene/Cesium3DTilePointFeature.js @@ -1,6 +1,5 @@ import Cartographic from "../Core/Cartographic.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Cesium3DTileFeature from "./Cesium3DTileFeature.js"; import createBillboardPointCallback from "./createBillboardPointCallback.js"; @@ -411,7 +410,7 @@ Object.defineProperties(Cesium3DTilePointFeature.prototype, { return this._heightOffset; }, set: function (value) { - const offset = defaultValue(this._heightOffset, 0.0); + const offset = this._heightOffset ?? 0.0; const ellipsoid = this._content.tileset.ellipsoid; const cart = ellipsoid.cartesianToCartographic( @@ -652,22 +651,15 @@ function setBillboardImage(feature) { return; } - const newColor = defaultValue( - feature._color, - Cesium3DTilePointFeature.defaultColor, - ); - const newOutlineColor = defaultValue( - feature._pointOutlineColor, - Cesium3DTilePointFeature.defaultPointOutlineColor, - ); - const newOutlineWidth = defaultValue( - feature._pointOutlineWidth, - Cesium3DTilePointFeature.defaultPointOutlineWidth, - ); - const newPointSize = defaultValue( - feature._pointSize, - Cesium3DTilePointFeature.defaultPointSize, - ); + const newColor = feature._color ?? Cesium3DTilePointFeature.defaultColor; + const newOutlineColor = + feature._pointOutlineColor ?? + Cesium3DTilePointFeature.defaultPointOutlineColor; + const newOutlineWidth = + feature._pointOutlineWidth ?? + Cesium3DTilePointFeature.defaultPointOutlineWidth; + const newPointSize = + feature._pointSize ?? Cesium3DTilePointFeature.defaultPointSize; const currentColor = feature._billboardColor; const currentOutlineColor = feature._billboardOutlineColor; diff --git a/packages/engine/Source/Scene/Cesium3DTileStyle.js b/packages/engine/Source/Scene/Cesium3DTileStyle.js index 5ebe368e10a0..046329007c46 100644 --- a/packages/engine/Source/Scene/Cesium3DTileStyle.js +++ b/packages/engine/Source/Scene/Cesium3DTileStyle.js @@ -86,7 +86,7 @@ function Cesium3DTileStyle(style) { } function setup(that, styleJson) { - styleJson = defaultValue(clone(styleJson, true), that._style); + styleJson = clone(styleJson, true) ?? that._style; that._style = styleJson; that.show = styleJson.show; @@ -119,7 +119,7 @@ function setup(that, styleJson) { const meta = {}; if (defined(styleJson.meta)) { const defines = styleJson.defines; - const metaJson = defaultValue(styleJson.meta, defaultValue.EMPTY_OBJECT); + const metaJson = styleJson.meta ?? defaultValue.EMPTY_OBJECT; for (const property in metaJson) { if (metaJson.hasOwnProperty(property)) { meta[property] = new Expression(metaJson[property], defines); @@ -133,10 +133,7 @@ function setup(that, styleJson) { } function getExpression(tileStyle, value) { - const defines = defaultValue( - tileStyle._style, - defaultValue.EMPTY_OBJECT, - ).defines; + const defines = (tileStyle._style ?? defaultValue.EMPTY_OBJECT).defines; if (!defined(value)) { return undefined; diff --git a/packages/engine/Source/Scene/Cesium3DTilesVoxelProvider.js b/packages/engine/Source/Scene/Cesium3DTilesVoxelProvider.js index f473b19b96e7..379c831f35f9 100644 --- a/packages/engine/Source/Scene/Cesium3DTilesVoxelProvider.js +++ b/packages/engine/Source/Scene/Cesium3DTilesVoxelProvider.js @@ -45,7 +45,7 @@ import VoxelShapeType from "./VoxelShapeType.js"; * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. */ function Cesium3DTilesVoxelProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** @inheritdoc */ this.shapeTransform = undefined; @@ -404,12 +404,12 @@ async function getSubtreePromise(provider, subtreeCoord) { /** @inheritdoc */ Cesium3DTilesVoxelProvider.prototype.requestData = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const tileLevel = defaultValue(options.tileLevel, 0); - const tileX = defaultValue(options.tileX, 0); - const tileY = defaultValue(options.tileY, 0); - const tileZ = defaultValue(options.tileZ, 0); - const keyframe = defaultValue(options.keyframe, 0); + options = options ?? defaultValue.EMPTY_OBJECT; + const tileLevel = options.tileLevel ?? 0; + const tileX = options.tileX ?? 0; + const tileY = options.tileY ?? 0; + const tileZ = options.tileZ ?? 0; + const keyframe = options.keyframe ?? 0; // 3D Tiles currently doesn't support time-dynamic data. if (keyframe !== 0) { diff --git a/packages/engine/Source/Scene/Cesium3DTileset.js b/packages/engine/Source/Scene/Cesium3DTileset.js index e23d1061792b..da81151f32e8 100644 --- a/packages/engine/Source/Scene/Cesium3DTileset.js +++ b/packages/engine/Source/Scene/Cesium3DTileset.js @@ -198,7 +198,7 @@ import DynamicEnvironmentMapManager from "./DynamicEnvironmentMapManager.js"; * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles specification} */ function Cesium3DTileset(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._url = undefined; this._basePath = undefined; @@ -227,12 +227,9 @@ function Cesium3DTileset(options) { this._extras = undefined; this._credits = undefined; - this._showCreditsOnScreen = defaultValue(options.showCreditsOnScreen, false); + this._showCreditsOnScreen = options.showCreditsOnScreen ?? false; - this._cullWithChildrenBounds = defaultValue( - options.cullWithChildrenBounds, - true, - ); + this._cullWithChildrenBounds = options.cullWithChildrenBounds ?? true; this._allTilesAdditive = true; this._hasMixedContent = false; @@ -240,21 +237,16 @@ function Cesium3DTileset(options) { this._stencilClearCommand = undefined; this._backfaceCommands = new ManagedArray(); - this._maximumScreenSpaceError = defaultValue( - options.maximumScreenSpaceError, - 16, - ); + this._maximumScreenSpaceError = options.maximumScreenSpaceError ?? 16; this._memoryAdjustedScreenSpaceError = this._maximumScreenSpaceError; - this._cacheBytes = defaultValue(options.cacheBytes, 512 * 1024 * 1024); + this._cacheBytes = options.cacheBytes ?? 512 * 1024 * 1024; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals("cacheBytes", this._cacheBytes, 0); //>>includeEnd('debug'); - const maximumCacheOverflowBytes = defaultValue( - options.maximumCacheOverflowBytes, - 512 * 1024 * 1024, - ); + const maximumCacheOverflowBytes = + options.maximumCacheOverflowBytes ?? 512 * 1024 * 1024; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThanOrEquals( "maximumCacheOverflowBytes", @@ -305,10 +297,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default true */ - this.cullRequestsWhileMoving = defaultValue( - options.cullRequestsWhileMoving, - true, - ); + this.cullRequestsWhileMoving = options.cullRequestsWhileMoving ?? true; this._cullRequestsWhileMoving = false; /** @@ -317,10 +306,8 @@ function Cesium3DTileset(options) { * @type {number} * @default 60.0 */ - this.cullRequestsWhileMovingMultiplier = defaultValue( - options.cullRequestsWhileMovingMultiplier, - 60.0, - ); + this.cullRequestsWhileMovingMultiplier = + options.cullRequestsWhileMovingMultiplier ?? 60.0; /** * Optimization option. If between (0.0, 0.5], tiles at or above the screen space error for the reduced screen resolution of progressiveResolutionHeightFraction*screenHeight will be prioritized first. This can help get a quick layer of tiles down while full resolution tiles continue to load. @@ -329,7 +316,7 @@ function Cesium3DTileset(options) { * @default 0.3 */ this.progressiveResolutionHeightFraction = CesiumMath.clamp( - defaultValue(options.progressiveResolutionHeightFraction, 0.3), + options.progressiveResolutionHeightFraction ?? 0.3, 0.0, 0.5, ); @@ -340,7 +327,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.preferLeaves = defaultValue(options.preferLeaves, false); + this.preferLeaves = options.preferLeaves ?? false; this._tilesLoaded = false; this._initialTilesLoaded = false; @@ -349,21 +336,16 @@ function Cesium3DTileset(options) { this._classificationType = options.classificationType; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84; this._initialClippingPlanesOriginMatrix = Matrix4.IDENTITY; // Computed from the tileset JSON. this._clippingPlanesOriginMatrix = undefined; // Combines the above with any run-time transforms. this._clippingPlanesOriginMatrixDirty = true; - this._vectorClassificationOnly = defaultValue( - options.vectorClassificationOnly, - false, - ); + this._vectorClassificationOnly = options.vectorClassificationOnly ?? false; - this._vectorKeepDecodedPositions = defaultValue( - options.vectorKeepDecodedPositions, - false, - ); + this._vectorKeepDecodedPositions = + options.vectorKeepDecodedPositions ?? false; /** * Preload tiles when tileset.show is false. Loads tiles as if the tileset is visible but does not render them. @@ -371,7 +353,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.preloadWhenHidden = defaultValue(options.preloadWhenHidden, false); + this.preloadWhenHidden = options.preloadWhenHidden ?? false; /** * Optimization option. Fetch tiles at the camera's flight destination while the camera is in flight. @@ -379,10 +361,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default true */ - this.preloadFlightDestinations = defaultValue( - options.preloadFlightDestinations, - true, - ); + this.preloadFlightDestinations = options.preloadFlightDestinations ?? true; this._pass = undefined; // Cesium3DTilePass /** @@ -395,10 +374,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default true */ - this.dynamicScreenSpaceError = defaultValue( - options.dynamicScreenSpaceError, - true, - ); + this.dynamicScreenSpaceError = options.dynamicScreenSpaceError ?? true; /** * Optimization option. Prioritize loading tiles in the center of the screen by temporarily raising the @@ -408,15 +384,10 @@ function Cesium3DTileset(options) { * @type {boolean} * @default true */ - this.foveatedScreenSpaceError = defaultValue( - options.foveatedScreenSpaceError, - true, - ); - this._foveatedConeSize = defaultValue(options.foveatedConeSize, 0.1); - this._foveatedMinimumScreenSpaceErrorRelaxation = defaultValue( - options.foveatedMinimumScreenSpaceErrorRelaxation, - 0.0, - ); + this.foveatedScreenSpaceError = options.foveatedScreenSpaceError ?? true; + this._foveatedConeSize = options.foveatedConeSize ?? 0.1; + this._foveatedMinimumScreenSpaceErrorRelaxation = + options.foveatedMinimumScreenSpaceErrorRelaxation ?? 0.0; /** * Gets or sets a callback to control how much to raise the screen space error for tiles outside the foveated cone, @@ -424,10 +395,8 @@ function Cesium3DTileset(options) { * * @type {Cesium3DTileset.foveatedInterpolationCallback} */ - this.foveatedInterpolationCallback = defaultValue( - options.foveatedInterpolationCallback, - CesiumMath.lerp, - ); + this.foveatedInterpolationCallback = + options.foveatedInterpolationCallback ?? CesiumMath.lerp; /** * Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control @@ -438,7 +407,7 @@ function Cesium3DTileset(options) { * @type {number} * @default 0.2 */ - this.foveatedTimeDelay = defaultValue(options.foveatedTimeDelay, 0.2); + this.foveatedTimeDelay = options.foveatedTimeDelay ?? 0.2; /** * Similar to {@link Fog#density}, this option controls the camera distance at which the {@link Cesium3DTileset#dynamicScreenSpaceError} @@ -461,10 +430,8 @@ function Cesium3DTileset(options) { * @type {number} * @default 2.0e-4 */ - this.dynamicScreenSpaceErrorDensity = defaultValue( - options.dynamicScreenSpaceErrorDensity, - 2.0e-4, - ); + this.dynamicScreenSpaceErrorDensity = + options.dynamicScreenSpaceErrorDensity ?? 2.0e-4; /** * A parameter that controls the intensity of the {@link Cesium3DTileset#dynamicScreenSpaceError} optimization for @@ -482,10 +449,8 @@ function Cesium3DTileset(options) { * @type {number} * @default 24.0 */ - this.dynamicScreenSpaceErrorFactor = defaultValue( - options.dynamicScreenSpaceErrorFactor, - 24.0, - ); + this.dynamicScreenSpaceErrorFactor = + options.dynamicScreenSpaceErrorFactor ?? 24.0; /** * A ratio of the tileset's height that determines "street level" for the {@link Cesium3DTileset#dynamicScreenSpaceError} @@ -496,10 +461,8 @@ function Cesium3DTileset(options) { * @type {number} * @default 0.25 */ - this.dynamicScreenSpaceErrorHeightFalloff = defaultValue( - options.dynamicScreenSpaceErrorHeightFalloff, - 0.25, - ); + this.dynamicScreenSpaceErrorHeightFalloff = + options.dynamicScreenSpaceErrorHeightFalloff ?? 0.25; // Updated based on the camera position and direction this._dynamicScreenSpaceErrorComputedDensity = 0.0; @@ -516,7 +479,7 @@ function Cesium3DTileset(options) { * @type {ShadowMode} * @default ShadowMode.ENABLED */ - this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED); + this.shadows = options.shadows ?? ShadowMode.ENABLED; /** * Determines if the tileset will be shown. @@ -524,7 +487,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * Defines how per-feature colors set from the Cesium API or declarative styling blend with the source colors from @@ -733,7 +696,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.skipLevelOfDetail = defaultValue(options.skipLevelOfDetail, false); + this.skipLevelOfDetail = options.skipLevelOfDetail ?? false; this._disableSkipLevelOfDetail = false; @@ -746,7 +709,7 @@ function Cesium3DTileset(options) { * @type {number} * @default 1024 */ - this.baseScreenSpaceError = defaultValue(options.baseScreenSpaceError, 1024); + this.baseScreenSpaceError = options.baseScreenSpaceError ?? 1024; /** * Multiplier defining the minimum screen space error to skip. @@ -759,10 +722,7 @@ function Cesium3DTileset(options) { * @type {number} * @default 16 */ - this.skipScreenSpaceErrorFactor = defaultValue( - options.skipScreenSpaceErrorFactor, - 16, - ); + this.skipScreenSpaceErrorFactor = options.skipScreenSpaceErrorFactor ?? 16; /** * Constant defining the minimum number of levels to skip when loading tiles. When it is 0, no levels are skipped. @@ -774,7 +734,7 @@ function Cesium3DTileset(options) { * @type {number} * @default 1 */ - this.skipLevels = defaultValue(options.skipLevels, 1); + this.skipLevels = options.skipLevels ?? 1; /** * When true, only tiles that meet the maximum screen space error will ever be downloaded. @@ -786,10 +746,8 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.immediatelyLoadDesiredLevelOfDetail = defaultValue( - options.immediatelyLoadDesiredLevelOfDetail, - false, - ); + this.immediatelyLoadDesiredLevelOfDetail = + options.immediatelyLoadDesiredLevelOfDetail ?? false; /** * Determines whether siblings of visible tiles are always downloaded during traversal. @@ -801,7 +759,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.loadSiblings = defaultValue(options.loadSiblings, false); + this.loadSiblings = options.loadSiblings ?? false; this._clippingPlanes = undefined; if (defined(options.clippingPlanes)) { @@ -853,9 +811,9 @@ function Cesium3DTileset(options) { * @type {boolean} * @default true */ - this.backFaceCulling = defaultValue(options.backFaceCulling, true); + this.backFaceCulling = options.backFaceCulling ?? true; - this._enableShowOutline = defaultValue(options.enableShowOutline, true); + this._enableShowOutline = options.enableShowOutline ?? true; /** * Whether to display the outline for models using the @@ -865,7 +823,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default true */ - this.showOutline = defaultValue(options.showOutline, true); + this.showOutline = options.showOutline ?? true; /** * The color to use when rendering outlines. @@ -873,7 +831,7 @@ function Cesium3DTileset(options) { * @type {Color} * @default Color.BLACK */ - this.outlineColor = defaultValue(options.outlineColor, Color.BLACK); + this.outlineColor = options.outlineColor ?? Color.BLACK; /** * The {@link SplitDirection} to apply to this tileset. @@ -881,10 +839,7 @@ function Cesium3DTileset(options) { * @type {SplitDirection} * @default {@link SplitDirection.NONE} */ - this.splitDirection = defaultValue( - options.splitDirection, - SplitDirection.NONE, - ); + this.splitDirection = options.splitDirection ?? SplitDirection.NONE; /** * If true, allows collisions for camera collisions or picking. While this is true the camera will be prevented from going in or below the tileset surface if {@link ScreenSpaceCameraController#enableCollisionDetection} is true. This can have performance implecations if the tileset contains tile with a larger number of vertices. @@ -892,9 +847,9 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.enableCollision = defaultValue(options.enableCollision, false); - this._projectTo2D = defaultValue(options.projectTo2D, false); - this._enablePick = defaultValue(options.enablePick, false); + this.enableCollision = options.enableCollision ?? false; + this._projectTo2D = options.projectTo2D ?? false; + this._enablePick = options.enablePick ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -907,7 +862,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugFreezeFrame = defaultValue(options.debugFreezeFrame, false); + this.debugFreezeFrame = options.debugFreezeFrame ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -920,12 +875,9 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugColorizeTiles = defaultValue(options.debugColorizeTiles, false); + this.debugColorizeTiles = options.debugColorizeTiles ?? false; - this._enableDebugWireframe = defaultValue( - options.enableDebugWireframe, - false, - ); + this._enableDebugWireframe = options.enableDebugWireframe ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -936,7 +888,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugWireframe = defaultValue(options.debugWireframe, false); + this.debugWireframe = options.debugWireframe ?? false; // Warning for improper setup of debug wireframe if (this.debugWireframe === true && this._enableDebugWireframe === false) { @@ -957,10 +909,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -972,10 +921,8 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugShowContentBoundingVolume = defaultValue( - options.debugShowContentBoundingVolume, - false, - ); + this.debugShowContentBoundingVolume = + options.debugShowContentBoundingVolume ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -986,10 +933,8 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugShowViewerRequestVolume = defaultValue( - options.debugShowViewerRequestVolume, - false, - ); + this.debugShowViewerRequestVolume = + options.debugShowViewerRequestVolume ?? false; /** * @private @@ -1009,10 +954,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugShowGeometricError = defaultValue( - options.debugShowGeometricError, - false, - ); + this.debugShowGeometricError = options.debugShowGeometricError ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -1023,10 +965,8 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugShowRenderingStatistics = defaultValue( - options.debugShowRenderingStatistics, - false, - ); + this.debugShowRenderingStatistics = + options.debugShowRenderingStatistics ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -1037,7 +977,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugShowMemoryUsage = defaultValue(options.debugShowMemoryUsage, false); + this.debugShowMemoryUsage = options.debugShowMemoryUsage ?? false; /** * This property is for debugging only; it is not optimized for production use. @@ -1048,7 +988,7 @@ function Cesium3DTileset(options) { * @type {boolean} * @default false */ - this.debugShowUrl = defaultValue(options.debugShowUrl, false); + this.debugShowUrl = options.debugShowUrl ?? false; /** * Function for examining vector lines as they are being streamed. @@ -1066,16 +1006,14 @@ function Cesium3DTileset(options) { this._customShader = options.customShader; - let featureIdLabel = defaultValue(options.featureIdLabel, "featureId_0"); + let featureIdLabel = options.featureIdLabel ?? "featureId_0"; if (typeof featureIdLabel === "number") { featureIdLabel = `featureId_${featureIdLabel}`; } this._featureIdLabel = featureIdLabel; - let instanceFeatureIdLabel = defaultValue( - options.instanceFeatureIdLabel, - "instanceFeatureId_0", - ); + let instanceFeatureIdLabel = + options.instanceFeatureIdLabel ?? "instanceFeatureId_0"; if (typeof instanceFeatureIdLabel === "number") { instanceFeatureIdLabel = `instanceFeatureId_${instanceFeatureIdLabel}`; } @@ -2092,7 +2030,7 @@ Cesium3DTileset.fromUrl = async function (url, options) { Check.defined("url", url); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resource = Resource.createIfNeeded(url); let basePath; @@ -2128,8 +2066,8 @@ Cesium3DTileset.fromUrl = async function (url, options) { const gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis) ? Axis.fromName(tilesetJson.asset.gltfUpAxis) : Axis.Y; - const modelUpAxis = defaultValue(options.modelUpAxis, gltfUpAxis); - const modelForwardAxis = defaultValue(options.modelForwardAxis, Axis.X); + const modelUpAxis = options.modelUpAxis ?? gltfUpAxis; + const modelForwardAxis = options.modelForwardAxis ?? Axis.X; tileset._properties = tilesetJson.properties; tileset._extensionsUsed = tilesetJson.extensionsUsed; @@ -3422,18 +3360,13 @@ Cesium3DTileset.prototype.updateForPass = function ( const passOptions = Cesium3DTilePass.getPassOptions(pass); const ignoreCommands = passOptions.ignoreCommands; - const commandList = defaultValue( - tilesetPassState.commandList, - originalCommandList, - ); + const commandList = tilesetPassState.commandList ?? originalCommandList; const commandStart = commandList.length; frameState.commandList = commandList; - frameState.camera = defaultValue(tilesetPassState.camera, originalCamera); - frameState.cullingVolume = defaultValue( - tilesetPassState.cullingVolume, - originalCullingVolume, - ); + frameState.camera = tilesetPassState.camera ?? originalCamera; + frameState.cullingVolume = + tilesetPassState.cullingVolume ?? originalCullingVolume; if (passOptions.isRender) { const environmentMapManager = this._environmentMapManager; @@ -3653,7 +3586,7 @@ Cesium3DTileset.prototype.updateHeight = function ( callback, ellipsoid, ) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); + ellipsoid = ellipsoid ?? Ellipsoid.WGS84; const object = { positionCartographic: cartographic, diff --git a/packages/engine/Source/Scene/Cesium3DTilesetMetadata.js b/packages/engine/Source/Scene/Cesium3DTilesetMetadata.js index ec92d7a2caeb..efacc41eb80f 100644 --- a/packages/engine/Source/Scene/Cesium3DTilesetMetadata.js +++ b/packages/engine/Source/Scene/Cesium3DTilesetMetadata.js @@ -24,7 +24,7 @@ import TilesetMetadata from "./TilesetMetadata.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function Cesium3DTilesetMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const metadataJson = options.metadataJson; // The calling code is responsible for loading the schema. @@ -37,7 +37,7 @@ function Cesium3DTilesetMetadata(options) { //>>includeEnd('debug'); // An older schema stored the tileset metadata in the "tileset" property. - const metadata = defaultValue(metadataJson.metadata, metadataJson.tileset); + const metadata = metadataJson.metadata ?? metadataJson.tileset; let tileset; if (defined(metadata)) { diff --git a/packages/engine/Source/Scene/CircleEmitter.js b/packages/engine/Source/Scene/CircleEmitter.js index 4fe04e5201bb..4857b0eec776 100644 --- a/packages/engine/Source/Scene/CircleEmitter.js +++ b/packages/engine/Source/Scene/CircleEmitter.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import CesiumMath from "../Core/Math.js"; /** @@ -13,13 +12,13 @@ import CesiumMath from "../Core/Math.js"; * @param {number} [radius=1.0] The radius of the circle in meters. */ function CircleEmitter(radius) { - radius = defaultValue(radius, 1.0); + radius = radius ?? 1.0; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThan("radius", radius, 0.0); //>>includeEnd('debug'); - this._radius = defaultValue(radius, 1.0); + this._radius = radius ?? 1.0; } Object.defineProperties(CircleEmitter.prototype, { diff --git a/packages/engine/Source/Scene/ClassificationPrimitive.js b/packages/engine/Source/Scene/ClassificationPrimitive.js index e08fc9950fdd..278c7c91bf15 100644 --- a/packages/engine/Source/Scene/ClassificationPrimitive.js +++ b/packages/engine/Source/Scene/ClassificationPrimitive.js @@ -70,7 +70,7 @@ import StencilOperation from "./StencilOperation.js"; * @see Appearance */ function ClassificationPrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const geometryInstances = options.geometryInstances; /** @@ -100,7 +100,7 @@ function ClassificationPrimitive(options) { * * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * Determines whether terrain, 3D Tiles or both will be classified. * @@ -108,10 +108,8 @@ function ClassificationPrimitive(options) { * * @default ClassificationType.BOTH */ - this.classificationType = defaultValue( - options.classificationType, - ClassificationType.BOTH, - ); + this.classificationType = + options.classificationType ?? ClassificationType.BOTH; /** * This property is for debugging only; it is not for production use nor is it optimized. *

@@ -122,10 +120,7 @@ function ClassificationPrimitive(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * This property is for debugging only; it is not for production use nor is it optimized. *

@@ -136,14 +131,11 @@ function ClassificationPrimitive(options) { * * @default false */ - this.debugShowShadowVolume = defaultValue( - options.debugShowShadowVolume, - false, - ); + this.debugShowShadowVolume = options.debugShowShadowVolume ?? false; this._debugShowShadowVolume = false; // These are used by GroundPrimitive to augment the shader and uniform map. - this._extruded = defaultValue(options._extruded, false); + this._extruded = options._extruded ?? false; this._uniformMap = options._uniformMap; this._sp = undefined; @@ -181,15 +173,12 @@ function ClassificationPrimitive(options) { this._primitiveOptions = { geometryInstances: undefined, appearance: undefined, - vertexCacheOptimize: defaultValue(options.vertexCacheOptimize, false), - interleave: defaultValue(options.interleave, false), - releaseGeometryInstances: defaultValue( - options.releaseGeometryInstances, - true, - ), - allowPicking: defaultValue(options.allowPicking, true), - asynchronous: defaultValue(options.asynchronous, true), - compressVertices: defaultValue(options.compressVertices, true), + vertexCacheOptimize: options.vertexCacheOptimize ?? false, + interleave: options.interleave ?? false, + releaseGeometryInstances: options.releaseGeometryInstances ?? true, + allowPicking: options.allowPicking ?? true, + asynchronous: options.asynchronous ?? true, + compressVertices: options.compressVertices ?? true, _createBoundingVolumeFunction: undefined, _createRenderStatesFunction: undefined, _createShaderProgramFunction: undefined, @@ -1164,7 +1153,7 @@ ClassificationPrimitive.prototype.update = function (frameState) { attributes: instance.attributes, modelMatrix: instance.modelMatrix, id: instance.id, - pickPrimitive: defaultValue(this._pickPrimitive, that), + pickPrimitive: this._pickPrimitive ?? that, }); } diff --git a/packages/engine/Source/Scene/ClippingPlaneCollection.js b/packages/engine/Source/Scene/ClippingPlaneCollection.js index d1372aafba61..73dc3aa9ab98 100644 --- a/packages/engine/Source/Scene/ClippingPlaneCollection.js +++ b/packages/engine/Source/Scene/ClippingPlaneCollection.js @@ -66,7 +66,7 @@ import ClippingPlane from "./ClippingPlane.js"; * viewer.zoomTo(entity); */ function ClippingPlaneCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._planes = []; @@ -75,7 +75,7 @@ function ClippingPlaneCollection(options) { this._dirtyIndex = -1; this._multipleDirtyPlanes = false; - this._enabled = defaultValue(options.enabled, true); + this._enabled = options.enabled ?? true; /** * The 4x4 transformation matrix specifying an additional transform relative to the clipping planes @@ -84,9 +84,7 @@ function ClippingPlaneCollection(options) { * @type {Matrix4} * @default Matrix4.IDENTITY */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); /** * The color applied to highlight the edge along which an object is clipped. @@ -94,7 +92,7 @@ function ClippingPlaneCollection(options) { * @type {Color} * @default Color.WHITE */ - this.edgeColor = Color.clone(defaultValue(options.edgeColor, Color.WHITE)); + this.edgeColor = Color.clone(options.edgeColor ?? Color.WHITE); /** * The width, in pixels, of the highlight applied to the edge along which an object is clipped. @@ -102,7 +100,7 @@ function ClippingPlaneCollection(options) { * @type {number} * @default 0.0 */ - this.edgeWidth = defaultValue(options.edgeWidth, 0.0); + this.edgeWidth = options.edgeWidth ?? 0.0; /** * An event triggered when a new clipping plane is added to the collection. Event handlers @@ -124,10 +122,7 @@ function ClippingPlaneCollection(options) { // This is because in a Cesium3DTileset multiple models may reference the tileset's ClippingPlaneCollection. this._owner = undefined; - const unionClippingRegions = defaultValue( - options.unionClippingRegions, - false, - ); + const unionClippingRegions = options.unionClippingRegions ?? false; this._unionClippingRegions = unionClippingRegions; this._testIntersection = unionClippingRegions ? unionIntersectFunction diff --git a/packages/engine/Source/Scene/ClippingPolygon.js b/packages/engine/Source/Scene/ClippingPolygon.js index 3b1886aa44b4..0cb368ef1baa 100644 --- a/packages/engine/Source/Scene/ClippingPolygon.js +++ b/packages/engine/Source/Scene/ClippingPolygon.js @@ -1,7 +1,6 @@ import Check from "../Core/Check.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Ellipsoid from "../Core/Ellipsoid.js"; import CesiumMath from "../Core/Math.js"; @@ -46,7 +45,7 @@ function ClippingPolygon(options) { ); //>>includeEnd('debug'); - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.default; this._positions = [...options.positions]; } diff --git a/packages/engine/Source/Scene/ClippingPolygonCollection.js b/packages/engine/Source/Scene/ClippingPolygonCollection.js index b1638373703d..6170aa269bf0 100644 --- a/packages/engine/Source/Scene/ClippingPolygonCollection.js +++ b/packages/engine/Source/Scene/ClippingPolygonCollection.js @@ -58,7 +58,7 @@ import PolygonSignedDistanceFS from "../Shaders/PolygonSignedDistanceFS.js"; * }); */ function ClippingPolygonCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._polygons = []; this._totalPositions = 0; @@ -70,7 +70,7 @@ function ClippingPolygonCollection(options) { * @type {boolean} * @default true */ - this.enabled = defaultValue(options.enabled, true); + this.enabled = options.enabled ?? true; /** * If true, a region will be clipped if it is outside of every polygon in the @@ -81,7 +81,7 @@ function ClippingPolygonCollection(options) { * @type {boolean} * @default false */ - this.inverse = defaultValue(options.inverse, false); + this.inverse = options.inverse ?? false; /** * An event triggered when a new clipping polygon is added to the collection. Event handlers diff --git a/packages/engine/Source/Scene/CloudCollection.js b/packages/engine/Source/Scene/CloudCollection.js index da168182e3ed..f0ca73b8b983 100644 --- a/packages/engine/Source/Scene/CloudCollection.js +++ b/packages/engine/Source/Scene/CloudCollection.js @@ -104,7 +104,7 @@ const COLOR_INDEX = CumulusCloud.COLOR_INDEX; * */ function CloudCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._clouds = []; this._cloudsToUpdate = []; @@ -143,7 +143,7 @@ function CloudCollection(options) { * * @default 16.0 */ - this.noiseDetail = defaultValue(options.noiseDetail, 16.0); + this.noiseDetail = options.noiseDetail ?? 16.0; /** *

@@ -167,9 +167,7 @@ function CloudCollection(options) { * * @default Cartesian3.ZERO */ - this.noiseOffset = Cartesian3.clone( - defaultValue(options.noiseOffset, Cartesian3.ZERO), - ); + this.noiseOffset = Cartesian3.clone(options.noiseOffset ?? Cartesian3.ZERO); this._loading = false; this._ready = false; @@ -198,7 +196,7 @@ function CloudCollection(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; this._colorCommands = []; @@ -212,7 +210,7 @@ function CloudCollection(options) { * * @default false */ - this.debugBillboards = defaultValue(options.debugBillboards, false); + this.debugBillboards = options.debugBillboards ?? false; this._compiledDebugBillboards = false; /** @@ -226,7 +224,7 @@ function CloudCollection(options) { * * @default false */ - this.debugEllipsoids = defaultValue(options.debugEllipsoids, false); + this.debugEllipsoids = options.debugEllipsoids ?? false; this._compiledDebugEllipsoids = false; } @@ -298,8 +296,8 @@ function destroyClouds(clouds) { * @see CloudCollection#removeAll */ CloudCollection.prototype.add = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const cloudType = defaultValue(options.cloudType, CloudType.CUMULUS); + options = options ?? defaultValue.EMPTY_OBJECT; + const cloudType = options.cloudType ?? CloudType.CUMULUS; //>>includeStart('debug', pragmas.debug); if (!CloudType.validate(cloudType)) { throw new DeveloperError("invalid cloud type"); diff --git a/packages/engine/Source/Scene/Composite3DTileContent.js b/packages/engine/Source/Scene/Composite3DTileContent.js index c9636bcda93a..23e4c64bceb3 100644 --- a/packages/engine/Source/Scene/Composite3DTileContent.js +++ b/packages/engine/Source/Scene/Composite3DTileContent.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import getMagic from "../Core/getMagic.js"; @@ -224,7 +223,7 @@ Composite3DTileContent.fromTileType = async function ( byteOffset, factory, ) { - byteOffset = defaultValue(byteOffset, 0); + byteOffset = byteOffset ?? 0; const uint8Array = new Uint8Array(arrayBuffer); const view = new DataView(arrayBuffer); diff --git a/packages/engine/Source/Scene/ConeEmitter.js b/packages/engine/Source/Scene/ConeEmitter.js index 49371c5e6d6d..f1ad406eede3 100644 --- a/packages/engine/Source/Scene/ConeEmitter.js +++ b/packages/engine/Source/Scene/ConeEmitter.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import CesiumMath from "../Core/Math.js"; const defaultAngle = CesiumMath.toRadians(30.0); @@ -15,7 +14,7 @@ const defaultAngle = CesiumMath.toRadians(30.0); * @param {number} [angle=Cesium.Math.toRadians(30.0)] The angle of the cone in radians. */ function ConeEmitter(angle) { - this._angle = defaultValue(angle, defaultAngle); + this._angle = angle ?? defaultAngle; } Object.defineProperties(ConeEmitter.prototype, { diff --git a/packages/engine/Source/Scene/ContentMetadata.js b/packages/engine/Source/Scene/ContentMetadata.js index b09c9077ed3c..407692b02828 100644 --- a/packages/engine/Source/Scene/ContentMetadata.js +++ b/packages/engine/Source/Scene/ContentMetadata.js @@ -19,7 +19,7 @@ import MetadataEntity from "./MetadataEntity.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function ContentMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const content = options.content; const metadataClass = options.class; diff --git a/packages/engine/Source/Scene/CreditDisplay.js b/packages/engine/Source/Scene/CreditDisplay.js index c2716ce8780f..249cc76d66f2 100644 --- a/packages/engine/Source/Scene/CreditDisplay.js +++ b/packages/engine/Source/Scene/CreditDisplay.js @@ -2,7 +2,6 @@ import AssociativeArray from "../Core/AssociativeArray.js"; import buildModuleUrl from "../Core/buildModuleUrl.js"; import Check from "../Core/Check.js"; import Credit from "../Core/Credit.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import Uri from "urijs"; @@ -23,7 +22,7 @@ const highlightColor = "#48b"; */ function CreditDisplayElement(credit, count) { this.credit = credit; - this.count = defaultValue(count, 1); + this.count = count ?? 1; } function contains(credits, credit) { @@ -273,10 +272,7 @@ function appendCss(container) { return undefined; } - const shadowRootOrDocumentHead = defaultValue( - getShadowRoot(container), - document.head, - ); + const shadowRootOrDocumentHead = getShadowRoot(container) ?? document.head; const styleElem = document.createElement("style"); styleElem.innerHTML = style; shadowRootOrDocumentHead.appendChild(styleElem); @@ -308,7 +304,7 @@ function CreditDisplay(container, delimiter, viewport) { //>>includeEnd('debug'); const that = this; - viewport = defaultValue(viewport, document.body); + viewport = viewport ?? document.body; const lightbox = document.createElement("div"); lightbox.className = "cesium-credit-lightbox-overlay"; @@ -359,7 +355,7 @@ function CreditDisplay(container, delimiter, viewport) { appendCss(container); const cesiumCredit = Credit.clone(CreditDisplay.cesiumCredit); - this._delimiter = defaultValue(delimiter, "•"); + this._delimiter = delimiter ?? "•"; this._screenContainer = screenContainer; this._cesiumCreditContainer = cesiumCreditContainer; this._lastViewportHeight = undefined; @@ -394,7 +390,7 @@ function CreditDisplay(container, delimiter, viewport) { } function setCredit(creditDisplay, credits, credit, count) { - count = defaultValue(count, 1); + count = count ?? 1; let creditDisplayElement = credits.get(credit.id); if (!defined(creditDisplayElement)) { const pool = creditDisplay._creditDisplayElementPool; diff --git a/packages/engine/Source/Scene/CumulusCloud.js b/packages/engine/Source/Scene/CumulusCloud.js index bfde2ff7e4f3..e538832eeaa4 100644 --- a/packages/engine/Source/Scene/CumulusCloud.js +++ b/packages/engine/Source/Scene/CumulusCloud.js @@ -34,34 +34,28 @@ import defined from "../Core/defined.js"; * @demo {@link https://sandcastle.cesium.com/index.html?src=Cloud%20Parameters.html|Cesium Sandcastle Cloud Parameters Demo} */ function CumulusCloud(options, cloudCollection) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - this._show = defaultValue(options.show, true); + options = options ?? defaultValue.EMPTY_OBJECT; + this._show = options.show ?? true; - this._position = Cartesian3.clone( - defaultValue(options.position, Cartesian3.ZERO), - ); + this._position = Cartesian3.clone(options.position ?? Cartesian3.ZERO); if (!defined(options.scale) && defined(options.maximumSize)) { this._maximumSize = Cartesian3.clone(options.maximumSize); this._scale = new Cartesian2(this._maximumSize.x, this._maximumSize.y); } else { - this._scale = Cartesian2.clone( - defaultValue(options.scale, new Cartesian2(20.0, 12.0)), - ); + this._scale = Cartesian2.clone(options.scale ?? new Cartesian2(20.0, 12.0)); const defaultMaxSize = new Cartesian3( this._scale.x, this._scale.y, Math.min(this._scale.x, this._scale.y) / 1.5, ); - this._maximumSize = Cartesian3.clone( - defaultValue(options.maximumSize, defaultMaxSize), - ); + this._maximumSize = Cartesian3.clone(options.maximumSize ?? defaultMaxSize); } - this._slice = defaultValue(options.slice, -1.0); - this._color = Color.clone(defaultValue(options.color, Color.WHITE)); - this._brightness = defaultValue(options.brightness, 1.0); + this._slice = options.slice ?? -1.0; + this._color = Color.clone(options.color ?? Color.WHITE); + this._brightness = options.brightness ?? 1.0; this._cloudCollection = cloudCollection; this._index = -1; // Used by CloudCollection } diff --git a/packages/engine/Source/Scene/DebugAppearance.js b/packages/engine/Source/Scene/DebugAppearance.js index f0d2b0fadfeb..e9cd2f9f5571 100644 --- a/packages/engine/Source/Scene/DebugAppearance.js +++ b/packages/engine/Source/Scene/DebugAppearance.js @@ -33,7 +33,7 @@ import Appearance from "./Appearance.js"; * }); */ function DebugAppearance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const attributeName = options.attributeName; let perInstanceAttribute = options.perInstanceAttribute; @@ -47,7 +47,7 @@ function DebugAppearance(options) { perInstanceAttribute = false; } - let glslDatatype = defaultValue(options.glslDatatype, "vec3"); + let glslDatatype = options.glslDatatype ?? "vec3"; const varyingName = `v_${attributeName}`; let getColor; @@ -126,16 +126,16 @@ function DebugAppearance(options) { * * @default false */ - this.translucent = defaultValue(options.translucent, false); + this.translucent = options.translucent ?? false; - this._vertexShaderSource = defaultValue(options.vertexShaderSource, vs); - this._fragmentShaderSource = defaultValue(options.fragmentShaderSource, fs); + this._vertexShaderSource = options.vertexShaderSource ?? vs; + this._fragmentShaderSource = options.fragmentShaderSource ?? fs; this._renderState = Appearance.getDefaultRenderState( false, false, options.renderState, ); - this._closed = defaultValue(options.closed, false); + this._closed = options.closed ?? false; // Non-derived members diff --git a/packages/engine/Source/Scene/DebugCameraPrimitive.js b/packages/engine/Source/Scene/DebugCameraPrimitive.js index d5ad4a421f8a..099ca2baf963 100644 --- a/packages/engine/Source/Scene/DebugCameraPrimitive.js +++ b/packages/engine/Source/Scene/DebugCameraPrimitive.js @@ -38,7 +38,7 @@ import Primitive from "./Primitive.js"; * })); */ function DebugCameraPrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.camera)) { @@ -48,8 +48,8 @@ function DebugCameraPrimitive(options) { this._camera = options.camera; this._frustumSplits = options.frustumSplits; - this._color = defaultValue(options.color, Color.CYAN); - this._updateOnChange = defaultValue(options.updateOnChange, true); + this._color = options.color ?? Color.CYAN; + this._updateOnChange = options.updateOnChange ?? true; /** * Determines if this primitive will be shown. @@ -57,7 +57,7 @@ function DebugCameraPrimitive(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * User-defined value returned when the primitive is picked. diff --git a/packages/engine/Source/Scene/DebugModelMatrixPrimitive.js b/packages/engine/Source/Scene/DebugModelMatrixPrimitive.js index 61214248993c..d7325995818c 100644 --- a/packages/engine/Source/Scene/DebugModelMatrixPrimitive.js +++ b/packages/engine/Source/Scene/DebugModelMatrixPrimitive.js @@ -39,7 +39,7 @@ import Primitive from "./Primitive.js"; * })); */ function DebugModelMatrixPrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The length of the axes in meters. @@ -47,7 +47,7 @@ function DebugModelMatrixPrimitive(options) { * @type {number} * @default 10000000.0 */ - this.length = defaultValue(options.length, 10000000.0); + this.length = options.length ?? 10000000.0; this._length = undefined; /** @@ -56,7 +56,7 @@ function DebugModelMatrixPrimitive(options) { * @type {number} * @default 2.0 */ - this.width = defaultValue(options.width, 2.0); + this.width = options.width ?? 2.0; this._width = undefined; /** @@ -65,7 +65,7 @@ function DebugModelMatrixPrimitive(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * The 4x4 matrix that defines the reference frame, i.e., origin plus axes, to visualize. @@ -73,9 +73,7 @@ function DebugModelMatrixPrimitive(options) { * @type {Matrix4} * @default {@link Matrix4.IDENTITY} */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._modelMatrix = new Matrix4(); /** diff --git a/packages/engine/Source/Scene/DepthPlane.js b/packages/engine/Source/Scene/DepthPlane.js index a45fe0c68ab6..c85d0e62227e 100644 --- a/packages/engine/Source/Scene/DepthPlane.js +++ b/packages/engine/Source/Scene/DepthPlane.js @@ -17,7 +17,6 @@ import VertexArray from "../Renderer/VertexArray.js"; import DepthPlaneFS from "../Shaders/DepthPlaneFS.js"; import DepthPlaneVS from "../Shaders/DepthPlaneVS.js"; import SceneMode from "./SceneMode.js"; -import defaultValue from "../Core/defaultValue.js"; import Ellipsoid from "../Core/Ellipsoid.js"; /** @@ -30,7 +29,7 @@ function DepthPlane(depthPlaneEllipsoidOffset) { this._command = undefined; this._mode = undefined; this._useLogDepth = false; - this._ellipsoidOffset = defaultValue(depthPlaneEllipsoidOffset, 0); + this._ellipsoidOffset = depthPlaneEllipsoidOffset ?? 0; } const depthQuadScratch = FeatureDetection.supportsTypedArrays() diff --git a/packages/engine/Source/Scene/DirectionalLight.js b/packages/engine/Source/Scene/DirectionalLight.js index bdf90c8d883f..856d022b4d48 100644 --- a/packages/engine/Source/Scene/DirectionalLight.js +++ b/packages/engine/Source/Scene/DirectionalLight.js @@ -1,7 +1,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import DeveloperError from "../Core/DeveloperError.js"; /** @@ -37,14 +36,14 @@ function DirectionalLight(options) { * @type {Color} * @default Color.WHITE */ - this.color = Color.clone(defaultValue(options.color, Color.WHITE)); + this.color = Color.clone(options.color ?? Color.WHITE); /** * The intensity of the light. * @type {number} * @default 1.0 */ - this.intensity = defaultValue(options.intensity, 1.0); + this.intensity = options.intensity ?? 1.0; } export default DirectionalLight; diff --git a/packages/engine/Source/Scene/DiscardMissingTileImagePolicy.js b/packages/engine/Source/Scene/DiscardMissingTileImagePolicy.js index 9cf5fc73a4e6..5c705cb54007 100644 --- a/packages/engine/Source/Scene/DiscardMissingTileImagePolicy.js +++ b/packages/engine/Source/Scene/DiscardMissingTileImagePolicy.js @@ -20,7 +20,7 @@ import Resource from "../Core/Resource.js"; * discard check will proceed no matter the values of the pixelsToCheck. */ function DiscardMissingTileImagePolicy(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.missingImageUrl)) { diff --git a/packages/engine/Source/Scene/EllipsoidPrimitive.js b/packages/engine/Source/Scene/EllipsoidPrimitive.js index ab7d70811787..82c21917e754 100644 --- a/packages/engine/Source/Scene/EllipsoidPrimitive.js +++ b/packages/engine/Source/Scene/EllipsoidPrimitive.js @@ -47,7 +47,7 @@ const attributeLocations = { * @private */ function EllipsoidPrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The center of the ellipsoid in the ellipsoid's model coordinates. @@ -60,7 +60,7 @@ function EllipsoidPrimitive(options) { * * @see EllipsoidPrimitive#modelMatrix */ - this.center = Cartesian3.clone(defaultValue(options.center, Cartesian3.ZERO)); + this.center = Cartesian3.clone(options.center ?? Cartesian3.ZERO); this._center = new Cartesian3(); /** @@ -99,9 +99,7 @@ function EllipsoidPrimitive(options) { * const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0); * e.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin); */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._modelMatrix = new Matrix4(); this._computedModelMatrix = new Matrix4(); @@ -111,7 +109,7 @@ function EllipsoidPrimitive(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * The surface appearance of the ellipsoid. This can be one of several built-in {@link Material} objects or a custom material, scripted with @@ -133,10 +131,7 @@ function EllipsoidPrimitive(options) { * * @see {@link https://github.com/CesiumGS/cesium/wiki/Fabric|Fabric} */ - this.material = defaultValue( - options.material, - Material.fromType(Material.ColorType), - ); + this.material = options.material ?? Material.fromType(Material.ColorType); this._material = undefined; this._translucent = undefined; @@ -162,21 +157,18 @@ function EllipsoidPrimitive(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * @private */ - this.onlySunLighting = defaultValue(options.onlySunLighting, false); + this.onlySunLighting = options.onlySunLighting ?? false; this._onlySunLighting = false; /** * @private */ - this._depthTestEnabled = defaultValue(options.depthTestEnabled, true); + this._depthTestEnabled = options.depthTestEnabled ?? true; this._useLogDepth = false; @@ -188,10 +180,10 @@ function EllipsoidPrimitive(options) { this._pickId = undefined; this._colorCommand = new DrawCommand({ - owner: defaultValue(options._owner, this), + owner: options._owner ?? this, }); this._pickCommand = new DrawCommand({ - owner: defaultValue(options._owner, this), + owner: options._owner ?? this, pickOnly: true, }); diff --git a/packages/engine/Source/Scene/EllipsoidSurfaceAppearance.js b/packages/engine/Source/Scene/EllipsoidSurfaceAppearance.js index f51ed1d2bcda..908569b8f6d0 100644 --- a/packages/engine/Source/Scene/EllipsoidSurfaceAppearance.js +++ b/packages/engine/Source/Scene/EllipsoidSurfaceAppearance.js @@ -42,10 +42,10 @@ import Material from "./Material.js"; * }); */ function EllipsoidSurfaceAppearance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const translucent = defaultValue(options.translucent, true); - const aboveGround = defaultValue(options.aboveGround, false); + const translucent = options.translucent ?? true; + const aboveGround = options.aboveGround ?? false; /** * The material used to determine the fragment color. Unlike other {@link EllipsoidSurfaceAppearance} @@ -68,16 +68,12 @@ function EllipsoidSurfaceAppearance(options) { * * @default true */ - this.translucent = defaultValue(options.translucent, true); + this.translucent = options.translucent ?? true; - this._vertexShaderSource = defaultValue( - options.vertexShaderSource, - EllipsoidSurfaceAppearanceVS, - ); - this._fragmentShaderSource = defaultValue( - options.fragmentShaderSource, - EllipsoidSurfaceAppearanceFS, - ); + this._vertexShaderSource = + options.vertexShaderSource ?? EllipsoidSurfaceAppearanceVS; + this._fragmentShaderSource = + options.fragmentShaderSource ?? EllipsoidSurfaceAppearanceFS; this._renderState = Appearance.getDefaultRenderState( translucent, !aboveGround, @@ -87,8 +83,8 @@ function EllipsoidSurfaceAppearance(options) { // Non-derived members - this._flat = defaultValue(options.flat, false); - this._faceForward = defaultValue(options.faceForward, aboveGround); + this._flat = options.flat ?? false; + this._faceForward = options.faceForward ?? aboveGround; this._aboveGround = aboveGround; } diff --git a/packages/engine/Source/Scene/FrameRateMonitor.js b/packages/engine/Source/Scene/FrameRateMonitor.js index 3e7f3ae5053a..2a874566262e 100644 --- a/packages/engine/Source/Scene/FrameRateMonitor.js +++ b/packages/engine/Source/Scene/FrameRateMonitor.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -42,30 +41,24 @@ function FrameRateMonitor(options) { * Gets or sets the length of the sliding window over which to compute the average frame rate, in seconds. * @type {number} */ - this.samplingWindow = defaultValue( - options.samplingWindow, - FrameRateMonitor.defaultSettings.samplingWindow, - ); + this.samplingWindow = + options.samplingWindow ?? FrameRateMonitor.defaultSettings.samplingWindow; /** * Gets or sets the length of time to wait at startup and each time the page becomes visible (i.e. when the user * switches back to the tab) before starting to measure performance, in seconds. * @type {number} */ - this.quietPeriod = defaultValue( - options.quietPeriod, - FrameRateMonitor.defaultSettings.quietPeriod, - ); + this.quietPeriod = + options.quietPeriod ?? FrameRateMonitor.defaultSettings.quietPeriod; /** * Gets or sets the length of the warmup period, in seconds. During the warmup period, a separate * (usually lower) frame rate is required. * @type {number} */ - this.warmupPeriod = defaultValue( - options.warmupPeriod, - FrameRateMonitor.defaultSettings.warmupPeriod, - ); + this.warmupPeriod = + options.warmupPeriod ?? FrameRateMonitor.defaultSettings.warmupPeriod; /** * Gets or sets the minimum frames-per-second that are required for acceptable performance during @@ -73,10 +66,9 @@ function FrameRateMonitor(options) { * lowFrameRate event will be raised and the page will redirect to the redirectOnLowFrameRateUrl, if any. * @type {number} */ - this.minimumFrameRateDuringWarmup = defaultValue( - options.minimumFrameRateDuringWarmup, - FrameRateMonitor.defaultSettings.minimumFrameRateDuringWarmup, - ); + this.minimumFrameRateDuringWarmup = + options.minimumFrameRateDuringWarmup ?? + FrameRateMonitor.defaultSettings.minimumFrameRateDuringWarmup; /** * Gets or sets the minimum frames-per-second that are required for acceptable performance after @@ -84,10 +76,9 @@ function FrameRateMonitor(options) { * lowFrameRate event will be raised and the page will redirect to the redirectOnLowFrameRateUrl, if any. * @type {number} */ - this.minimumFrameRateAfterWarmup = defaultValue( - options.minimumFrameRateAfterWarmup, - FrameRateMonitor.defaultSettings.minimumFrameRateAfterWarmup, - ); + this.minimumFrameRateAfterWarmup = + options.minimumFrameRateAfterWarmup ?? + FrameRateMonitor.defaultSettings.minimumFrameRateAfterWarmup; this._lowFrameRate = new Event(); this._nominalFrameRate = new Event(); diff --git a/packages/engine/Source/Scene/FrustumCommands.js b/packages/engine/Source/Scene/FrustumCommands.js index 1e374378e22a..c779da8182ae 100644 --- a/packages/engine/Source/Scene/FrustumCommands.js +++ b/packages/engine/Source/Scene/FrustumCommands.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import Pass from "../Renderer/Pass.js"; /** @@ -12,8 +11,8 @@ import Pass from "../Renderer/Pass.js"; * @private */ function FrustumCommands(near, far) { - this.near = defaultValue(near, 0.0); - this.far = defaultValue(far, 0.0); + this.near = near ?? 0.0; + this.far = far ?? 0.0; const numPasses = Pass.NUMBER_OF_PASSES; const commands = new Array(numPasses); diff --git a/packages/engine/Source/Scene/Geometry3DTileContent.js b/packages/engine/Source/Scene/Geometry3DTileContent.js index 17685da7cd65..b17f7463251b 100644 --- a/packages/engine/Source/Scene/Geometry3DTileContent.js +++ b/packages/engine/Source/Scene/Geometry3DTileContent.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -171,13 +170,10 @@ function getBatchIds(featureTableJson, featureTableBinary) { let sphereBatchIds; let i; - const numberOfBoxes = defaultValue(featureTableJson.BOXES_LENGTH, 0); - const numberOfCylinders = defaultValue(featureTableJson.CYLINDERS_LENGTH, 0); - const numberOfEllipsoids = defaultValue( - featureTableJson.ELLIPSOIDS_LENGTH, - 0, - ); - const numberOfSpheres = defaultValue(featureTableJson.SPHERES_LENGTH, 0); + const numberOfBoxes = featureTableJson.BOXES_LENGTH ?? 0; + const numberOfCylinders = featureTableJson.CYLINDERS_LENGTH ?? 0; + const numberOfEllipsoids = featureTableJson.ELLIPSOIDS_LENGTH ?? 0; + const numberOfSpheres = featureTableJson.SPHERES_LENGTH ?? 0; if (numberOfBoxes > 0 && defined(featureTableJson.BOX_BATCH_IDS)) { const boxBatchIdsByteOffset = @@ -283,7 +279,7 @@ function getBatchIds(featureTableJson, featureTableBinary) { const sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; function initialize(content, arrayBuffer, byteOffset) { - byteOffset = defaultValue(byteOffset, 0); + byteOffset = byteOffset ?? 0; const uint8Array = new Uint8Array(arrayBuffer); const view = new DataView(arrayBuffer); @@ -362,13 +358,10 @@ function initialize(content, arrayBuffer, byteOffset) { } } - const numberOfBoxes = defaultValue(featureTableJson.BOXES_LENGTH, 0); - const numberOfCylinders = defaultValue(featureTableJson.CYLINDERS_LENGTH, 0); - const numberOfEllipsoids = defaultValue( - featureTableJson.ELLIPSOIDS_LENGTH, - 0, - ); - const numberOfSpheres = defaultValue(featureTableJson.SPHERES_LENGTH, 0); + const numberOfBoxes = featureTableJson.BOXES_LENGTH ?? 0; + const numberOfCylinders = featureTableJson.CYLINDERS_LENGTH ?? 0; + const numberOfEllipsoids = featureTableJson.ELLIPSOIDS_LENGTH ?? 0; + const numberOfSpheres = featureTableJson.SPHERES_LENGTH ?? 0; const totalPrimitives = numberOfBoxes + numberOfCylinders + numberOfEllipsoids + numberOfSpheres; diff --git a/packages/engine/Source/Scene/Globe.js b/packages/engine/Source/Scene/Globe.js index ca2c6a611be9..d659f993c385 100644 --- a/packages/engine/Source/Scene/Globe.js +++ b/packages/engine/Source/Scene/Globe.js @@ -3,7 +3,6 @@ import buildModuleUrl from "../Core/buildModuleUrl.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -41,7 +40,7 @@ import CesiumMath from "../Core/Math.js"; * globe. */ function Globe(ellipsoid) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); + ellipsoid = ellipsoid ?? Ellipsoid.default; const terrainProvider = new EllipsoidTerrainProvider({ ellipsoid: ellipsoid, }); @@ -716,7 +715,7 @@ Globe.prototype.pickWorldCoordinates = function ( } //>>includeEnd('debug'); - cullBackFaces = defaultValue(cullBackFaces, true); + cullBackFaces = cullBackFaces ?? true; const mode = scene.mode; const projection = scene.mapProjection; @@ -931,7 +930,7 @@ Globe.prototype.getHeight = function (cartographic) { if (defined(tile.data.tileBoundingRegion)) { minimumHeight = tile.data.tileBoundingRegion.minimumHeight; } - const magnitude = Math.min(defaultValue(minimumHeight, 0.0), -11500.0); + const magnitude = Math.min(minimumHeight ?? 0.0, -11500.0); // multiply by the *positive* value of the magnitude const vectorToMinimumPoint = Cartesian3.multiplyByScalar( diff --git a/packages/engine/Source/Scene/GlobeSurfaceTileProvider.js b/packages/engine/Source/Scene/GlobeSurfaceTileProvider.js index 6aeab65e44af..41e4ecaac4a2 100644 --- a/packages/engine/Source/Scene/GlobeSurfaceTileProvider.js +++ b/packages/engine/Source/Scene/GlobeSurfaceTileProvider.js @@ -8,7 +8,6 @@ import clone from "../Core/clone.js"; import Color from "../Core/Color.js"; import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js"; import combine from "../Core/combine.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -1440,10 +1439,7 @@ function getTileReadyCallback(tileImageriesToFree, layer, terrainProvider) { let i; for (i = 0; i < length; ++i) { tileImagery = tileImageryCollection[i]; - imagery = defaultValue( - tileImagery.readyImagery, - tileImagery.loadingImagery, - ); + imagery = tileImagery.readyImagery ?? tileImagery.loadingImagery; if (imagery.imageryLayer === layer) { startIndex = i; break; @@ -1454,7 +1450,7 @@ function getTileReadyCallback(tileImageriesToFree, layer, terrainProvider) { const endIndex = startIndex + tileImageriesToFree; tileImagery = tileImageryCollection[endIndex]; imagery = defined(tileImagery) - ? defaultValue(tileImagery.readyImagery, tileImagery.loadingImagery) + ? (tileImagery.readyImagery ?? tileImagery.loadingImagery) : undefined; if (!defined(imagery) || imagery.imageryLayer !== layer) { // Return false to keep the callback if we have to wait on the skeletons @@ -1506,10 +1502,8 @@ GlobeSurfaceTileProvider.prototype._onLayerAdded = function (layer, index) { let tileImageriesToFree = 0; for (i = 0; i < length; ++i) { const tileImagery = tileImageryCollection[i]; - const imagery = defaultValue( - tileImagery.readyImagery, - tileImagery.loadingImagery, - ); + const imagery = + tileImagery.readyImagery ?? tileImagery.loadingImagery; if (imagery.imageryLayer === layer) { if (startIndex === -1) { startIndex = i; @@ -2166,14 +2160,11 @@ function addDrawCommandsForTile(tileProvider, tile, frameState) { globeTranslucencyState.backFaceAlphaByDistance; const translucencyRectangle = globeTranslucencyState.rectangle; - const undergroundColor = defaultValue( - tileProvider.undergroundColor, - defaultUndergroundColor, - ); - const undergroundColorAlphaByDistance = defaultValue( - tileProvider.undergroundColorAlphaByDistance, - defaultUndergroundColorAlphaByDistance, - ); + const undergroundColor = + tileProvider.undergroundColor ?? defaultUndergroundColor; + const undergroundColorAlphaByDistance = + tileProvider.undergroundColorAlphaByDistance ?? + defaultUndergroundColorAlphaByDistance; const showUndergroundColor = isUndergroundVisible(tileProvider, frameState) && frameState.mode === SceneMode.SCENE3D && diff --git a/packages/engine/Source/Scene/GlobeTranslucencyState.js b/packages/engine/Source/Scene/GlobeTranslucencyState.js index c26d7da41d68..d0300696840d 100644 --- a/packages/engine/Source/Scene/GlobeTranslucencyState.js +++ b/packages/engine/Source/Scene/GlobeTranslucencyState.js @@ -1,5 +1,4 @@ import combine from "../Core/combine.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import NearFarScalar from "../Core/NearFarScalar.js"; import Rectangle from "../Core/Rectangle.js"; @@ -807,18 +806,12 @@ function updateDerivedCommands( const frameNumber = frameState.frameNumber; - const uniformMapDirtyFrame = defaultValue( - derivedCommandsObject.uniformMapDirtyFrame, - 0, - ); - const shaderProgramDirtyFrame = defaultValue( - derivedCommandsObject.shaderProgramDirtyFrame, - 0, - ); - const renderStateDirtyFrame = defaultValue( - derivedCommandsObject.renderStateDirtyFrame, - 0, - ); + const uniformMapDirtyFrame = + derivedCommandsObject.uniformMapDirtyFrame ?? 0; + const shaderProgramDirtyFrame = + derivedCommandsObject.shaderProgramDirtyFrame ?? 0; + const renderStateDirtyFrame = + derivedCommandsObject.renderStateDirtyFrame ?? 0; const uniformMapDirty = derivedCommandsObject.uniformMap !== command.uniformMap; @@ -866,18 +859,12 @@ function updateDerivedCommands( derivedCommand = DrawCommand.shallowClone(command, derivedCommand); derivedCommandsObject[derivedCommandName] = derivedCommand; - const derivedUniformMapDirtyFrame = defaultValue( - derivedCommand.derivedCommands.uniformMapDirtyFrame, - 0, - ); - const derivedShaderProgramDirtyFrame = defaultValue( - derivedCommand.derivedCommands.shaderProgramDirtyFrame, - 0, - ); - const derivedRenderStateDirtyFrame = defaultValue( - derivedCommand.derivedCommands.renderStateDirtyFrame, - 0, - ); + const derivedUniformMapDirtyFrame = + derivedCommand.derivedCommands.uniformMapDirtyFrame ?? 0; + const derivedShaderProgramDirtyFrame = + derivedCommand.derivedCommands.shaderProgramDirtyFrame ?? 0; + const derivedRenderStateDirtyFrame = + derivedCommand.derivedCommands.renderStateDirtyFrame ?? 0; const derivedUniformMapDirty = uniformMapDirty || derivedUniformMapDirtyFrame < uniformMapDirtyFrame; diff --git a/packages/engine/Source/Scene/GltfBufferViewLoader.js b/packages/engine/Source/Scene/GltfBufferViewLoader.js index b53275b5e3c0..544c10e18929 100644 --- a/packages/engine/Source/Scene/GltfBufferViewLoader.js +++ b/packages/engine/Source/Scene/GltfBufferViewLoader.js @@ -27,7 +27,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @private */ function GltfBufferViewLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resourceCache = options.resourceCache; const gltf = options.gltf; const bufferViewId = options.bufferViewId; @@ -57,14 +57,14 @@ function GltfBufferViewLoader(options) { if (hasExtension(bufferView, "EXT_meshopt_compression")) { const meshopt = bufferView.extensions.EXT_meshopt_compression; bufferId = meshopt.buffer; - byteOffset = defaultValue(meshopt.byteOffset, 0); + byteOffset = meshopt.byteOffset ?? 0; byteLength = meshopt.byteLength; hasMeshopt = true; meshoptByteStride = meshopt.byteStride; meshoptCount = meshopt.count; meshoptMode = meshopt.mode; - meshoptFilter = defaultValue(meshopt.filter, "NONE"); + meshoptFilter = meshopt.filter ?? "NONE"; } const buffer = gltf.buffers[bufferId]; diff --git a/packages/engine/Source/Scene/GltfDracoLoader.js b/packages/engine/Source/Scene/GltfDracoLoader.js index a1902e0ba848..02c411a4a5d5 100644 --- a/packages/engine/Source/Scene/GltfDracoLoader.js +++ b/packages/engine/Source/Scene/GltfDracoLoader.js @@ -26,7 +26,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @private */ function GltfDracoLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resourceCache = options.resourceCache; const gltf = options.gltf; const draco = options.draco; diff --git a/packages/engine/Source/Scene/GltfImageLoader.js b/packages/engine/Source/Scene/GltfImageLoader.js index 91ae40022b81..2204017fd475 100644 --- a/packages/engine/Source/Scene/GltfImageLoader.js +++ b/packages/engine/Source/Scene/GltfImageLoader.js @@ -28,7 +28,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @private */ function GltfImageLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resourceCache = options.resourceCache; const gltf = options.gltf; const imageId = options.imageId; diff --git a/packages/engine/Source/Scene/GltfIndexBufferLoader.js b/packages/engine/Source/Scene/GltfIndexBufferLoader.js index 5a46f8e43535..6cd4f6c98889 100644 --- a/packages/engine/Source/Scene/GltfIndexBufferLoader.js +++ b/packages/engine/Source/Scene/GltfIndexBufferLoader.js @@ -35,7 +35,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @private */ function GltfIndexBufferLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resourceCache = options.resourceCache; const gltf = options.gltf; const accessorId = options.accessorId; @@ -43,9 +43,9 @@ function GltfIndexBufferLoader(options) { const baseResource = options.baseResource; const draco = options.draco; const cacheKey = options.cacheKey; - const asynchronous = defaultValue(options.asynchronous, true); - const loadBuffer = defaultValue(options.loadBuffer, false); - const loadTypedArray = defaultValue(options.loadTypedArray, false); + const asynchronous = options.asynchronous ?? true; + const loadBuffer = options.loadBuffer ?? false; + const loadTypedArray = options.loadTypedArray ?? false; //>>includeStart('debug', pragmas.debug); Check.typeOf.func("options.resourceCache", resourceCache); diff --git a/packages/engine/Source/Scene/GltfJsonLoader.js b/packages/engine/Source/Scene/GltfJsonLoader.js index 5f6b7dc3daac..cfcd5f1ccf32 100644 --- a/packages/engine/Source/Scene/GltfJsonLoader.js +++ b/packages/engine/Source/Scene/GltfJsonLoader.js @@ -38,7 +38,7 @@ import ModelUtility from "./Model/ModelUtility.js"; * @private */ function GltfJsonLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resourceCache = options.resourceCache; const gltfResource = options.gltfResource; const baseResource = options.baseResource; diff --git a/packages/engine/Source/Scene/GltfLoader.js b/packages/engine/Source/Scene/GltfLoader.js index d853d90d73dc..b057bd011105 100644 --- a/packages/engine/Source/Scene/GltfLoader.js +++ b/packages/engine/Source/Scene/GltfLoader.js @@ -195,7 +195,7 @@ const GltfLoaderState = { * @private */ function GltfLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltfResource, typedArray, @@ -851,7 +851,7 @@ async function loadAccessorBufferView( bufferViewLoader.typedArray, ); - useQuaternion = defaultValue(useQuaternion, false); + useQuaternion = useQuaternion ?? false; loadAccessorValues(accessor, typedArray, values, useQuaternion); } @@ -1000,7 +1000,7 @@ function setQuantizationFromWeb3dQuantizedAttributes( function createAttribute(gltf, accessorId, name, semantic, setIndex) { const accessor = gltf.accessors[accessorId]; const MathType = AttributeType.getMathType(accessor.type); - const normalized = defaultValue(accessor.normalized, false); + const normalized = accessor.normalized ?? false; const attribute = new Attribute(); attribute.name = name; @@ -1659,10 +1659,7 @@ function loadClearcoat(loader, clearcoatInfo, frameState) { function loadMaterial(loader, gltfMaterial, frameState) { const material = new Material(); - const extensions = defaultValue( - gltfMaterial.extensions, - defaultValue.EMPTY_OBJECT, - ); + const extensions = gltfMaterial.extensions ?? defaultValue.EMPTY_OBJECT; const pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness; const pbrSpecular = extensions.KHR_materials_specular; const pbrAnisotropy = extensions.KHR_materials_anisotropy; @@ -1783,9 +1780,9 @@ function loadFeatureIdImplicitRangeLegacy( featureIdRange.featureCount = featureCount; // constant/divisor was renamed to offset/repeat - featureIdRange.offset = defaultValue(featureIds.constant, 0); + featureIdRange.offset = featureIds.constant ?? 0; // The default is now undefined - const divisor = defaultValue(featureIds.divisor, 0); + const divisor = featureIds.divisor ?? 0; featureIdRange.repeat = divisor === 0 ? undefined : divisor; featureIdRange.positionalLabel = positionalLabel; @@ -1923,10 +1920,7 @@ function loadPrimitive(loader, gltfPrimitive, hasInstances, frameState) { ); } - const extensions = defaultValue( - gltfPrimitive.extensions, - defaultValue.EMPTY_OBJECT, - ); + const extensions = gltfPrimitive.extensions ?? defaultValue.EMPTY_OBJECT; let needsPostProcessing = false; const outlineExtension = extensions.CESIUM_primitive_outline; @@ -2227,10 +2221,8 @@ function loadInstances(loader, nodeExtensions, frameState) { } } - const instancingExtExtensions = defaultValue( - instancingExtension.extensions, - defaultValue.EMPTY_OBJECT, - ); + const instancingExtExtensions = + instancingExtension.extensions ?? defaultValue.EMPTY_OBJECT; const instanceFeatures = nodeExtensions.EXT_instance_features; const featureMetadataLegacy = instancingExtExtensions.EXT_feature_metadata; @@ -2328,10 +2320,7 @@ function loadNode(loader, gltfNode, frameState) { node.rotation = fromArray(Quaternion, gltfNode.rotation); node.scale = fromArray(Cartesian3, gltfNode.scale); - const nodeExtensions = defaultValue( - gltfNode.extensions, - defaultValue.EMPTY_OBJECT, - ); + const nodeExtensions = gltfNode.extensions ?? defaultValue.EMPTY_OBJECT; const instancingExtension = nodeExtensions.EXT_mesh_gpu_instancing; const articulationsExtension = nodeExtensions.AGI_articulations; @@ -2365,7 +2354,7 @@ function loadNode(loader, gltfNode, frameState) { // If the node has no weights array, it will look for the weights array provided // by the mesh. If both are undefined, it will default to an array of zero weights. - const morphWeights = defaultValue(gltfNode.weights, mesh.weights); + const morphWeights = gltfNode.weights ?? mesh.weights; const targets = node.primitives[0].morphTargets; // Since meshes are not stored as separate components, the mesh weights will still @@ -2495,10 +2484,8 @@ function loadAnimationSampler(loader, gltfSampler) { animationSampler.input = loadAccessor(loader, inputAccessor); const gltfInterpolation = gltfSampler.interpolation; - animationSampler.interpolation = defaultValue( - InterpolationType[gltfInterpolation], - InterpolationType.LINEAR, - ); + animationSampler.interpolation = + InterpolationType[gltfInterpolation] ?? InterpolationType.LINEAR; const outputAccessor = accessors[gltfSampler.output]; animationSampler.output = loadAccessor(loader, outputAccessor, true); @@ -2593,7 +2580,7 @@ function loadArticulation(articulationJson) { } function loadArticulations(gltf) { - const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT); + const extensions = gltf.extensions ?? defaultValue.EMPTY_OBJECT; const articulationJsons = extensions.AGI_articulations?.articulations; if (!defined(articulationJsons)) { return []; @@ -2606,7 +2593,7 @@ function getSceneNodeIds(gltf) { if (defined(gltf.scenes) && defined(gltf.scene)) { nodesIds = gltf.scenes[gltf.scene].nodes; } - nodesIds = defaultValue(nodesIds, gltf.nodes); + nodesIds = nodesIds ?? gltf.nodes; nodesIds = defined(nodesIds) ? nodesIds : []; return nodesIds; } @@ -2639,7 +2626,7 @@ const scratchCenter = new Cartesian3(); */ function parse(loader, frameState) { const gltf = loader.gltfJson; - const extensions = defaultValue(gltf.extensions, defaultValue.EMPTY_OBJECT); + const extensions = gltf.extensions ?? defaultValue.EMPTY_OBJECT; const structuralMetadataExtension = extensions.EXT_structural_metadata; const featureMetadataExtensionLegacy = extensions.EXT_feature_metadata; const cesiumRtcExtension = extensions.CESIUM_RTC; diff --git a/packages/engine/Source/Scene/GltfLoaderUtil.js b/packages/engine/Source/Scene/GltfLoaderUtil.js index e2d76e46d722..0783208cb94d 100644 --- a/packages/engine/Source/Scene/GltfLoaderUtil.js +++ b/packages/engine/Source/Scene/GltfLoaderUtil.js @@ -34,7 +34,7 @@ const GltfLoaderUtil = {}; * @private */ GltfLoaderUtil.getImageIdFromTexture = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, textureId, supportedImageFormats } = options; //>>includeStart('debug', pragmas.debug); @@ -70,7 +70,7 @@ GltfLoaderUtil.getImageIdFromTexture = function (options) { * @private */ GltfLoaderUtil.createSampler = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, textureInfo, compressedTextureNoMipmap = false } = options; //>>includeStart('debug', pragmas.debug); @@ -90,10 +90,10 @@ GltfLoaderUtil.createSampler = function (options) { if (defined(samplerId)) { const sampler = gltf.samplers[samplerId]; - wrapS = defaultValue(sampler.wrapS, wrapS); - wrapT = defaultValue(sampler.wrapT, wrapT); - minFilter = defaultValue(sampler.minFilter, minFilter); - magFilter = defaultValue(sampler.magFilter, magFilter); + wrapS = sampler.wrapS ?? wrapS; + wrapT = sampler.wrapT ?? wrapT; + minFilter = sampler.minFilter ?? minFilter; + magFilter = sampler.magFilter ?? magFilter; } if ( @@ -132,25 +132,25 @@ const defaultScale = new Cartesian2(1.0, 1.0); * @returns {ModelComponents.TextureReader} The texture reader for this model. */ GltfLoaderUtil.createModelTextureReader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { textureInfo, channels, texture } = options; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.textureInfo", textureInfo); //>>includeEnd('debug'); - let texCoord = defaultValue(textureInfo.texCoord, 0); + let texCoord = textureInfo.texCoord ?? 0; let transform; const textureTransform = textureInfo.extensions?.KHR_texture_transform; if (defined(textureTransform)) { - texCoord = defaultValue(textureTransform.texCoord, texCoord); + texCoord = textureTransform.texCoord ?? texCoord; const offset = defined(textureTransform.offset) ? Cartesian2.unpack(textureTransform.offset) : Cartesian2.ZERO; - let rotation = defaultValue(textureTransform.rotation, 0.0); + let rotation = textureTransform.rotation ?? 0.0; const scale = defined(textureTransform.scale) ? Cartesian2.unpack(textureTransform.scale) : defaultScale; diff --git a/packages/engine/Source/Scene/GltfPipeline/addDefaults.js b/packages/engine/Source/Scene/GltfPipeline/addDefaults.js index d67b10fd98b4..ea6811f0b3a2 100644 --- a/packages/engine/Source/Scene/GltfPipeline/addDefaults.js +++ b/packages/engine/Source/Scene/GltfPipeline/addDefaults.js @@ -16,19 +16,19 @@ import WebGLConstants from "../../Core/WebGLConstants.js"; function addDefaults(gltf) { ForEach.accessor(gltf, function (accessor) { if (defined(accessor.bufferView)) { - accessor.byteOffset = defaultValue(accessor.byteOffset, 0); + accessor.byteOffset = accessor.byteOffset ?? 0; } }); ForEach.bufferView(gltf, function (bufferView) { if (defined(bufferView.buffer)) { - bufferView.byteOffset = defaultValue(bufferView.byteOffset, 0); + bufferView.byteOffset = bufferView.byteOffset ?? 0; } }); ForEach.mesh(gltf, function (mesh) { ForEach.meshPrimitive(mesh, function (primitive) { - primitive.mode = defaultValue(primitive.mode, WebGLConstants.TRIANGLES); + primitive.mode = primitive.mode ?? WebGLConstants.TRIANGLES; if (!defined(primitive.material)) { if (!defined(gltf.materials)) { gltf.materials = []; @@ -44,7 +44,7 @@ function addDefaults(gltf) { ForEach.accessorContainingVertexAttributeData(gltf, function (accessorId) { const accessor = gltf.accessors[accessorId]; const bufferViewId = accessor.bufferView; - accessor.normalized = defaultValue(accessor.normalized, false); + accessor.normalized = accessor.normalized ?? false; if (defined(bufferViewId)) { const bufferView = gltf.bufferViews[bufferViewId]; bufferView.byteStride = getAccessorByteStride(gltf, accessor); @@ -62,10 +62,7 @@ function addDefaults(gltf) { }); ForEach.material(gltf, function (material) { - const extensions = defaultValue( - material.extensions, - defaultValue.EMPTY_OBJECT - ); + const extensions = material.extensions ?? defaultValue.EMPTY_OBJECT; const materialsCommon = extensions.KHR_materials_common; if (defined(materialsCommon)) { const technique = materialsCommon.technique; @@ -81,7 +78,7 @@ function addDefaults(gltf) { ? values.emission : [0.0, 0.0, 0.0, 1.0]; - values.transparency = defaultValue(values.transparency, 1.0); + values.transparency = values.transparency ?? 1.0; if (technique !== "CONSTANT") { values.diffuse = defined(values.diffuse) @@ -91,32 +88,23 @@ function addDefaults(gltf) { values.specular = defined(values.specular) ? values.specular : [0.0, 0.0, 0.0, 1.0]; - values.shininess = defaultValue(values.shininess, 0.0); + values.shininess = values.shininess ?? 0.0; } } // These actually exist on the extension object, not the values object despite what's shown in the spec - materialsCommon.transparent = defaultValue( - materialsCommon.transparent, - false - ); - materialsCommon.doubleSided = defaultValue( - materialsCommon.doubleSided, - false - ); + materialsCommon.transparent = materialsCommon.transparent ?? false; + materialsCommon.doubleSided = materialsCommon.doubleSided ?? false; return; } - material.emissiveFactor = defaultValue( - material.emissiveFactor, - [0.0, 0.0, 0.0] - ); - material.alphaMode = defaultValue(material.alphaMode, "OPAQUE"); - material.doubleSided = defaultValue(material.doubleSided, false); + material.emissiveFactor = material.emissiveFactor ?? [0.0, 0.0, 0.0]; + material.alphaMode = material.alphaMode ?? "OPAQUE"; + material.doubleSided = material.doubleSided ?? false; if (material.alphaMode === "MASK") { - material.alphaCutoff = defaultValue(material.alphaCutoff, 0.5); + material.alphaCutoff = material.alphaCutoff ?? 0.5; } const techniquesExtension = extensions.KHR_techniques_webgl; @@ -135,18 +123,9 @@ function addDefaults(gltf) { const pbrMetallicRoughness = material.pbrMetallicRoughness; if (defined(pbrMetallicRoughness)) { - pbrMetallicRoughness.baseColorFactor = defaultValue( - pbrMetallicRoughness.baseColorFactor, - [1.0, 1.0, 1.0, 1.0] - ); - pbrMetallicRoughness.metallicFactor = defaultValue( - pbrMetallicRoughness.metallicFactor, - 1.0 - ); - pbrMetallicRoughness.roughnessFactor = defaultValue( - pbrMetallicRoughness.roughnessFactor, - 1.0 - ); + pbrMetallicRoughness.baseColorFactor = pbrMetallicRoughness.baseColorFactor ?? [1.0, 1.0, 1.0, 1.0]; + pbrMetallicRoughness.metallicFactor = pbrMetallicRoughness.metallicFactor ?? 1.0; + pbrMetallicRoughness.roughnessFactor = pbrMetallicRoughness.roughnessFactor ?? 1.0; addTextureDefaults(pbrMetallicRoughness.baseColorTexture); addTextureDefaults(pbrMetallicRoughness.metallicRoughnessTexture); } @@ -154,25 +133,16 @@ function addDefaults(gltf) { const pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness; if (defined(pbrSpecularGlossiness)) { - pbrSpecularGlossiness.diffuseFactor = defaultValue( - pbrSpecularGlossiness.diffuseFactor, - [1.0, 1.0, 1.0, 1.0] - ); - pbrSpecularGlossiness.specularFactor = defaultValue( - pbrSpecularGlossiness.specularFactor, - [1.0, 1.0, 1.0] - ); - pbrSpecularGlossiness.glossinessFactor = defaultValue( - pbrSpecularGlossiness.glossinessFactor, - 1.0 - ); + pbrSpecularGlossiness.diffuseFactor = pbrSpecularGlossiness.diffuseFactor ?? [1.0, 1.0, 1.0, 1.0]; + pbrSpecularGlossiness.specularFactor = pbrSpecularGlossiness.specularFactor ?? [1.0, 1.0, 1.0]; + pbrSpecularGlossiness.glossinessFactor = pbrSpecularGlossiness.glossinessFactor ?? 1.0; addTextureDefaults(pbrSpecularGlossiness.specularGlossinessTexture); } }); ForEach.animation(gltf, function (animation) { ForEach.animationSampler(animation, function (sampler) { - sampler.interpolation = defaultValue(sampler.interpolation, "LINEAR"); + sampler.interpolation = sampler.interpolation ?? "LINEAR"; }); }); @@ -185,23 +155,20 @@ function addDefaults(gltf) { defined(node.rotation) || defined(node.scale) ) { - node.translation = defaultValue(node.translation, [0.0, 0.0, 0.0]); - node.rotation = defaultValue(node.rotation, [0.0, 0.0, 0.0, 1.0]); - node.scale = defaultValue(node.scale, [1.0, 1.0, 1.0]); + node.translation = node.translation ?? [0.0, 0.0, 0.0]; + node.rotation = node.rotation ?? [0.0, 0.0, 0.0, 1.0]; + node.scale = node.scale ?? [1.0, 1.0, 1.0]; } else { - node.matrix = defaultValue( - node.matrix, - [ + node.matrix = node.matrix ?? [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, - ] - ); + ]; } }); ForEach.sampler(gltf, function (sampler) { - sampler.wrapS = defaultValue(sampler.wrapS, WebGLConstants.REPEAT); - sampler.wrapT = defaultValue(sampler.wrapT, WebGLConstants.REPEAT); + sampler.wrapS = sampler.wrapS ?? WebGLConstants.REPEAT; + sampler.wrapT = sampler.wrapT ?? WebGLConstants.REPEAT; }); if (defined(gltf.scenes) && !defined(gltf.scene)) { @@ -229,7 +196,7 @@ function getAnimatedNodes(gltf) { function addTextureDefaults(texture) { if (defined(texture)) { - texture.texCoord = defaultValue(texture.texCoord, 0); + texture.texCoord = texture.texCoord ?? 0; } } diff --git a/packages/engine/Source/Scene/GltfPipeline/addToArray.js b/packages/engine/Source/Scene/GltfPipeline/addToArray.js index a9d025a21d86..21d934f0c6f1 100644 --- a/packages/engine/Source/Scene/GltfPipeline/addToArray.js +++ b/packages/engine/Source/Scene/GltfPipeline/addToArray.js @@ -10,7 +10,7 @@ import defaultValue from "../../Core/defaultValue.js"; * @private */ function addToArray(array, element, checkDuplicates) { - checkDuplicates = defaultValue(checkDuplicates, false); + checkDuplicates = checkDuplicates ?? false; if (checkDuplicates) { const index = array.indexOf(element); if (index > -1) { diff --git a/packages/engine/Source/Scene/GltfPipeline/moveTechniqueRenderStates.js b/packages/engine/Source/Scene/GltfPipeline/moveTechniqueRenderStates.js index 9d2aa3b59bbb..26fe71748c66 100644 --- a/packages/engine/Source/Scene/GltfPipeline/moveTechniqueRenderStates.js +++ b/packages/engine/Source/Scene/GltfPipeline/moveTechniqueRenderStates.js @@ -84,8 +84,8 @@ function moveTechniqueRenderStates(gltf) { defined(blendFunctions.blendFuncSeparate)) ) { blendingForTechnique[techniqueIndex] = { - blendEquation: defaultValue( - blendFunctions.blendEquationSeparate, + blendEquation: ( + blendFunctions.blendEquationSeparate ?? defaultBlendEquation ), blendFactors: getSupportedBlendFactors( diff --git a/packages/engine/Source/Scene/GltfPipeline/parseGlb.js b/packages/engine/Source/Scene/GltfPipeline/parseGlb.js index 3ada028bc7d4..ec7f73bcb416 100644 --- a/packages/engine/Source/Scene/GltfPipeline/parseGlb.js +++ b/packages/engine/Source/Scene/GltfPipeline/parseGlb.js @@ -72,10 +72,7 @@ function parseGlbVersion1(glb, header) { const buffers = gltf.buffers; if (defined(buffers) && Object.keys(buffers).length > 0) { // In some older models, the binary glTF buffer is named KHR_binary_glTF - const binaryGltfBuffer = defaultValue( - buffers.binary_glTF, - buffers.KHR_binary_glTF - ); + const binaryGltfBuffer = buffers.binary_glTF ?? buffers.KHR_binary_glTF; if (defined(binaryGltfBuffer)) { binaryGltfBuffer.extras._pipeline.source = binaryBuffer; delete binaryGltfBuffer.uri; diff --git a/packages/engine/Source/Scene/GltfPipeline/removeUnusedElements.js b/packages/engine/Source/Scene/GltfPipeline/removeUnusedElements.js index b0740661c0e5..d2a9a2e77b76 100644 --- a/packages/engine/Source/Scene/GltfPipeline/removeUnusedElements.js +++ b/packages/engine/Source/Scene/GltfPipeline/removeUnusedElements.js @@ -25,7 +25,7 @@ const allElementTypes = [ * @private */ function removeUnusedElements(gltf, elementTypes) { - elementTypes = defaultValue(elementTypes, allElementTypes); + elementTypes = elementTypes ?? allElementTypes; allElementTypes.forEach(function (type) { if (elementTypes.indexOf(type) > -1) { removeUnusedElementsByType(gltf, type); diff --git a/packages/engine/Source/Scene/GltfPipeline/updateVersion.js b/packages/engine/Source/Scene/GltfPipeline/updateVersion.js index 9a3e9ed86db5..f0f904bdda5d 100644 --- a/packages/engine/Source/Scene/GltfPipeline/updateVersion.js +++ b/packages/engine/Source/Scene/GltfPipeline/updateVersion.js @@ -40,16 +40,16 @@ const updateFunctions = { * @private */ function updateVersion(gltf, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const targetVersion = options.targetVersion; let version = gltf.version; - gltf.asset = defaultValue(gltf.asset, { + gltf.asset = gltf.asset ?? { version: "1.0", - }); + }; - gltf.asset.version = defaultValue(gltf.asset.version, "1.0"); - version = defaultValue(version, gltf.asset.version).toString(); + gltf.asset.version = gltf.asset.version ?? "1.0"; + version = (version ?? gltf.asset.version).toString(); // Invalid version if (!Object.prototype.hasOwnProperty.call(updateFunctions, version)) { @@ -107,11 +107,8 @@ function setPrimitiveModes(gltf) { const primitivesLength = primitives.length; for (let i = 0; i < primitivesLength; ++i) { const primitive = primitives[i]; - const defaultMode = defaultValue( - primitive.primitive, - WebGLConstants.TRIANGLES - ); - primitive.mode = defaultValue(primitive.mode, defaultMode); + const defaultMode = primitive.primitive ?? WebGLConstants.TRIANGLES; + primitive.mode = primitive.mode ?? defaultMode; delete primitive.primitive; } } @@ -205,23 +202,14 @@ function removeTechniquePasses(gltf) { const technique = techniques[techniqueId]; const passes = technique.passes; if (defined(passes)) { - const passName = defaultValue(technique.pass, "defaultPass"); + const passName = technique.pass ?? "defaultPass"; if (Object.prototype.hasOwnProperty.call(passes, passName)) { const pass = passes[passName]; const instanceProgram = pass.instanceProgram; - technique.attributes = defaultValue( - technique.attributes, - instanceProgram.attributes - ); - technique.program = defaultValue( - technique.program, - instanceProgram.program - ); - technique.uniforms = defaultValue( - technique.uniforms, - instanceProgram.uniforms - ); - technique.states = defaultValue(technique.states, pass.states); + technique.attributes = technique.attributes ?? instanceProgram.attributes; + technique.program = technique.program ?? instanceProgram.program; + technique.uniforms = technique.uniforms ?? instanceProgram.uniforms; + technique.states = technique.states ?? pass.states; } delete technique.passes; delete technique.pass; @@ -269,9 +257,9 @@ function glTF08to10(gltf) { } // gltf.lights -> khrMaterialsCommon.lights if (defined(gltf.lights)) { - const extensions = defaultValue(gltf.extensions, {}); + const extensions = gltf.extensions ?? {}; gltf.extensions = extensions; - const materialsCommon = defaultValue(extensions.KHR_materials_common, {}); + const materialsCommon = extensions.KHR_materials_common ?? {}; extensions.KHR_materials_common = materialsCommon; materialsCommon.lights = gltf.lights; delete gltf.lights; @@ -611,7 +599,7 @@ const knownExtensions = { }; function requireKnownExtensions(gltf) { const extensionsUsed = gltf.extensionsUsed; - gltf.extensionsRequired = defaultValue(gltf.extensionsRequired, []); + gltf.extensionsRequired = gltf.extensionsRequired ?? []; if (defined(extensionsUsed)) { const extensionsUsedLength = extensionsUsed.length; for (let i = 0; i < extensionsUsedLength; ++i) { @@ -768,7 +756,7 @@ function requireByteLength(gltf) { const accessorByteEnd = accessor.byteOffset + accessor.count * accessorByteStride; bufferView.byteLength = Math.max( - defaultValue(bufferView.byteLength, 0), + (bufferView.byteLength ?? 0), accessorByteEnd ); } @@ -793,8 +781,8 @@ function moveByteStrideToBufferView(gltf) { const bufferViewMap = {}; ForEach.accessor(gltf, function (accessor) { if (defined(accessor.bufferView)) { - bufferViewMap[accessor.bufferView] = defaultValue( - bufferViewMap[accessor.bufferView], + bufferViewMap[accessor.bufferView] = ( + bufferViewMap[accessor.bufferView] ?? [] ); bufferViewMap[accessor.bufferView].push(accessor); @@ -955,7 +943,7 @@ function validatePresentAccessorMinMax(gltf) { } function glTF10to20(gltf) { - gltf.asset = defaultValue(gltf.asset, {}); + gltf.asset = gltf.asset ?? {}; gltf.asset.version = "2.0"; // material.instanceTechnique properties should be directly on the material. instanceTechnique is a gltf 0.8 property but is seen in some 1.0 models. updateInstanceTechniques(gltf); @@ -1052,15 +1040,9 @@ function srgbToLinear(srgb) { } function convertTechniquesToPbr(gltf, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const baseColorTextureNames = defaultValue( - options.baseColorTextureNames, - defaultBaseColorTextureNames - ); - const baseColorFactorNames = defaultValue( - options.baseColorFactorNames, - defaultBaseColorFactorNames - ); + options = options ?? defaultValue.EMPTY_OBJECT; + const baseColorTextureNames = options.baseColorTextureNames ?? defaultBaseColorTextureNames; + const baseColorFactorNames = options.baseColorFactorNames ?? defaultBaseColorFactorNames; // Future work: convert other values like emissive, specular, etc. Only handling diffuse right now. ForEach.material(gltf, function (material) { @@ -1102,8 +1084,8 @@ function assignAsEmissive(material, emissive) { function convertMaterialsCommonToPbr(gltf) { // Future work: convert KHR_materials_common lights to KHR_lights_punctual ForEach.material(gltf, function (material) { - const materialsCommon = defaultValue( - material.extensions, + const materialsCommon = ( + material.extensions ?? defaultValue.EMPTY_OBJECT ).KHR_materials_common; if (!defined(materialsCommon)) { @@ -1111,7 +1093,7 @@ function convertMaterialsCommonToPbr(gltf) { return; } - const values = defaultValue(materialsCommon.values, {}); + const values = materialsCommon.values ?? {}; const ambient = values.ambient; const diffuse = values.diffuse; const emission = values.emission; diff --git a/packages/engine/Source/Scene/GltfStructuralMetadataLoader.js b/packages/engine/Source/Scene/GltfStructuralMetadataLoader.js index 964b000760be..4f54d6ce1750 100644 --- a/packages/engine/Source/Scene/GltfStructuralMetadataLoader.js +++ b/packages/engine/Source/Scene/GltfStructuralMetadataLoader.js @@ -33,7 +33,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function GltfStructuralMetadataLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, extension, @@ -366,10 +366,9 @@ function loadTextures(structuralMetadataLoader) { } async function loadSchema(structuralMetadataLoader) { - const extension = defaultValue( - structuralMetadataLoader._extension, - structuralMetadataLoader._extensionLegacy, - ); + const extension = + structuralMetadataLoader._extension ?? + structuralMetadataLoader._extensionLegacy; let schemaLoader; if (defined(extension.schemaUri)) { diff --git a/packages/engine/Source/Scene/GltfTextureLoader.js b/packages/engine/Source/Scene/GltfTextureLoader.js index 4c07eef67629..896c2d9b9c0b 100644 --- a/packages/engine/Source/Scene/GltfTextureLoader.js +++ b/packages/engine/Source/Scene/GltfTextureLoader.js @@ -35,7 +35,7 @@ import resizeImageToNextPowerOfTwo from "../Core/resizeImageToNextPowerOfTwo.js" * @private */ function GltfTextureLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resourceCache = options.resourceCache; const gltf = options.gltf; const textureInfo = options.textureInfo; @@ -43,7 +43,7 @@ function GltfTextureLoader(options) { const baseResource = options.baseResource; const supportedImageFormats = options.supportedImageFormats; const cacheKey = options.cacheKey; - const asynchronous = defaultValue(options.asynchronous, true); + const asynchronous = options.asynchronous ?? true; //>>includeStart('debug', pragmas.debug); Check.typeOf.func("options.resourceCache", resourceCache); diff --git a/packages/engine/Source/Scene/GltfVertexBufferLoader.js b/packages/engine/Source/Scene/GltfVertexBufferLoader.js index 52f77e4505e1..493fc67cdc66 100644 --- a/packages/engine/Source/Scene/GltfVertexBufferLoader.js +++ b/packages/engine/Source/Scene/GltfVertexBufferLoader.js @@ -41,7 +41,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @private */ function GltfVertexBufferLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resourceCache = options.resourceCache; const gltf = options.gltf; const gltfResource = options.gltfResource; @@ -51,9 +51,9 @@ function GltfVertexBufferLoader(options) { const attributeSemantic = options.attributeSemantic; const accessorId = options.accessorId; const cacheKey = options.cacheKey; - const asynchronous = defaultValue(options.asynchronous, true); - const loadBuffer = defaultValue(options.loadBuffer, false); - const loadTypedArray = defaultValue(options.loadTypedArray, false); + const asynchronous = options.asynchronous ?? true; + const loadBuffer = options.loadBuffer ?? false; + const loadTypedArray = options.loadTypedArray ?? false; //>>includeStart('debug', pragmas.debug); Check.typeOf.func("options.resourceCache", resourceCache); diff --git a/packages/engine/Source/Scene/GoogleEarthEnterpriseImageryProvider.js b/packages/engine/Source/Scene/GoogleEarthEnterpriseImageryProvider.js index 60ee4a4d69f5..0b5f838e27dc 100644 --- a/packages/engine/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +++ b/packages/engine/Source/Scene/GoogleEarthEnterpriseImageryProvider.js @@ -86,7 +86,7 @@ GoogleEarthEnterpriseDiscardPolicy.prototype.shouldDiscardImage = function ( * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} */ function GoogleEarthEnterpriseImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; this._defaultDayAlpha = undefined; diff --git a/packages/engine/Source/Scene/GoogleEarthEnterpriseMapsProvider.js b/packages/engine/Source/Scene/GoogleEarthEnterpriseMapsProvider.js index c5d078f72421..e034a162b259 100644 --- a/packages/engine/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +++ b/packages/engine/Source/Scene/GoogleEarthEnterpriseMapsProvider.js @@ -1,7 +1,6 @@ import buildModuleUrl from "../Core/buildModuleUrl.js"; import Check from "../Core/Check.js"; import Credit from "../Core/Credit.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Event from "../Core/Event.js"; import GeographicTilingScheme from "../Core/GeographicTilingScheme.js"; @@ -201,7 +200,7 @@ async function requestMetadata( * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} */ function GoogleEarthEnterpriseMapsProvider(options) { - options = defaultValue(options, {}); + options = options ?? {}; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; @@ -458,9 +457,9 @@ GoogleEarthEnterpriseMapsProvider.fromUrl = async function ( Check.defined("channel", channel); //>>includeEnd('debug'); - options = defaultValue(options, {}); + options = options ?? {}; - const path = defaultValue(options.path, "/default_map"); + const path = options.path ?? "/default_map"; const resource = Resource.createIfNeeded(url).getDerivedResource({ // We used to just append path to url, so now that we do proper URI resolution, removed the / diff --git a/packages/engine/Source/Scene/GridImageryProvider.js b/packages/engine/Source/Scene/GridImageryProvider.js index e3f6fd4497b0..68aafa9943bf 100644 --- a/packages/engine/Source/Scene/GridImageryProvider.js +++ b/packages/engine/Source/Scene/GridImageryProvider.js @@ -37,7 +37,7 @@ const defaultBackgroundColor = new Color(0.0, 0.5, 0.0, 0.2); * */ function GridImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; @@ -53,22 +53,19 @@ function GridImageryProvider(options) { this._tilingScheme = defined(options.tilingScheme) ? options.tilingScheme : new GeographicTilingScheme({ ellipsoid: options.ellipsoid }); - this._cells = defaultValue(options.cells, 8); - this._color = defaultValue(options.color, defaultColor); - this._glowColor = defaultValue(options.glowColor, defaultGlowColor); - this._glowWidth = defaultValue(options.glowWidth, 6); - this._backgroundColor = defaultValue( - options.backgroundColor, - defaultBackgroundColor, - ); + this._cells = options.cells ?? 8; + this._color = options.color ?? defaultColor; + this._glowColor = options.glowColor ?? defaultGlowColor; + this._glowWidth = options.glowWidth ?? 6; + this._backgroundColor = options.backgroundColor ?? defaultBackgroundColor; this._errorEvent = new Event(); - this._tileWidth = defaultValue(options.tileWidth, 256); - this._tileHeight = defaultValue(options.tileHeight, 256); + this._tileWidth = options.tileWidth ?? 256; + this._tileHeight = options.tileHeight ?? 256; // A little larger than tile size so lines are sharper // Note: can't be too much difference otherwise texture blowout - this._canvasSize = defaultValue(options.canvasSize, 256); + this._canvasSize = options.canvasSize ?? 256; // We only need a single canvas since all tiles will be the same this._canvas = this._createGridCanvas(); diff --git a/packages/engine/Source/Scene/GroundPolylinePrimitive.js b/packages/engine/Source/Scene/GroundPolylinePrimitive.js index c82b9e1dd263..adb8644db42d 100644 --- a/packages/engine/Source/Scene/GroundPolylinePrimitive.js +++ b/packages/engine/Source/Scene/GroundPolylinePrimitive.js @@ -94,7 +94,7 @@ import StencilOperation from "./StencilOperation.js"; * })); */ function GroundPolylinePrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The geometry instances rendered with this primitive. This may @@ -136,7 +136,7 @@ function GroundPolylinePrimitive(options) { * * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * Determines whether terrain, 3D Tiles or both will be classified. @@ -145,10 +145,8 @@ function GroundPolylinePrimitive(options) { * * @default ClassificationType.BOTH */ - this.classificationType = defaultValue( - options.classificationType, - ClassificationType.BOTH, - ); + this.classificationType = + options.classificationType ?? ClassificationType.BOTH; /** * This property is for debugging only; it is not for production use nor is it optimized. @@ -160,28 +158,19 @@ function GroundPolylinePrimitive(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; // Shadow volume is shown by removing a discard in the shader, so this isn't toggleable. - this._debugShowShadowVolume = defaultValue( - options.debugShowShadowVolume, - false, - ); + this._debugShowShadowVolume = options.debugShowShadowVolume ?? false; this._primitiveOptions = { geometryInstances: undefined, appearance: undefined, vertexCacheOptimize: false, - interleave: defaultValue(options.interleave, false), - releaseGeometryInstances: defaultValue( - options.releaseGeometryInstances, - true, - ), - allowPicking: defaultValue(options.allowPicking, true), - asynchronous: defaultValue(options.asynchronous, true), + interleave: options.interleave ?? false, + releaseGeometryInstances: options.releaseGeometryInstances ?? true, + allowPicking: options.allowPicking ?? true, + asynchronous: options.asynchronous ?? true, compressVertices: false, _createShaderProgramFunction: undefined, _createCommandsFunction: undefined, diff --git a/packages/engine/Source/Scene/GroundPrimitive.js b/packages/engine/Source/Scene/GroundPrimitive.js index 5a3d5ab85393..bca03a63c546 100644 --- a/packages/engine/Source/Scene/GroundPrimitive.js +++ b/packages/engine/Source/Scene/GroundPrimitive.js @@ -112,7 +112,7 @@ const GroundPrimitiveUniformMap = { * @see Appearance */ function GroundPrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let appearance = options.appearance; const geometryInstances = options.geometryInstances; @@ -165,7 +165,7 @@ function GroundPrimitive(options) { * * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * Determines whether terrain, 3D Tiles or both will be classified. * @@ -173,10 +173,8 @@ function GroundPrimitive(options) { * * @default ClassificationType.BOTH */ - this.classificationType = defaultValue( - options.classificationType, - ClassificationType.BOTH, - ); + this.classificationType = + options.classificationType ?? ClassificationType.BOTH; /** * This property is for debugging only; it is not for production use nor is it optimized. *

@@ -187,10 +185,7 @@ function GroundPrimitive(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * This property is for debugging only; it is not for production use nor is it optimized. @@ -202,10 +197,7 @@ function GroundPrimitive(options) { * * @default false */ - this.debugShowShadowVolume = defaultValue( - options.debugShowShadowVolume, - false, - ); + this.debugShowShadowVolume = options.debugShowShadowVolume ?? false; this._boundingVolumes = []; this._boundingVolumes2D = []; @@ -230,15 +222,12 @@ function GroundPrimitive(options) { this._classificationPrimitiveOptions = { geometryInstances: undefined, appearance: undefined, - vertexCacheOptimize: defaultValue(options.vertexCacheOptimize, false), - interleave: defaultValue(options.interleave, false), - releaseGeometryInstances: defaultValue( - options.releaseGeometryInstances, - true, - ), - allowPicking: defaultValue(options.allowPicking, true), - asynchronous: defaultValue(options.asynchronous, true), - compressVertices: defaultValue(options.compressVertices, true), + vertexCacheOptimize: options.vertexCacheOptimize ?? false, + interleave: options.interleave ?? false, + releaseGeometryInstances: options.releaseGeometryInstances ?? true, + allowPicking: options.allowPicking ?? true, + asynchronous: options.asynchronous ?? true, + compressVertices: options.compressVertices ?? true, _createBoundingVolumeFunction: undefined, _updateAndQueueCommandsFunction: undefined, _pickPrimitive: that, diff --git a/packages/engine/Source/Scene/GroupMetadata.js b/packages/engine/Source/Scene/GroupMetadata.js index 5308fdbc2435..669621d0ceb2 100644 --- a/packages/engine/Source/Scene/GroupMetadata.js +++ b/packages/engine/Source/Scene/GroupMetadata.js @@ -20,7 +20,7 @@ import MetadataEntity from "./MetadataEntity.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function GroupMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const id = options.id; const group = options.group; const metadataClass = options.class; diff --git a/packages/engine/Source/Scene/I3SDataProvider.js b/packages/engine/Source/Scene/I3SDataProvider.js index 89e87643ef26..5237e3aec204 100644 --- a/packages/engine/Source/Scene/I3SDataProvider.js +++ b/packages/engine/Source/Scene/I3SDataProvider.js @@ -139,25 +139,20 @@ import Rectangle from "../Core/Rectangle.js"; * } */ function I3SDataProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; // All public configuration is defined as ES5 properties // These are just the "private" variables and their defaults. this._name = options.name; - this._show = defaultValue(options.show, true); + this._show = options.show ?? true; this._geoidTiledTerrainProvider = options.geoidTiledTerrainProvider; - this._showFeatures = defaultValue(options.showFeatures, false); - this._adjustMaterialAlphaMode = defaultValue( - options.adjustMaterialAlphaMode, - false, - ); - this._applySymbology = defaultValue(options.applySymbology, false); - this._calculateNormals = defaultValue(options.calculateNormals, false); + this._showFeatures = options.showFeatures ?? false; + this._adjustMaterialAlphaMode = options.adjustMaterialAlphaMode ?? false; + this._applySymbology = options.applySymbology ?? false; + this._calculateNormals = options.calculateNormals ?? false; - this._cesium3dTilesetOptions = defaultValue( - options.cesium3dTilesetOptions, - defaultValue.EMPTY_OBJECT, - ); + this._cesium3dTilesetOptions = + options.cesium3dTilesetOptions ?? defaultValue.EMPTY_OBJECT; this._layers = []; this._sublayers = []; @@ -542,7 +537,7 @@ I3SDataProvider.fromUrl = async function (url, options) { Check.defined("url", url); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resource = Resource.createIfNeeded(url); // Set a query parameter for json to avoid failure on html pages diff --git a/packages/engine/Source/Scene/I3SNode.js b/packages/engine/Source/Scene/I3SNode.js index d3311e42b031..c28e9c4c3f48 100644 --- a/packages/engine/Source/Scene/I3SNode.js +++ b/packages/engine/Source/Scene/I3SNode.js @@ -1,6 +1,5 @@ import Cartographic from "../Core/Cartographic.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Ellipsoid from "../Core/Ellipsoid.js"; import HeadingPitchRoll from "../Core/HeadingPitchRoll.js"; @@ -348,11 +347,7 @@ I3SNode.prototype._loadChildren = function () { childIndex++ ) { const child = that._data.children[childIndex]; - const newChild = new I3SNode( - that, - defaultValue(child.href, child), - false, - ); + const newChild = new I3SNode(that, child.href ?? child, false); that._children.push(newChild); childPromises.push(newChild.load()); } diff --git a/packages/engine/Source/Scene/I3SSublayer.js b/packages/engine/Source/Scene/I3SSublayer.js index 129d7ee3032d..f8986fd3b98a 100644 --- a/packages/engine/Source/Scene/I3SSublayer.js +++ b/packages/engine/Source/Scene/I3SSublayer.js @@ -1,5 +1,4 @@ import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import I3SDataProvider from "./I3SDataProvider.js"; import I3SLayer from "./I3SLayer.js"; @@ -19,7 +18,7 @@ function I3SSublayer(dataProvider, parent, sublayerData) { this._data = sublayerData; this._name = sublayerData.name; this._modelName = sublayerData.modelName; - this._visibility = defaultValue(sublayerData.visibility, true); + this._visibility = sublayerData.visibility ?? true; this._resource = undefined; this._sublayers = []; this._i3sLayers = []; diff --git a/packages/engine/Source/Scene/I3SSymbology.js b/packages/engine/Source/Scene/I3SSymbology.js index 5b4a802dbc66..21a218843955 100644 --- a/packages/engine/Source/Scene/I3SSymbology.js +++ b/packages/engine/Source/Scene/I3SSymbology.js @@ -1,5 +1,4 @@ import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import srgbToLinear from "../Core/srgbToLinear.js"; @@ -166,8 +165,8 @@ function buildClassBreaksHash(renderer, isColorCaptured) { if (defined(renderer.classBreakInfos)) { const classBreakInfos = [...renderer.classBreakInfos]; classBreakInfos.sort(function (a, b) { - const aMax = defaultValue(a.classMaxValue, a.classMinValue); - const bMax = defaultValue(b.classMaxValue, b.classMinValue); + const aMax = a.classMaxValue ?? a.classMinValue; + const bMax = b.classMaxValue ?? b.classMinValue; return aMax - bMax; }); const valueHash = { diff --git a/packages/engine/Source/Scene/I3dmParser.js b/packages/engine/Source/Scene/I3dmParser.js index 22bb7a1cb856..cda8bfb68345 100644 --- a/packages/engine/Source/Scene/I3dmParser.js +++ b/packages/engine/Source/Scene/I3dmParser.js @@ -1,5 +1,4 @@ import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import deprecationWarning from "../Core/deprecationWarning.js"; import getJsonFromTypedArray from "../Core/getJsonFromTypedArray.js"; import RuntimeError from "../Core/RuntimeError.js"; @@ -29,7 +28,7 @@ I3dmParser.parse = function (arrayBuffer, byteOffset) { Check.defined("arrayBuffer", arrayBuffer); //>>includeEnd('debug'); - const byteStart = defaultValue(byteOffset, 0); + const byteStart = byteOffset ?? 0; byteOffset = byteStart; const uint8Array = new Uint8Array(arrayBuffer); diff --git a/packages/engine/Source/Scene/ImageBasedLighting.js b/packages/engine/Source/Scene/ImageBasedLighting.js index 2dffbd654fc7..a35574f5dfc2 100644 --- a/packages/engine/Source/Scene/ImageBasedLighting.js +++ b/packages/engine/Source/Scene/ImageBasedLighting.js @@ -24,7 +24,7 @@ import SpecularEnvironmentCubeMap from "./SpecularEnvironmentCubeMap.js"; * @param {string} [options.specularEnvironmentMaps] A URL to a KTX2 file that contains a cube map of the specular lighting and the convoluted specular mipmaps. */ function ImageBasedLighting(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const imageBasedLightingFactor = defined(options.imageBasedLightingFactor) ? Cartesian2.clone(options.imageBasedLightingFactor) : new Cartesian2(1.0, 1.0); @@ -58,6 +58,15 @@ function ImageBasedLighting(options) { this._imageBasedLightingFactor = imageBasedLightingFactor; + + const luminanceAtZenith = options.luminanceAtZenith ?? 0.2; + + //>>includeStart('debug', pragmas.debug); + Check.typeOf.number("options.luminanceAtZenith", luminanceAtZenith); + //>>includeEnd('debug'); + + this._luminanceAtZenith = luminanceAtZenith; + const sphericalHarmonicCoefficients = options.sphericalHarmonicCoefficients; //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Scene/ImageryLayer.js b/packages/engine/Source/Scene/ImageryLayer.js index 897686064402..abaec44f5914 100644 --- a/packages/engine/Source/Scene/ImageryLayer.js +++ b/packages/engine/Source/Scene/ImageryLayer.js @@ -162,8 +162,8 @@ function ImageryLayer(imageryProvider, options) { this._readyEvent = new Event(); this._errorEvent = new Event(); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - imageryProvider = defaultValue(imageryProvider, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; + imageryProvider = imageryProvider ?? defaultValue.EMPTY_OBJECT; /** * The alpha blending value of this layer, with 0.0 representing fully transparent and @@ -172,10 +172,7 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default 1.0 */ - this.alpha = defaultValue( - options.alpha, - defaultValue(imageryProvider._defaultAlpha, 1.0), - ); + this.alpha = options.alpha ?? imageryProvider._defaultAlpha ?? 1.0; /** * The alpha blending value of this layer on the night side of the globe, with 0.0 representing fully transparent and @@ -184,10 +181,8 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default 1.0 */ - this.nightAlpha = defaultValue( - options.nightAlpha, - defaultValue(imageryProvider._defaultNightAlpha, 1.0), - ); + this.nightAlpha = + options.nightAlpha ?? imageryProvider._defaultNightAlpha ?? 1.0; /** * The alpha blending value of this layer on the day side of the globe, with 0.0 representing fully transparent and @@ -196,10 +191,7 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default 1.0 */ - this.dayAlpha = defaultValue( - options.dayAlpha, - defaultValue(imageryProvider._defaultDayAlpha, 1.0), - ); + this.dayAlpha = options.dayAlpha ?? imageryProvider._defaultDayAlpha ?? 1.0; /** * The brightness of this layer. 1.0 uses the unmodified imagery color. Less than 1.0 @@ -208,13 +200,10 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default {@link ImageryLayer.DEFAULT_BRIGHTNESS} */ - this.brightness = defaultValue( - options.brightness, - defaultValue( - imageryProvider._defaultBrightness, - ImageryLayer.DEFAULT_BRIGHTNESS, - ), - ); + this.brightness = + options.brightness ?? + imageryProvider._defaultBrightness ?? + ImageryLayer.DEFAULT_BRIGHTNESS; /** * The contrast of this layer. 1.0 uses the unmodified imagery color. Less than 1.0 reduces @@ -223,13 +212,10 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default {@link ImageryLayer.DEFAULT_CONTRAST} */ - this.contrast = defaultValue( - options.contrast, - defaultValue( - imageryProvider._defaultContrast, - ImageryLayer.DEFAULT_CONTRAST, - ), - ); + this.contrast = + options.contrast ?? + imageryProvider._defaultContrast ?? + ImageryLayer.DEFAULT_CONTRAST; /** * The hue of this layer in radians. 0.0 uses the unmodified imagery color. @@ -237,10 +223,8 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default {@link ImageryLayer.DEFAULT_HUE} */ - this.hue = defaultValue( - options.hue, - defaultValue(imageryProvider._defaultHue, ImageryLayer.DEFAULT_HUE), - ); + this.hue = + options.hue ?? imageryProvider._defaultHue ?? ImageryLayer.DEFAULT_HUE; /** * The saturation of this layer. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the @@ -249,13 +233,10 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default {@link ImageryLayer.DEFAULT_SATURATION} */ - this.saturation = defaultValue( - options.saturation, - defaultValue( - imageryProvider._defaultSaturation, - ImageryLayer.DEFAULT_SATURATION, - ), - ); + this.saturation = + options.saturation ?? + imageryProvider._defaultSaturation ?? + ImageryLayer.DEFAULT_SATURATION; /** * The gamma correction to apply to this layer. 1.0 uses the unmodified imagery color. @@ -263,10 +244,10 @@ function ImageryLayer(imageryProvider, options) { * @type {number} * @default {@link ImageryLayer.DEFAULT_GAMMA} */ - this.gamma = defaultValue( - options.gamma, - defaultValue(imageryProvider._defaultGamma, ImageryLayer.DEFAULT_GAMMA), - ); + this.gamma = + options.gamma ?? + imageryProvider._defaultGamma ?? + ImageryLayer.DEFAULT_GAMMA; /** * The {@link SplitDirection} to apply to this layer. @@ -274,10 +255,7 @@ function ImageryLayer(imageryProvider, options) { * @type {SplitDirection} * @default {@link ImageryLayer.DEFAULT_SPLIT} */ - this.splitDirection = defaultValue( - options.splitDirection, - ImageryLayer.DEFAULT_SPLIT, - ); + this.splitDirection = options.splitDirection ?? ImageryLayer.DEFAULT_SPLIT; /** * The {@link TextureMinificationFilter} to apply to this layer. @@ -290,13 +268,10 @@ function ImageryLayer(imageryProvider, options) { * @type {TextureMinificationFilter} * @default {@link ImageryLayer.DEFAULT_MINIFICATION_FILTER} */ - this.minificationFilter = defaultValue( - options.minificationFilter, - defaultValue( - imageryProvider._defaultMinificationFilter, - ImageryLayer.DEFAULT_MINIFICATION_FILTER, - ), - ); + this.minificationFilter = + options.minificationFilter ?? + imageryProvider._defaultMinificationFilter ?? + ImageryLayer.DEFAULT_MINIFICATION_FILTER; /** * The {@link TextureMagnificationFilter} to apply to this layer. @@ -309,13 +284,10 @@ function ImageryLayer(imageryProvider, options) { * @type {TextureMagnificationFilter} * @default {@link ImageryLayer.DEFAULT_MAGNIFICATION_FILTER} */ - this.magnificationFilter = defaultValue( - options.magnificationFilter, - defaultValue( - imageryProvider._defaultMagnificationFilter, - ImageryLayer.DEFAULT_MAGNIFICATION_FILTER, - ), - ); + this.magnificationFilter = + options.magnificationFilter ?? + imageryProvider._defaultMagnificationFilter ?? + ImageryLayer.DEFAULT_MAGNIFICATION_FILTER; /** * Determines if this layer is shown. @@ -323,12 +295,12 @@ function ImageryLayer(imageryProvider, options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; this._minimumTerrainLevel = options.minimumTerrainLevel; this._maximumTerrainLevel = options.maximumTerrainLevel; - this._rectangle = defaultValue(options.rectangle, Rectangle.MAX_VALUE); + this._rectangle = options.rectangle ?? Rectangle.MAX_VALUE; this._maximumAnisotropy = options.maximumAnisotropy; this._imageryCache = {}; @@ -367,10 +339,9 @@ function ImageryLayer(imageryProvider, options) { * * @type {number} */ - this.colorToAlphaThreshold = defaultValue( - options.colorToAlphaThreshold, - ImageryLayer.DEFAULT_APPLY_COLOR_TO_ALPHA_THRESHOLD, - ); + this.colorToAlphaThreshold = + options.colorToAlphaThreshold ?? + ImageryLayer.DEFAULT_APPLY_COLOR_TO_ALPHA_THRESHOLD; } Object.defineProperties(ImageryLayer.prototype, { @@ -604,7 +575,7 @@ ImageryLayer.fromProviderAsync = function (imageryProviderPromise, options) { * @see ImageryLayer.provider */ ImageryLayer.fromWorldImagery = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; return ImageryLayer.fromProviderAsync( createWorldImageryAsync({ @@ -1316,7 +1287,7 @@ ImageryLayer.prototype._finalizeReprojectTexture = function (context, texture) { ContextLimits.maximumTextureFilterAnisotropy; const maximumAnisotropy = Math.min( maximumSupportedAnisotropy, - defaultValue(this._maximumAnisotropy, maximumSupportedAnisotropy), + this._maximumAnisotropy ?? maximumSupportedAnisotropy, ); const mipmapSamplerKey = getSamplerKey( minificationFilter, @@ -1383,7 +1354,7 @@ ImageryLayer.prototype._reprojectTexture = function ( const rectangle = imagery.rectangle; const context = frameState.context; - needGeographicProjection = defaultValue(needGeographicProjection, true); + needGeographicProjection = needGeographicProjection ?? true; // Reproject this texture if it is not already in a geographic projection and // the pixels are more than 1e-5 radians apart. The pixel spacing cutoff diff --git a/packages/engine/Source/Scene/ImageryLayerCollection.js b/packages/engine/Source/Scene/ImageryLayerCollection.js index 3c2769810b2c..299d6ca0b56c 100644 --- a/packages/engine/Source/Scene/ImageryLayerCollection.js +++ b/packages/engine/Source/Scene/ImageryLayerCollection.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -158,7 +157,7 @@ ImageryLayerCollection.prototype.addImageryProvider = function ( * false if the layer was not in the collection. */ ImageryLayerCollection.prototype.remove = function (layer, destroy) { - destroy = defaultValue(destroy, true); + destroy = destroy ?? true; const index = this._layers.indexOf(layer); if (index !== -1) { @@ -184,7 +183,7 @@ ImageryLayerCollection.prototype.remove = function (layer, destroy) { * @param {boolean} [destroy=true] whether to destroy the layers in addition to removing them. */ ImageryLayerCollection.prototype.removeAll = function (destroy) { - destroy = defaultValue(destroy, true); + destroy = destroy ?? true; const layers = this._layers; for (let i = 0, len = layers.length; i < len; i++) { diff --git a/packages/engine/Source/Scene/Implicit3DTileContent.js b/packages/engine/Source/Scene/Implicit3DTileContent.js index 9cd00a69a94b..e5b4a871c566 100644 --- a/packages/engine/Source/Scene/Implicit3DTileContent.js +++ b/packages/engine/Source/Scene/Implicit3DTileContent.js @@ -2,7 +2,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; import clone from "../Core/clone.js"; import combine from "../Core/combine.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -216,7 +215,7 @@ Implicit3DTileContent.fromSubtreeJson = async function ( } //>>includeEnd('debug'); - byteOffset = defaultValue(byteOffset, 0); + byteOffset = byteOffset ?? 0; let uint8Array; if (defined(arrayBuffer)) { uint8Array = new Uint8Array(arrayBuffer, byteOffset); @@ -449,7 +448,7 @@ function deriveChildTile( ) { const implicitTileset = implicitContent._implicitTileset; let implicitCoordinates; - if (defaultValue(parentIsPlaceholderTile, false)) { + if (parentIsPlaceholderTile ?? false) { implicitCoordinates = parentTile.implicitCoordinates; } else { implicitCoordinates = @@ -718,7 +717,7 @@ function getTileBoundingVolume( implicitTileset, implicitCoordinates, childIndex, - defaultValue(parentIsPlaceholderTile, false), + parentIsPlaceholderTile ?? false, parentTile, ); } else { diff --git a/packages/engine/Source/Scene/ImplicitAvailabilityBitstream.js b/packages/engine/Source/Scene/ImplicitAvailabilityBitstream.js index c9af8ca5c6ae..aa497eac2b87 100644 --- a/packages/engine/Source/Scene/ImplicitAvailabilityBitstream.js +++ b/packages/engine/Source/Scene/ImplicitAvailabilityBitstream.js @@ -1,6 +1,5 @@ import Check from "../Core/Check.js"; import defined from "../Core/defined.js"; -import defaultValue from "../Core/defaultValue.js"; import DeveloperError from "../Core/DeveloperError.js"; import RuntimeError from "../Core/RuntimeError.js"; @@ -44,10 +43,8 @@ function ImplicitAvailabilityBitstream(options) { // Only compute the available count if requested, as this involves looping // over the bitstream. - const computeAvailableCountEnabled = defaultValue( - options.computeAvailableCountEnabled, - false, - ); + const computeAvailableCountEnabled = + options.computeAvailableCountEnabled ?? false; if (!defined(availableCount) && computeAvailableCountEnabled) { availableCount = count1Bits(bitstream, lengthBits); } diff --git a/packages/engine/Source/Scene/ImplicitMetadataView.js b/packages/engine/Source/Scene/ImplicitMetadataView.js index 98e8456fab24..cbf55e34ec50 100644 --- a/packages/engine/Source/Scene/ImplicitMetadataView.js +++ b/packages/engine/Source/Scene/ImplicitMetadataView.js @@ -19,7 +19,7 @@ import defaultValue from "../Core/defaultValue.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function ImplicitMetadataView(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const metadataTable = options.metadataTable; const metadataClass = options.class; const entityId = options.entityId; diff --git a/packages/engine/Source/Scene/ImplicitSubtree.js b/packages/engine/Source/Scene/ImplicitSubtree.js index d59d4516e34a..c7372b153f50 100644 --- a/packages/engine/Source/Scene/ImplicitSubtree.js +++ b/packages/engine/Source/Scene/ImplicitSubtree.js @@ -1,5 +1,4 @@ import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import DeveloperError from "../Core/DeveloperError.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; @@ -207,7 +206,7 @@ ImplicitSubtree.prototype.contentIsAvailableAtIndex = function ( index, contentIndex, ) { - contentIndex = defaultValue(contentIndex, 0); + contentIndex = contentIndex ?? 0; //>>includeStart('debug', pragmas.debug); if ( contentIndex < 0 || @@ -401,7 +400,7 @@ ImplicitSubtree.fromSubtreeJson = async function ( subtreeJson.contentAvailabilityHeaders = subtreeJson.contentAvailability; } else { subtreeJson.contentAvailabilityHeaders.push( - defaultValue(subtreeJson.contentAvailability, defaultContentAvailability), + subtreeJson.contentAvailability ?? defaultContentAvailability, ); } @@ -644,19 +643,15 @@ function markActiveMetadataBufferViews(propertyTableJson, bufferViewHeaders) { const metadataHeader = properties[key]; // An older spec used bufferView - const valuesBufferView = defaultValue( - metadataHeader.values, - metadataHeader.bufferView, - ); + const valuesBufferView = + metadataHeader.values ?? metadataHeader.bufferView; header = bufferViewHeaders[valuesBufferView]; header.isActive = true; header.bufferHeader.isActive = true; // An older spec used stringOffsetBufferView - const stringOffsetBufferView = defaultValue( - metadataHeader.stringOffsets, - metadataHeader.stringOffsetBufferView, - ); + const stringOffsetBufferView = + metadataHeader.stringOffsets ?? metadataHeader.stringOffsetBufferView; if (defined(stringOffsetBufferView)) { header = bufferViewHeaders[stringOffsetBufferView]; header.isActive = true; @@ -664,10 +659,8 @@ function markActiveMetadataBufferViews(propertyTableJson, bufferViewHeaders) { } // an older spec used arrayOffsetBufferView - const arrayOffsetBufferView = defaultValue( - metadataHeader.arrayOffsets, - metadataHeader.arrayOffsetBufferView, - ); + const arrayOffsetBufferView = + metadataHeader.arrayOffsets ?? metadataHeader.arrayOffsetBufferView; if (defined(arrayOffsetBufferView)) { header = bufferViewHeaders[arrayOffsetBufferView]; header.isActive = true; diff --git a/packages/engine/Source/Scene/ImplicitSubtreeCache.js b/packages/engine/Source/Scene/ImplicitSubtreeCache.js index 584cf6f362da..168c05eba42d 100644 --- a/packages/engine/Source/Scene/ImplicitSubtreeCache.js +++ b/packages/engine/Source/Scene/ImplicitSubtreeCache.js @@ -12,13 +12,13 @@ import DoubleEndedPriorityQueue from "../Core/DoubleEndedPriorityQueue.js"; * @private */ function ImplicitSubtreeCache(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * @type {number} * @private */ - this._maximumSubtreeCount = defaultValue(options.maximumSubtreeCount, 0); + this._maximumSubtreeCount = options.maximumSubtreeCount ?? 0; /** * A counter that goes up whenever a subtree is added. Used to sort subtrees by recency. diff --git a/packages/engine/Source/Scene/ImplicitSubtreeMetadata.js b/packages/engine/Source/Scene/ImplicitSubtreeMetadata.js index 887eea3d88a2..fa331051d494 100644 --- a/packages/engine/Source/Scene/ImplicitSubtreeMetadata.js +++ b/packages/engine/Source/Scene/ImplicitSubtreeMetadata.js @@ -19,7 +19,7 @@ import MetadataEntity from "./MetadataEntity.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function ImplicitSubtreeMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const subtreeMetadata = options.subtreeMetadata; const metadataClass = options.class; diff --git a/packages/engine/Source/Scene/IonImageryProvider.js b/packages/engine/Source/Scene/IonImageryProvider.js index 730bb803839e..db1461547af8 100644 --- a/packages/engine/Source/Scene/IonImageryProvider.js +++ b/packages/engine/Source/Scene/IonImageryProvider.js @@ -82,7 +82,7 @@ const ImageryProviderAsyncMapping = { * @see IonImageryProvider.fromAssetId */ function IonImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; @@ -266,7 +266,7 @@ IonImageryProvider.fromAssetId = async function (assetId, options) { Check.typeOf.number("assetId", assetId); //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const endpointResource = IonResource._createEndpointResource( assetId, options, diff --git a/packages/engine/Source/Scene/Label.js b/packages/engine/Source/Scene/Label.js index 7196877768a9..7d678e8e02d0 100644 --- a/packages/engine/Source/Scene/Label.js +++ b/packages/engine/Source/Scene/Label.js @@ -137,7 +137,7 @@ function parseFont(label) { * @demo {@link https://sandcastle.cesium.com/index.html?src=Labels.html|Cesium Sandcastle Labels Demo} */ function Label(options, labelCollection) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if ( @@ -201,47 +201,30 @@ function Label(options, labelCollection) { this._renderedText = undefined; this._text = undefined; - this._show = defaultValue(options.show, true); - this._font = defaultValue(options.font, "30px sans-serif"); - this._fillColor = Color.clone(defaultValue(options.fillColor, Color.WHITE)); - this._outlineColor = Color.clone( - defaultValue(options.outlineColor, Color.BLACK), - ); - this._outlineWidth = defaultValue(options.outlineWidth, 1.0); - this._showBackground = defaultValue(options.showBackground, false); + this._show = options.show ?? true; + this._font = options.font ?? "30px sans-serif"; + this._fillColor = Color.clone(options.fillColor ?? Color.WHITE); + this._outlineColor = Color.clone(options.outlineColor ?? Color.BLACK); + this._outlineWidth = options.outlineWidth ?? 1.0; + this._showBackground = options.showBackground ?? false; this._backgroundColor = Color.clone( - defaultValue(options.backgroundColor, defaultBackgroundColor), + options.backgroundColor ?? defaultBackgroundColor, ); this._backgroundPadding = Cartesian2.clone( - defaultValue(options.backgroundPadding, defaultBackgroundPadding), - ); - this._style = defaultValue(options.style, LabelStyle.FILL); - this._verticalOrigin = defaultValue( - options.verticalOrigin, - VerticalOrigin.BASELINE, - ); - this._horizontalOrigin = defaultValue( - options.horizontalOrigin, - HorizontalOrigin.LEFT, - ); - this._pixelOffset = Cartesian2.clone( - defaultValue(options.pixelOffset, Cartesian2.ZERO), + options.backgroundPadding ?? defaultBackgroundPadding, ); - this._eyeOffset = Cartesian3.clone( - defaultValue(options.eyeOffset, Cartesian3.ZERO), - ); - this._position = Cartesian3.clone( - defaultValue(options.position, Cartesian3.ZERO), - ); - this._scale = defaultValue(options.scale, 1.0); + this._style = options.style ?? LabelStyle.FILL; + this._verticalOrigin = options.verticalOrigin ?? VerticalOrigin.BASELINE; + this._horizontalOrigin = options.horizontalOrigin ?? HorizontalOrigin.LEFT; + this._pixelOffset = Cartesian2.clone(options.pixelOffset ?? Cartesian2.ZERO); + this._eyeOffset = Cartesian3.clone(options.eyeOffset ?? Cartesian3.ZERO); + this._position = Cartesian3.clone(options.position ?? Cartesian3.ZERO); + this._scale = options.scale ?? 1.0; this._id = options.id; this._translucencyByDistance = translucencyByDistance; this._pixelOffsetScaleByDistance = pixelOffsetScaleByDistance; this._scaleByDistance = scaleByDistance; - this._heightReference = defaultValue( - options.heightReference, - HeightReference.NONE, - ); + this._heightReference = options.heightReference ?? HeightReference.NONE; this._distanceDisplayCondition = distanceDisplayCondition; this._disableDepthTestDistance = options.disableDepthTestDistance; @@ -259,7 +242,7 @@ function Label(options, labelCollection) { this._clusterShow = true; - this.text = defaultValue(options.text, ""); + this.text = options.text ?? ""; this._relativeSize = 1.0; diff --git a/packages/engine/Source/Scene/LabelCollection.js b/packages/engine/Source/Scene/LabelCollection.js index 6bd01bac9ee8..bb097bdfeba9 100644 --- a/packages/engine/Source/Scene/LabelCollection.js +++ b/packages/engine/Source/Scene/LabelCollection.js @@ -593,7 +593,7 @@ function destroyLabel(labelCollection, label) { * }); */ function LabelCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._scene = options.scene; this._batchTable = options.batchTable; @@ -627,7 +627,7 @@ function LabelCollection(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * The 4x4 transformation matrix that transforms each label in this collection from model to world coordinates. @@ -658,9 +658,7 @@ function LabelCollection(options) { * text : 'Up' * }); */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); /** * This property is for debugging only; it is not for production use nor is it optimized. @@ -672,10 +670,7 @@ function LabelCollection(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * The label blending option. The default is used for rendering both opaque and translucent labels. @@ -685,10 +680,7 @@ function LabelCollection(options) { * @type {BlendOption} * @default BlendOption.OPAQUE_AND_TRANSLUCENT */ - this.blendOption = defaultValue( - options.blendOption, - BlendOption.OPAQUE_AND_TRANSLUCENT, - ); + this.blendOption = options.blendOption ?? BlendOption.OPAQUE_AND_TRANSLUCENT; } Object.defineProperties(LabelCollection.prototype, { diff --git a/packages/engine/Source/Scene/MapboxImageryProvider.js b/packages/engine/Source/Scene/MapboxImageryProvider.js index 2a86db331cfc..fa60c9745d00 100644 --- a/packages/engine/Source/Scene/MapboxImageryProvider.js +++ b/packages/engine/Source/Scene/MapboxImageryProvider.js @@ -47,7 +47,7 @@ const defaultCredit = new Credit( * @see {@link https://docs.mapbox.com/api/accounts/tokens/} */ function MapboxImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const mapId = options.mapId; //>>includeStart('debug', pragmas.debug); if (!defined(mapId)) { @@ -74,13 +74,13 @@ function MapboxImageryProvider(options) { this._defaultMagnificationFilter = undefined; const resource = Resource.createIfNeeded( - defaultValue(options.url, "https://{s}.tiles.mapbox.com/v4/"), + options.url ?? "https://{s}.tiles.mapbox.com/v4/", ); this._mapId = mapId; this._accessToken = accessToken; - let format = defaultValue(options.format, "png"); + let format = options.format ?? "png"; if (!/\./.test(format)) { format = `.${format}`; } diff --git a/packages/engine/Source/Scene/MapboxStyleImageryProvider.js b/packages/engine/Source/Scene/MapboxStyleImageryProvider.js index 6eb2d07d5f3b..2a8610648e85 100644 --- a/packages/engine/Source/Scene/MapboxStyleImageryProvider.js +++ b/packages/engine/Source/Scene/MapboxStyleImageryProvider.js @@ -49,7 +49,7 @@ const defaultCredit = new Credit( * @see {@link https://docs.mapbox.com/api/#access-tokens-and-token-scopes} */ function MapboxStyleImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const styleId = options.styleId; //>>includeStart('debug', pragmas.debug); if (!defined(styleId)) { @@ -76,16 +76,16 @@ function MapboxStyleImageryProvider(options) { this._defaultMagnificationFilter = undefined; const resource = Resource.createIfNeeded( - defaultValue(options.url, "https://api.mapbox.com/styles/v1/"), + options.url ?? "https://api.mapbox.com/styles/v1/", ); this._styleId = styleId; this._accessToken = accessToken; - const tilesize = defaultValue(options.tilesize, 512); + const tilesize = options.tilesize ?? 512; this._tilesize = tilesize; - const username = defaultValue(options.username, "mapbox"); + const username = options.username ?? "mapbox"; this._username = username; const scaleFactor = defined(options.scaleFactor) ? "@2x" : ""; diff --git a/packages/engine/Source/Scene/Material.js b/packages/engine/Source/Scene/Material.js index 8673b8a1b06f..de16bc58b58d 100644 --- a/packages/engine/Source/Scene/Material.js +++ b/packages/engine/Source/Scene/Material.js @@ -308,14 +308,10 @@ function Material(options) { */ this.translucent = undefined; - this._minificationFilter = defaultValue( - options.minificationFilter, - TextureMinificationFilter.LINEAR, - ); - this._magnificationFilter = defaultValue( - options.magnificationFilter, - TextureMagnificationFilter.LINEAR, - ); + this._minificationFilter = + options.minificationFilter ?? TextureMinificationFilter.LINEAR; + this._magnificationFilter = + options.magnificationFilter ?? TextureMagnificationFilter.LINEAR; this._strict = undefined; this._template = undefined; @@ -586,17 +582,15 @@ Material.prototype.destroy = function () { }; function initializeMaterial(options, result) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - result._strict = defaultValue(options.strict, false); - result._count = defaultValue(options.count, 0); - result._template = clone( - defaultValue(options.fabric, defaultValue.EMPTY_OBJECT), - ); + options = options ?? defaultValue.EMPTY_OBJECT; + result._strict = options.strict ?? false; + result._count = options.count ?? 0; + result._template = clone(options.fabric ?? defaultValue.EMPTY_OBJECT); result._template.uniforms = clone( - defaultValue(result._template.uniforms, defaultValue.EMPTY_OBJECT), + result._template.uniforms ?? defaultValue.EMPTY_OBJECT, ); result._template.materials = clone( - defaultValue(result._template.materials, defaultValue.EMPTY_OBJECT), + result._template.materials ?? defaultValue.EMPTY_OBJECT, ); result.type = defined(result._template.type) @@ -633,8 +627,8 @@ function initializeMaterial(options, result) { const defaultTranslucent = result._translucentFunctions.length === 0 ? true : undefined; - translucent = defaultValue(translucent, defaultTranslucent); - translucent = defaultValue(options.translucent, translucent); + translucent = translucent ?? defaultTranslucent; + translucent = options.translucent ?? translucent; if (defined(translucent)) { if (typeof translucent === "function") { @@ -1185,7 +1179,7 @@ function createSubMaterials(material) { // If excludePeriod is true, do not accept tokens that are preceded by periods. // http://stackoverflow.com/questions/641407/javascript-negative-lookbehind-equivalent function replaceToken(material, token, newToken, excludePeriod) { - excludePeriod = defaultValue(excludePeriod, true); + excludePeriod = excludePeriod ?? true; let count = 0; const suffixChars = "([\\w])?"; const prefixChars = `([\\w${excludePeriod ? "." : ""}])?`; diff --git a/packages/engine/Source/Scene/MaterialAppearance.js b/packages/engine/Source/Scene/MaterialAppearance.js index 9dba04b55122..d03829dfdd0f 100644 --- a/packages/engine/Source/Scene/MaterialAppearance.js +++ b/packages/engine/Source/Scene/MaterialAppearance.js @@ -47,14 +47,12 @@ import Material from "./Material.js"; * }); */ function MaterialAppearance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const translucent = defaultValue(options.translucent, true); - const closed = defaultValue(options.closed, false); - const materialSupport = defaultValue( - options.materialSupport, - MaterialAppearance.MaterialSupport.TEXTURED, - ); + const translucent = options.translucent ?? true; + const closed = options.closed ?? false; + const materialSupport = + options.materialSupport ?? MaterialAppearance.MaterialSupport.TEXTURED; /** * The material used to determine the fragment color. Unlike other {@link MaterialAppearance} @@ -79,14 +77,10 @@ function MaterialAppearance(options) { */ this.translucent = translucent; - this._vertexShaderSource = defaultValue( - options.vertexShaderSource, - materialSupport.vertexShaderSource, - ); - this._fragmentShaderSource = defaultValue( - options.fragmentShaderSource, - materialSupport.fragmentShaderSource, - ); + this._vertexShaderSource = + options.vertexShaderSource ?? materialSupport.vertexShaderSource; + this._fragmentShaderSource = + options.fragmentShaderSource ?? materialSupport.fragmentShaderSource; this._renderState = Appearance.getDefaultRenderState( translucent, closed, @@ -98,8 +92,8 @@ function MaterialAppearance(options) { this._materialSupport = materialSupport; this._vertexFormat = materialSupport.vertexFormat; - this._flat = defaultValue(options.flat, false); - this._faceForward = defaultValue(options.faceForward, !closed); + this._flat = options.flat ?? false; + this._faceForward = options.faceForward ?? !closed; } Object.defineProperties(MaterialAppearance.prototype, { diff --git a/packages/engine/Source/Scene/Megatexture.js b/packages/engine/Source/Scene/Megatexture.js index f91828ef0d3f..2b1e927fabe4 100644 --- a/packages/engine/Source/Scene/Megatexture.js +++ b/packages/engine/Source/Scene/Megatexture.js @@ -2,7 +2,6 @@ import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; import ContextLimits from "../Renderer/ContextLimits.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -75,7 +74,7 @@ function Megatexture( const maximumTextureMemoryByteLength = 512 * 1024 * 1024; const defaultTextureMemoryByteLength = 128 * 1024 * 1024; textureMemoryByteLength = Math.min( - defaultValue(textureMemoryByteLength, defaultTextureMemoryByteLength), + textureMemoryByteLength ?? defaultTextureMemoryByteLength, maximumTextureMemoryByteLength, ); const maximumTextureDimensionContext = ContextLimits.maximumTextureSize; diff --git a/packages/engine/Source/Scene/MetadataClass.js b/packages/engine/Source/Scene/MetadataClass.js index 49b9b609e188..898d8d01fe16 100644 --- a/packages/engine/Source/Scene/MetadataClass.js +++ b/packages/engine/Source/Scene/MetadataClass.js @@ -24,14 +24,14 @@ import MetadataClassProperty from "./MetadataClassProperty.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataClass(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const id = options.id; //>>includeStart('debug', pragmas.debug); Check.typeOf.string("options.id", id); //>>includeEnd('debug'); - const properties = defaultValue(options.properties, {}); + const properties = options.properties ?? {}; const propertiesBySemantic = {}; for (const propertyId in properties) { if (properties.hasOwnProperty(propertyId)) { @@ -65,7 +65,7 @@ function MetadataClass(options) { * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ MetadataClass.fromJson = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const id = options.id; const classDefinition = options.class; diff --git a/packages/engine/Source/Scene/MetadataClassProperty.js b/packages/engine/Source/Scene/MetadataClassProperty.js index dec9b1393e3e..15c1e0f9ceae 100644 --- a/packages/engine/Source/Scene/MetadataClassProperty.js +++ b/packages/engine/Source/Scene/MetadataClassProperty.js @@ -45,7 +45,7 @@ import MetadataComponentType from "./MetadataComponentType.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataClassProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const id = options.id; const type = options.type; @@ -60,7 +60,7 @@ function MetadataClassProperty(options) { const normalized = defined(componentType) && MetadataComponentType.isIntegerType(componentType) && - defaultValue(options.normalized, false); + (options.normalized ?? false); // Basic information about this property this._id = id; @@ -78,11 +78,8 @@ function MetadataClassProperty(options) { this._valueType = defined(enumType) ? enumType.valueType : componentType; // Details about arrays - this._isArray = defaultValue(options.isArray, false); - this._isVariableLengthArray = defaultValue( - options.isVariableLengthArray, - false, - ); + this._isArray = options.isArray ?? false; + this._isVariableLengthArray = options.isVariableLengthArray ?? false; this._arrayLength = options.arrayLength; // min and max allowed values @@ -115,7 +112,7 @@ function MetadataClassProperty(options) { // For vector and array types, this is stored as an array of values. this._default = clone(options.default, true); - this._required = defaultValue(options.required, true); + this._required = options.required ?? true; // extras and extensions this._extras = clone(options.extras, true); @@ -136,7 +133,7 @@ function MetadataClassProperty(options) { * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ MetadataClassProperty.fromJson = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const id = options.id; const property = options.property; @@ -164,7 +161,7 @@ MetadataClassProperty.fromJson = function (options) { } else if (isLegacyExtension) { required = defined(property.optional) ? !property.optional : true; } else { - required = defaultValue(property.required, false); + required = property.required ?? false; } return new MetadataClassProperty({ @@ -782,7 +779,7 @@ MetadataClassProperty.prototype.expandConstant = function ( constant, enableNestedArrays, ) { - enableNestedArrays = defaultValue(enableNestedArrays, false); + enableNestedArrays = enableNestedArrays ?? false; const isArray = this._isArray; const arrayLength = this._arrayLength; const componentCount = MetadataType.getComponentCount(this._type); @@ -873,7 +870,7 @@ MetadataClassProperty.prototype.unpackVectorAndMatrixTypes = function ( value, enableNestedArrays, ) { - enableNestedArrays = defaultValue(enableNestedArrays, false); + enableNestedArrays = enableNestedArrays ?? false; const MathType = MetadataType.getMathType(this._type); const isArray = this._isArray; const componentCount = MetadataType.getComponentCount(this._type); @@ -912,7 +909,7 @@ MetadataClassProperty.prototype.packVectorAndMatrixTypes = function ( value, enableNestedArrays, ) { - enableNestedArrays = defaultValue(enableNestedArrays, false); + enableNestedArrays = enableNestedArrays ?? false; const MathType = MetadataType.getMathType(this._type); const isArray = this._isArray; const componentCount = MetadataType.getComponentCount(this._type); diff --git a/packages/engine/Source/Scene/MetadataEnum.js b/packages/engine/Source/Scene/MetadataEnum.js index d4816ad6a9d1..abd0734a12f8 100644 --- a/packages/engine/Source/Scene/MetadataEnum.js +++ b/packages/engine/Source/Scene/MetadataEnum.js @@ -24,7 +24,7 @@ import MetadataComponentType from "./MetadataComponentType.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataEnum(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const id = options.id; const values = options.values; @@ -43,10 +43,7 @@ function MetadataEnum(options) { valuesByName[value.name] = value.value; } - const valueType = defaultValue( - options.valueType, - MetadataComponentType.UINT16, - ); + const valueType = options.valueType ?? MetadataComponentType.UINT16; this._values = values; this._namesByValue = namesByValue; @@ -72,7 +69,7 @@ function MetadataEnum(options) { * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ MetadataEnum.fromJson = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const id = options.id; const enumDefinition = options.enum; diff --git a/packages/engine/Source/Scene/MetadataEnumValue.js b/packages/engine/Source/Scene/MetadataEnumValue.js index d08232daf26e..9ea59ef8b09d 100644 --- a/packages/engine/Source/Scene/MetadataEnumValue.js +++ b/packages/engine/Source/Scene/MetadataEnumValue.js @@ -20,7 +20,7 @@ import defaultValue from "../Core/defaultValue.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataEnumValue(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const value = options.value; const name = options.name; diff --git a/packages/engine/Source/Scene/MetadataSchema.js b/packages/engine/Source/Scene/MetadataSchema.js index b9fb5c0b505d..961fc79de919 100644 --- a/packages/engine/Source/Scene/MetadataSchema.js +++ b/packages/engine/Source/Scene/MetadataSchema.js @@ -26,10 +26,10 @@ import MetadataEnum from "./MetadataEnum.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataSchema(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const classes = defaultValue(options.classes, {}); - const enums = defaultValue(options.enums, {}); + const classes = options.classes ?? {}; + const enums = options.enums ?? {}; this._classes = classes; this._enums = enums; diff --git a/packages/engine/Source/Scene/MetadataSchemaLoader.js b/packages/engine/Source/Scene/MetadataSchemaLoader.js index fd09000df38b..ad4989f4c058 100644 --- a/packages/engine/Source/Scene/MetadataSchemaLoader.js +++ b/packages/engine/Source/Scene/MetadataSchemaLoader.js @@ -26,7 +26,7 @@ import ResourceLoaderState from "./ResourceLoaderState.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataSchemaLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const schema = options.schema; const resource = options.resource; const cacheKey = options.cacheKey; diff --git a/packages/engine/Source/Scene/MetadataTable.js b/packages/engine/Source/Scene/MetadataTable.js index b6113c96b63f..7fffbfc88e5e 100644 --- a/packages/engine/Source/Scene/MetadataTable.js +++ b/packages/engine/Source/Scene/MetadataTable.js @@ -26,7 +26,7 @@ import MetadataTableProperty from "./MetadataTableProperty.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataTable(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const count = options.count; const metadataClass = options.class; diff --git a/packages/engine/Source/Scene/MetadataTableProperty.js b/packages/engine/Source/Scene/MetadataTableProperty.js index 3af58b4f559e..d181cb254876 100644 --- a/packages/engine/Source/Scene/MetadataTableProperty.js +++ b/packages/engine/Source/Scene/MetadataTableProperty.js @@ -32,7 +32,7 @@ import MetadataType from "./MetadataType.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function MetadataTableProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const count = options.count; const property = options.property; const classProperty = options.classProperty; @@ -61,21 +61,14 @@ function MetadataTableProperty(options) { if (isVariableLengthArray) { // EXT_structural_metadata uses arrayOffsetType. // EXT_feature_metadata uses offsetType for both arrays and strings - let arrayOffsetType = defaultValue( - property.arrayOffsetType, - property.offsetType, - ); - arrayOffsetType = defaultValue( - MetadataComponentType[arrayOffsetType], - MetadataComponentType.UINT32, - ); + let arrayOffsetType = property.arrayOffsetType ?? property.offsetType; + arrayOffsetType = + MetadataComponentType[arrayOffsetType] ?? MetadataComponentType.UINT32; // EXT_structural_metadata uses arrayOffsets. // EXT_feature_metadata uses arrayOffsetBufferView - const arrayOffsetBufferView = defaultValue( - property.arrayOffsets, - property.arrayOffsetBufferView, - ); + const arrayOffsetBufferView = + property.arrayOffsets ?? property.arrayOffsetBufferView; arrayOffsets = new BufferView( bufferViews[arrayOffsetBufferView], arrayOffsetType, @@ -101,21 +94,14 @@ function MetadataTableProperty(options) { let stringOffsets; if (hasStrings) { // EXT_structural_metadata uses stringOffsetType, EXT_feature_metadata uses offsetType for both arrays and strings - let stringOffsetType = defaultValue( - property.stringOffsetType, - property.offsetType, - ); - stringOffsetType = defaultValue( - MetadataComponentType[stringOffsetType], - MetadataComponentType.UINT32, - ); + let stringOffsetType = property.stringOffsetType ?? property.offsetType; + stringOffsetType = + MetadataComponentType[stringOffsetType] ?? MetadataComponentType.UINT32; // EXT_structural_metadata uses stringOffsets. // EXT_feature_metadata uses stringOffsetBufferView - const stringOffsetBufferView = defaultValue( - property.stringOffsets, - property.stringOffsetBufferView, - ); + const stringOffsetBufferView = + property.stringOffsets ?? property.stringOffsetBufferView; stringOffsets = new BufferView( bufferViews[stringOffsetBufferView], stringOffsetType, @@ -141,7 +127,7 @@ function MetadataTableProperty(options) { // EXT_structural_metadata uses values // EXT_feature_metadata uses bufferView - const valuesBufferView = defaultValue(property.values, property.bufferView); + const valuesBufferView = property.values ?? property.bufferView; const values = new BufferView( bufferViews[valuesBufferView], valueType, @@ -160,8 +146,8 @@ function MetadataTableProperty(options) { // class property. The class property handles setting the default of identity: // (offset 0, scale 1) with the same array shape as the property's type // information. - offset = defaultValue(offset, classProperty.offset); - scale = defaultValue(scale, classProperty.scale); + offset = offset ?? classProperty.offset; + scale = scale ?? classProperty.scale; // Since metadata table properties are stored as packed typed // arrays, flatten the offset/scale to make it easier to apply the @@ -446,7 +432,7 @@ function getArrayValues(property, classProperty, index) { offset *= componentCount; length *= componentCount; } else { - const arrayLength = defaultValue(classProperty.arrayLength, 1); + const arrayLength = classProperty.arrayLength ?? 1; const componentCount = arrayLength * property._vectorComponentCount; offset = index * componentCount; length = componentCount; @@ -493,7 +479,7 @@ function set(property, index, value) { offset = property._arrayOffsets.get(index); length = property._arrayOffsets.get(index + 1) - offset; } else { - const arrayLength = defaultValue(classProperty.arrayLength, 1); + const arrayLength = classProperty.arrayLength ?? 1; const componentCount = arrayLength * property._vectorComponentCount; offset = index * componentCount; length = componentCount; diff --git a/packages/engine/Source/Scene/Model/AlphaPipelineStage.js b/packages/engine/Source/Scene/Model/AlphaPipelineStage.js index c21113304ac4..4819d9283991 100644 --- a/packages/engine/Source/Scene/Model/AlphaPipelineStage.js +++ b/packages/engine/Source/Scene/Model/AlphaPipelineStage.js @@ -1,4 +1,3 @@ -import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import ShaderDestination from "../../Renderer/ShaderDestination.js"; import BlendingState from "../BlendingState.js"; @@ -20,7 +19,7 @@ AlphaPipelineStage.process = function (renderResources, primitive, frameState) { // Ensure the pass is defined const model = renderResources.model; - alphaOptions.pass = defaultValue(alphaOptions.pass, model.opaquePass); + alphaOptions.pass = alphaOptions.pass ?? model.opaquePass; const renderStateOptions = renderResources.renderStateOptions; if (alphaOptions.pass === Pass.TRANSLUCENT) { diff --git a/packages/engine/Source/Scene/Model/B3dmLoader.js b/packages/engine/Source/Scene/Model/B3dmLoader.js index c9bb0feff45a..8d4cb27ab07f 100644 --- a/packages/engine/Source/Scene/Model/B3dmLoader.js +++ b/packages/engine/Source/Scene/Model/B3dmLoader.js @@ -56,35 +56,24 @@ const FeatureIdAttribute = ModelComponents.FeatureIdAttribute; * @param {boolean} [options.loadForClassification=false] If true and if the model has feature IDs, load the feature IDs and indices as typed arrays. This is useful for batching features for classification. * */ function B3dmLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const b3dmResource = options.b3dmResource; let baseResource = options.baseResource; const arrayBuffer = options.arrayBuffer; - const byteOffset = defaultValue(options.byteOffset, 0); - const releaseGltfJson = defaultValue(options.releaseGltfJson, false); - const asynchronous = defaultValue(options.asynchronous, true); - const incrementallyLoadTextures = defaultValue( - options.incrementallyLoadTextures, - true, - ); - const upAxis = defaultValue(options.upAxis, Axis.Y); - const forwardAxis = defaultValue(options.forwardAxis, Axis.X); - const loadAttributesAsTypedArray = defaultValue( - options.loadAttributesAsTypedArray, - false, - ); - const loadAttributesFor2D = defaultValue(options.loadAttributesFor2D, false); - const enablePick = defaultValue(options.enablePick, false); - const loadIndicesForWireframe = defaultValue( - options.loadIndicesForWireframe, - false, - ); - const loadPrimitiveOutline = defaultValue(options.loadPrimitiveOutline, true); - const loadForClassification = defaultValue( - options.loadForClassification, - false, - ); + const byteOffset = options.byteOffset ?? 0; + const releaseGltfJson = options.releaseGltfJson ?? false; + const asynchronous = options.asynchronous ?? true; + const incrementallyLoadTextures = options.incrementallyLoadTextures ?? true; + const upAxis = options.upAxis ?? Axis.Y; + const forwardAxis = options.forwardAxis ?? Axis.X; + const loadAttributesAsTypedArray = + options.loadAttributesAsTypedArray ?? false; + const loadAttributesFor2D = options.loadAttributesFor2D ?? false; + const enablePick = options.enablePick ?? false; + const loadIndicesForWireframe = options.loadIndicesForWireframe ?? false; + const loadPrimitiveOutline = options.loadPrimitiveOutline ?? true; + const loadForClassification = options.loadForClassification ?? false; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.b3dmResource", b3dmResource); diff --git a/packages/engine/Source/Scene/Model/BatchTexturePipelineStage.js b/packages/engine/Source/Scene/Model/BatchTexturePipelineStage.js index fd9047de3473..5461ed79a393 100644 --- a/packages/engine/Source/Scene/Model/BatchTexturePipelineStage.js +++ b/packages/engine/Source/Scene/Model/BatchTexturePipelineStage.js @@ -1,5 +1,4 @@ import combine from "../../Core/combine.js"; -import defaultValue from "../../Core/defaultValue.js"; /** * The batch texture stage is responsible for setting up the batch texture for the primitive. @@ -45,7 +44,7 @@ BatchTexturePipelineStage.process = function ( const batchTexture = featureTable.batchTexture; shaderBuilder.addUniform("sampler2D", "model_batchTexture"); batchTextureUniforms.model_batchTexture = function () { - return defaultValue(batchTexture.batchTexture, batchTexture.defaultTexture); + return batchTexture.batchTexture ?? batchTexture.defaultTexture; }; // Batch texture step size diff --git a/packages/engine/Source/Scene/Model/ClassificationModelDrawCommand.js b/packages/engine/Source/Scene/Model/ClassificationModelDrawCommand.js index 1b8c3c91115c..5a0f6a8f14d3 100644 --- a/packages/engine/Source/Scene/Model/ClassificationModelDrawCommand.js +++ b/packages/engine/Source/Scene/Model/ClassificationModelDrawCommand.js @@ -28,7 +28,7 @@ import StencilOperation from "../StencilOperation.js"; * @private */ function ClassificationModelDrawCommand(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const command = options.command; const renderResources = options.primitiveRenderResources; diff --git a/packages/engine/Source/Scene/Model/CustomShader.js b/packages/engine/Source/Scene/Model/CustomShader.js index d4ead8fbd3ba..7cf659ed689d 100644 --- a/packages/engine/Source/Scene/Model/CustomShader.js +++ b/packages/engine/Source/Scene/Model/CustomShader.js @@ -120,7 +120,7 @@ import CustomShaderTranslucencyMode from "./CustomShaderTranslucencyMode.js"; * }); */ function CustomShader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * A value determining how the custom shader interacts with the overall @@ -129,7 +129,7 @@ function CustomShader(options) { * @type {CustomShaderMode} * @readonly */ - this.mode = defaultValue(options.mode, CustomShaderMode.MODIFY_MATERIAL); + this.mode = options.mode ?? CustomShaderMode.MODIFY_MATERIAL; /** * The lighting model to use when using the custom shader. * This is used by {@link CustomShaderPipelineStage} @@ -144,7 +144,7 @@ function CustomShader(options) { * @type {Object} * @readonly */ - this.uniforms = defaultValue(options.uniforms, defaultValue.EMPTY_OBJECT); + this.uniforms = options.uniforms ?? defaultValue.EMPTY_OBJECT; /** * Additional varyings as declared by the user. * This is used by {@link CustomShaderPipelineStage} @@ -152,7 +152,7 @@ function CustomShader(options) { * @type {Object} * @readonly */ - this.varyings = defaultValue(options.varyings, defaultValue.EMPTY_OBJECT); + this.varyings = options.varyings ?? defaultValue.EMPTY_OBJECT; /** * The user-defined GLSL code for the vertex shader * @@ -178,10 +178,8 @@ function CustomShader(options) { * @default CustomShaderTranslucencyMode.INHERIT * @readonly */ - this.translucencyMode = defaultValue( - options.translucencyMode, - CustomShaderTranslucencyMode.INHERIT, - ); + this.translucencyMode = + options.translucencyMode ?? CustomShaderTranslucencyMode.INHERIT; /** * texture uniforms require some asynchronous processing. This is delegated @@ -273,9 +271,9 @@ function buildUniformMap(customShader) { function createUniformTexture2DFunction(customShader, uniformName) { return function () { - return defaultValue( - customShader._textureManager.getTexture(uniformName), - customShader._defaultTexture, + return ( + customShader._textureManager.getTexture(uniformName) ?? + customShader._defaultTexture ); }; } diff --git a/packages/engine/Source/Scene/Model/Extensions/Gpm/GltfMeshPrimitiveGpmLoader.js b/packages/engine/Source/Scene/Model/Extensions/Gpm/GltfMeshPrimitiveGpmLoader.js index 7be022144311..334887e0978c 100644 --- a/packages/engine/Source/Scene/Model/Extensions/Gpm/GltfMeshPrimitiveGpmLoader.js +++ b/packages/engine/Source/Scene/Model/Extensions/Gpm/GltfMeshPrimitiveGpmLoader.js @@ -39,7 +39,7 @@ import MeshPrimitiveGpmLocal from "./MeshPrimitiveGpmLocal.js"; * @private */ function GltfMeshPrimitiveGpmLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const gltf = options.gltf; const extension = options.extension; const gltfResource = options.gltfResource; @@ -47,7 +47,7 @@ function GltfMeshPrimitiveGpmLoader(options) { const supportedImageFormats = options.supportedImageFormats; const frameState = options.frameState; const cacheKey = options.cacheKey; - const asynchronous = defaultValue(options.asynchronous, true); + const asynchronous = options.asynchronous ?? true; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.gltf", gltf); diff --git a/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js b/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js index a4f25ff160f9..33f5e1d8c5ac 100644 --- a/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js +++ b/packages/engine/Source/Scene/Model/FeatureIdPipelineStage.js @@ -1,5 +1,4 @@ import ComponentDatatype from "../../Core/ComponentDatatype.js"; -import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import ShaderDestination from "../../Renderer/ShaderDestination.js"; import Buffer from "../../Renderer/Buffer.js"; @@ -359,10 +358,7 @@ function processTexture( const uniformMap = renderResources.uniformMap; const textureReader = featureIdTexture.textureReader; uniformMap[uniformName] = function () { - return defaultValue( - textureReader.texture, - frameState.context.defaultTexture, - ); + return textureReader.texture ?? frameState.context.defaultTexture; }; const channels = textureReader.channels; diff --git a/packages/engine/Source/Scene/Model/GeoJsonLoader.js b/packages/engine/Source/Scene/Model/GeoJsonLoader.js index 092962cd10f5..ae08bf188112 100644 --- a/packages/engine/Source/Scene/Model/GeoJsonLoader.js +++ b/packages/engine/Source/Scene/Model/GeoJsonLoader.js @@ -41,7 +41,7 @@ import BufferUsage from "../../Renderer/BufferUsage.js"; * @param {object} options.geoJson The GeoJson object. */ function GeoJsonLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.geoJson", options.geoJson); @@ -129,7 +129,7 @@ function ParseResult() { function parsePosition(position) { const x = position[0]; const y = position[1]; - const z = defaultValue(position[2], 0.0); + const z = position[2] ?? 0.0; return new Cartesian3(x, y, z); } @@ -546,10 +546,7 @@ function parse(geoJson, frameState) { const properties = {}; for (let i = 0; i < featureCount; i++) { const feature = features[i]; - const featureProperties = defaultValue( - feature.properties, - defaultValue.EMPTY_OBJECT, - ); + const featureProperties = feature.properties ?? defaultValue.EMPTY_OBJECT; for (const propertyId in featureProperties) { if (featureProperties.hasOwnProperty(propertyId)) { if (!defined(properties[propertyId])) { @@ -564,7 +561,7 @@ function parse(geoJson, frameState) { const feature = features[i]; for (const propertyId in properties) { if (properties.hasOwnProperty(propertyId)) { - const value = defaultValue(feature.properties[propertyId], ""); + const value = feature.properties[propertyId] ?? ""; properties[propertyId][i] = value; } } diff --git a/packages/engine/Source/Scene/Model/I3dmLoader.js b/packages/engine/Source/Scene/Model/I3dmLoader.js index 8328628bd150..deb51cde2f5e 100644 --- a/packages/engine/Source/Scene/Model/I3dmLoader.js +++ b/packages/engine/Source/Scene/Model/I3dmLoader.js @@ -69,30 +69,22 @@ const Instances = ModelComponents.Instances; * @param {boolean} [options.loadPrimitiveOutline=true] If true, load outlines from the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set false to avoid post-processing geometry at load time. */ function I3dmLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const i3dmResource = options.i3dmResource; const arrayBuffer = options.arrayBuffer; let baseResource = options.baseResource; - const byteOffset = defaultValue(options.byteOffset, 0); - const releaseGltfJson = defaultValue(options.releaseGltfJson, false); - const asynchronous = defaultValue(options.asynchronous, true); - const incrementallyLoadTextures = defaultValue( - options.incrementallyLoadTextures, - true, - ); - const upAxis = defaultValue(options.upAxis, Axis.Y); - const forwardAxis = defaultValue(options.forwardAxis, Axis.X); - const loadAttributesAsTypedArray = defaultValue( - options.loadAttributesAsTypedArray, - false, - ); - const loadIndicesForWireframe = defaultValue( - options.loadIndicesForWireframe, - false, - ); - const loadPrimitiveOutline = defaultValue(options.loadPrimitiveOutline, true); - const enablePick = defaultValue(options.enablePick, false); + const byteOffset = options.byteOffset ?? 0; + const releaseGltfJson = options.releaseGltfJson ?? false; + const asynchronous = options.asynchronous ?? true; + const incrementallyLoadTextures = options.incrementallyLoadTextures ?? true; + const upAxis = options.upAxis ?? Axis.Y; + const forwardAxis = options.forwardAxis ?? Axis.X; + const loadAttributesAsTypedArray = + options.loadAttributesAsTypedArray ?? false; + const loadIndicesForWireframe = options.loadIndicesForWireframe ?? false; + const loadPrimitiveOutline = options.loadPrimitiveOutline ?? true; + const enablePick = options.enablePick ?? false; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.i3dmResource", i3dmResource); diff --git a/packages/engine/Source/Scene/Model/MaterialPipelineStage.js b/packages/engine/Source/Scene/Model/MaterialPipelineStage.js index 577741aae74b..ed2812a83bd9 100644 --- a/packages/engine/Source/Scene/Model/MaterialPipelineStage.js +++ b/packages/engine/Source/Scene/Model/MaterialPipelineStage.js @@ -1,5 +1,4 @@ import defined from "../../Core/defined.js"; -import defaultValue from "../../Core/defaultValue.js"; import Cartesian3 from "../../Core/Cartesian3.js"; import Cartesian4 from "../../Core/Cartesian4.js"; import Matrix3 from "../../Core/Matrix3.js"; @@ -272,7 +271,7 @@ function processTexture( ShaderDestination.FRAGMENT, ); uniformMap[uniformName] = function () { - return defaultValue(textureReader.texture, defaultTexture); + return textureReader.texture ?? defaultTexture; }; // Add a #define directive to enable using the texture in the shader diff --git a/packages/engine/Source/Scene/Model/Model.js b/packages/engine/Source/Scene/Model/Model.js index 1e76382b423c..e6b84454cfa4 100644 --- a/packages/engine/Source/Scene/Model/Model.js +++ b/packages/engine/Source/Scene/Model/Model.js @@ -174,7 +174,7 @@ import pickModel from "./pickModel.js"; * @demo {@link https://sandcastle.cesium.com/index.html?src=3D%20Models.html|Cesium Sandcastle Models Demo} */ function Model(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.loader", options.loader); Check.typeOf.object("options.resource", options.resource); @@ -198,7 +198,7 @@ function Model(options) { * * @private */ - this.type = defaultValue(options.type, ModelType.GLTF); + this.type = options.type ?? ModelType.GLTF; /** * The 4x4 transformation matrix that transforms the model from model to world coordinates. @@ -214,13 +214,11 @@ function Model(options) { * const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0); * m.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin); */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._modelMatrix = Matrix4.clone(this.modelMatrix); - this._scale = defaultValue(options.scale, 1.0); + this._scale = options.scale ?? 1.0; - this._minimumPixelSize = defaultValue(options.minimumPixelSize, 0.0); + this._minimumPixelSize = options.minimumPixelSize ?? 0.0; this._maximumScale = options.maximumScale; @@ -269,7 +267,7 @@ function Model(options) { this._defaultTexture = undefined; this._activeAnimations = new ModelAnimationCollection(this); - this._clampAnimations = defaultValue(options.clampAnimations, true); + this._clampAnimations = options.clampAnimations ?? true; // This flag is true when the Cesium API, not a glTF animation, changes // the transform of a node in the model. @@ -279,15 +277,12 @@ function Model(options) { this._idDirty = false; this._color = Color.clone(options.color); - this._colorBlendMode = defaultValue( - options.colorBlendMode, - ColorBlendMode.HIGHLIGHT, - ); - this._colorBlendAmount = defaultValue(options.colorBlendAmount, 0.5); + this._colorBlendMode = options.colorBlendMode ?? ColorBlendMode.HIGHLIGHT; + this._colorBlendAmount = options.colorBlendAmount ?? 0.5; - const silhouetteColor = defaultValue(options.silhouetteColor, Color.RED); + const silhouetteColor = options.silhouetteColor ?? Color.RED; this._silhouetteColor = Color.clone(silhouetteColor); - this._silhouetteSize = defaultValue(options.silhouetteSize, 0.0); + this._silhouetteSize = options.silhouetteSize ?? 0.0; this._silhouetteDirty = false; // If silhouettes are used for the model, this will be set to the number @@ -295,25 +290,23 @@ function Model(options) { // by ModelSilhouettePipelineStage, not by Model itself. this._silhouetteId = undefined; - this._cull = defaultValue(options.cull, true); - this._opaquePass = defaultValue(options.opaquePass, Pass.OPAQUE); - this._allowPicking = defaultValue(options.allowPicking, true); - this._show = defaultValue(options.show, true); + this._cull = options.cull ?? true; + this._opaquePass = options.opaquePass ?? Pass.OPAQUE; + this._allowPicking = options.allowPicking ?? true; + this._show = options.show ?? true; this._style = undefined; this._styleDirty = false; this._styleCommandsNeeded = undefined; - let featureIdLabel = defaultValue(options.featureIdLabel, "featureId_0"); + let featureIdLabel = options.featureIdLabel ?? "featureId_0"; if (typeof featureIdLabel === "number") { featureIdLabel = `featureId_${featureIdLabel}`; } this._featureIdLabel = featureIdLabel; - let instanceFeatureIdLabel = defaultValue( - options.instanceFeatureIdLabel, - "instanceFeatureId_0", - ); + let instanceFeatureIdLabel = + options.instanceFeatureIdLabel ?? "instanceFeatureId_0"; if (typeof instanceFeatureIdLabel === "number") { instanceFeatureIdLabel = `instanceFeatureId_${instanceFeatureIdLabel}`; } @@ -339,17 +332,11 @@ function Model(options) { this._boundingSphere = new BoundingSphere(); this._initialRadius = undefined; - this._heightReference = defaultValue( - options.heightReference, - HeightReference.NONE, - ); + this._heightReference = options.heightReference ?? HeightReference.NONE; this._heightDirty = this._heightReference !== HeightReference.NONE; this._removeUpdateHeightCallback = undefined; - this._enableVerticalExaggeration = defaultValue( - options.enableVerticalExaggeration, - true, - ); + this._enableVerticalExaggeration = options.enableVerticalExaggeration ?? true; this._hasVerticalExaggeration = false; this._clampedModelMatrix = undefined; // For use with height reference @@ -412,24 +399,18 @@ function Model(options) { "_environmentMapManager", ); - this._backFaceCulling = defaultValue(options.backFaceCulling, true); + this._backFaceCulling = options.backFaceCulling ?? true; this._backFaceCullingDirty = false; - this._shadows = defaultValue(options.shadows, ShadowMode.ENABLED); + this._shadows = options.shadows ?? ShadowMode.ENABLED; this._shadowsDirty = false; this._debugShowBoundingVolumeDirty = false; - this._debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this._debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; - this._enableDebugWireframe = defaultValue( - options.enableDebugWireframe, - false, - ); - this._enableShowOutline = defaultValue(options.enableShowOutline, true); - this._debugWireframe = defaultValue(options.debugWireframe, false); + this._enableDebugWireframe = options.enableDebugWireframe ?? false; + this._enableShowOutline = options.enableShowOutline ?? true; + this._debugWireframe = options.debugWireframe ?? false; // Warning for improper setup of debug wireframe if ( @@ -458,15 +439,12 @@ function Model(options) { // Credits parsed from the glTF by GltfLoader. this._gltfCredits = []; - this._showCreditsOnScreen = defaultValue(options.showCreditsOnScreen, false); + this._showCreditsOnScreen = options.showCreditsOnScreen ?? false; this._showCreditsOnScreenDirty = true; - this._splitDirection = defaultValue( - options.splitDirection, - SplitDirection.NONE, - ); + this._splitDirection = options.splitDirection ?? SplitDirection.NONE; - this._enableShowOutline = defaultValue(options.enableShowOutline, true); + this._enableShowOutline = options.enableShowOutline ?? true; /** * Whether to display the outline for models using the @@ -477,7 +455,7 @@ function Model(options) { * * @default true */ - this.showOutline = defaultValue(options.showOutline, true); + this.showOutline = options.showOutline ?? true; /** * The color to use when rendering outlines. @@ -486,20 +464,20 @@ function Model(options) { * * @default Color.BLACK */ - this.outlineColor = defaultValue(options.outlineColor, Color.BLACK); + this.outlineColor = options.outlineColor ?? Color.BLACK; this._classificationType = options.classificationType; this._statistics = new ModelStatistics(); this._sceneMode = undefined; - this._projectTo2D = defaultValue(options.projectTo2D, false); - this._enablePick = defaultValue(options.enablePick, false); + this._projectTo2D = options.projectTo2D ?? false; + this._enablePick = options.enablePick ?? false; this._fogRenderable = undefined; this._skipLevelOfDetail = false; - this._ignoreCommands = defaultValue(options.ignoreCommands, false); + this._ignoreCommands = options.ignoreCommands ?? false; this._errorEvent = new Event(); this._readyEvent = new Event(); @@ -678,7 +656,7 @@ Object.defineProperties(Model.prototype, { */ incrementallyLoadTextures: { get: function () { - return defaultValue(this._loader.incrementallyLoadTextures, false); + return this._loader.incrementallyLoadTextures ?? false; }, }, @@ -2265,7 +2243,7 @@ function updateClamping(model) { return; } - const ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.default); + const ellipsoid = scene.ellipsoid ?? Ellipsoid.default; // Compute cartographic position so we don't recompute every update const modelMatrix = model.modelMatrix; @@ -2399,7 +2377,7 @@ function updateReferenceMatrices(model, frameState) { const modelMatrix = defined(model._clampedModelMatrix) ? model._clampedModelMatrix : model.modelMatrix; - const referenceMatrix = defaultValue(model.referenceMatrix, modelMatrix); + const referenceMatrix = model.referenceMatrix ?? modelMatrix; const context = frameState.context; let iblReferenceFrameMatrix3 = scratchIBLReferenceFrameMatrix3; @@ -3012,7 +2990,7 @@ Model.prototype.destroyModelResources = function () { * } */ Model.fromGltfAsync = async function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.url) && !defined(options.gltf)) { @@ -3023,7 +3001,7 @@ Model.fromGltfAsync = async function (options) { // options.gltf is used internally for 3D Tiles. It can be a Resource, a URL // to a glTF/glb file, a binary glTF buffer, or a JSON object containing the // glTF contents. - const gltf = defaultValue(options.url, options.gltf); + const gltf = options.url ?? options.gltf; const loaderOptions = { releaseGltfJson: options.releaseGltfJson, @@ -3038,7 +3016,7 @@ Model.fromGltfAsync = async function (options) { loadForClassification: defined(options.classificationType), }; - const basePath = defaultValue(options.basePath, ""); + const basePath = options.basePath ?? ""; const baseResource = Resource.createIfNeeded(basePath); if (defined(gltf.asset)) { diff --git a/packages/engine/Source/Scene/Model/ModelAnimation.js b/packages/engine/Source/Scene/Model/ModelAnimation.js index c78535b402a0..82ad2c7ad5a0 100644 --- a/packages/engine/Source/Scene/Model/ModelAnimation.js +++ b/packages/engine/Source/Scene/Model/ModelAnimation.js @@ -1,4 +1,3 @@ -import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import Event from "../../Core/Event.js"; import JulianDate from "../../Core/JulianDate.js"; @@ -29,7 +28,7 @@ function ModelAnimation(model, animation, options) { this._runtimeChannels = undefined; this._startTime = JulianDate.clone(options.startTime); - this._delay = defaultValue(options.delay, 0.0); // in seconds + this._delay = options.delay ?? 0.0; // in seconds this._stopTime = JulianDate.clone(options.stopTime); /** @@ -40,10 +39,10 @@ function ModelAnimation(model, animation, options) { * @type {boolean} * @default false */ - this.removeOnStop = defaultValue(options.removeOnStop, false); - this._multiplier = defaultValue(options.multiplier, 1.0); - this._reverse = defaultValue(options.reverse, false); - this._loop = defaultValue(options.loop, ModelAnimationLoop.NONE); + this.removeOnStop = options.removeOnStop ?? false; + this._multiplier = options.multiplier ?? 1.0; + this._reverse = options.reverse ?? false; + this._loop = options.loop ?? ModelAnimationLoop.NONE; this._animationTime = options.animationTime; this._prevAnimationDelta = undefined; diff --git a/packages/engine/Source/Scene/Model/ModelAnimationChannel.js b/packages/engine/Source/Scene/Model/ModelAnimationChannel.js index 9dbb92a00b5c..2322f4688579 100644 --- a/packages/engine/Source/Scene/Model/ModelAnimationChannel.js +++ b/packages/engine/Source/Scene/Model/ModelAnimationChannel.js @@ -29,7 +29,7 @@ const AnimatedPropertyType = ModelComponents.AnimatedPropertyType; * @private */ function ModelAnimationChannel(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const channel = options.channel; const runtimeAnimation = options.runtimeAnimation; diff --git a/packages/engine/Source/Scene/Model/ModelAnimationCollection.js b/packages/engine/Source/Scene/Model/ModelAnimationCollection.js index 3c441c0aa94f..65ffa8d2a420 100644 --- a/packages/engine/Source/Scene/Model/ModelAnimationCollection.js +++ b/packages/engine/Source/Scene/Model/ModelAnimationCollection.js @@ -167,7 +167,7 @@ function addAnimation(collection, animation, options) { * }); */ ModelAnimationCollection.prototype.add = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const model = this._model; @@ -251,7 +251,7 @@ ModelAnimationCollection.prototype.add = function (options) { * }); */ ModelAnimationCollection.prototype.addAll = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const model = this._model; @@ -426,7 +426,7 @@ ModelAnimationCollection.prototype.update = function (frameState) { if (!defined(runtimeAnimation._computedStartTime)) { runtimeAnimation._computedStartTime = JulianDate.addSeconds( - defaultValue(runtimeAnimation.startTime, sceneTime), + runtimeAnimation.startTime ?? sceneTime, runtimeAnimation.delay, new JulianDate(), ); diff --git a/packages/engine/Source/Scene/Model/ModelArticulation.js b/packages/engine/Source/Scene/Model/ModelArticulation.js index bc3f745d9d6d..af9d58abb49a 100644 --- a/packages/engine/Source/Scene/Model/ModelArticulation.js +++ b/packages/engine/Source/Scene/Model/ModelArticulation.js @@ -19,7 +19,7 @@ import ModelArticulationStage from "./ModelArticulationStage.js"; * @private */ function ModelArticulation(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const articulation = options.articulation; const sceneGraph = options.sceneGraph; diff --git a/packages/engine/Source/Scene/Model/ModelArticulationStage.js b/packages/engine/Source/Scene/Model/ModelArticulationStage.js index 772c03966732..c5e2311fdc8e 100644 --- a/packages/engine/Source/Scene/Model/ModelArticulationStage.js +++ b/packages/engine/Source/Scene/Model/ModelArticulationStage.js @@ -22,7 +22,7 @@ const articulationEpsilon = CesiumMath.EPSILON16; * @private */ function ModelArticulationStage(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const stage = options.stage; const runtimeArticulation = options.runtimeArticulation; diff --git a/packages/engine/Source/Scene/Model/ModelDrawCommand.js b/packages/engine/Source/Scene/Model/ModelDrawCommand.js index 4bbc2a841aca..94be3ed58f3d 100644 --- a/packages/engine/Source/Scene/Model/ModelDrawCommand.js +++ b/packages/engine/Source/Scene/Model/ModelDrawCommand.js @@ -34,7 +34,7 @@ import StyleCommandsNeeded from "./StyleCommandsNeeded.js"; * @private */ function ModelDrawCommand(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const command = options.command; const renderResources = options.primitiveRenderResources; @@ -124,7 +124,7 @@ function ModelDerivedCommand(options) { this.updateDebugShowBoundingVolume = options.updateDebugShowBoundingVolume; // Whether this ModelDerivedCommand is in 2D. - this.is2D = defaultValue(options.is2D, false); + this.is2D = options.is2D ?? false; // A ModelDerivedCommand that is the 2D version of this one. this.derivedCommand2D = undefined; diff --git a/packages/engine/Source/Scene/Model/ModelFeatureTable.js b/packages/engine/Source/Scene/Model/ModelFeatureTable.js index dff95e0582e8..24dc7ec5c2ee 100644 --- a/packages/engine/Source/Scene/Model/ModelFeatureTable.js +++ b/packages/engine/Source/Scene/Model/ModelFeatureTable.js @@ -5,7 +5,6 @@ import Color from "../../Core/Color.js"; import defined from "../../Core/defined.js"; import destroyObject from "../../Core/destroyObject.js"; import ModelFeature from "./ModelFeature.js"; -import defaultValue from "../../Core/defaultValue.js"; import StyleCommandsNeeded from "./StyleCommandsNeeded.js"; import ModelType from "./ModelType.js"; @@ -264,16 +263,11 @@ ModelFeatureTable.prototype.applyStyle = function (style) { for (let i = 0; i < this._featuresLength; i++) { const feature = this.getFeature(i); const color = defined(style.color) - ? defaultValue( - style.color.evaluateColor(feature, scratchColor), - BatchTexture.DEFAULT_COLOR_VALUE, - ) + ? (style.color.evaluateColor(feature, scratchColor) ?? + BatchTexture.DEFAULT_COLOR_VALUE) : BatchTexture.DEFAULT_COLOR_VALUE; const show = defined(style.show) - ? defaultValue( - style.show.evaluate(feature), - BatchTexture.DEFAULT_SHOW_VALUE, - ) + ? (style.show.evaluate(feature) ?? BatchTexture.DEFAULT_SHOW_VALUE) : BatchTexture.DEFAULT_SHOW_VALUE; this.setColor(i, color); diff --git a/packages/engine/Source/Scene/Model/ModelLightingOptions.js b/packages/engine/Source/Scene/Model/ModelLightingOptions.js index 747034dbe46b..f2bb930170d9 100644 --- a/packages/engine/Source/Scene/Model/ModelLightingOptions.js +++ b/packages/engine/Source/Scene/Model/ModelLightingOptions.js @@ -13,7 +13,7 @@ import LightingModel from "./LightingModel.js"; * @private */ function ModelLightingOptions(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The lighting model to use, such as UNLIT or PBR. This is determined by @@ -23,7 +23,7 @@ function ModelLightingOptions(options) { * * @private */ - this.lightingModel = defaultValue(options.lightingModel, LightingModel.UNLIT); + this.lightingModel = options.lightingModel ?? LightingModel.UNLIT; } export default ModelLightingOptions; diff --git a/packages/engine/Source/Scene/Model/ModelRuntimeNode.js b/packages/engine/Source/Scene/Model/ModelRuntimeNode.js index a45a3078304e..535ff6419817 100644 --- a/packages/engine/Source/Scene/Model/ModelRuntimeNode.js +++ b/packages/engine/Source/Scene/Model/ModelRuntimeNode.js @@ -26,7 +26,7 @@ import NodeStatisticsPipelineStage from "./NodeStatisticsPipelineStage.js"; * @private */ function ModelRuntimeNode(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const node = options.node; const transform = options.transform; diff --git a/packages/engine/Source/Scene/Model/ModelRuntimePrimitive.js b/packages/engine/Source/Scene/Model/ModelRuntimePrimitive.js index dca730224b55..838f42d43c3e 100644 --- a/packages/engine/Source/Scene/Model/ModelRuntimePrimitive.js +++ b/packages/engine/Source/Scene/Model/ModelRuntimePrimitive.js @@ -43,7 +43,7 @@ import WireframePipelineStage from "./WireframePipelineStage.js"; * @private */ function ModelRuntimePrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const primitive = options.primitive; const node = options.node; diff --git a/packages/engine/Source/Scene/Model/ModelSceneGraph.js b/packages/engine/Source/Scene/Model/ModelSceneGraph.js index 248ee80f3403..741c59616573 100644 --- a/packages/engine/Source/Scene/Model/ModelSceneGraph.js +++ b/packages/engine/Source/Scene/Model/ModelSceneGraph.js @@ -40,7 +40,7 @@ import ModelDrawCommands from "./ModelDrawCommands.js"; * @private */ function ModelSceneGraph(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const components = options.modelComponents; //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Scene/Model/ModelSkin.js b/packages/engine/Source/Scene/Model/ModelSkin.js index 2a62ef61dcfb..a7165c46fc94 100644 --- a/packages/engine/Source/Scene/Model/ModelSkin.js +++ b/packages/engine/Source/Scene/Model/ModelSkin.js @@ -17,7 +17,7 @@ import defaultValue from "../../Core/defaultValue.js"; * @private */ function ModelSkin(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.skin", options.skin); Check.typeOf.object("options.sceneGraph", options.sceneGraph); diff --git a/packages/engine/Source/Scene/Model/PickingPipelineStage.js b/packages/engine/Source/Scene/Model/PickingPipelineStage.js index 76563792d191..44d16d4e8428 100644 --- a/packages/engine/Source/Scene/Model/PickingPipelineStage.js +++ b/packages/engine/Source/Scene/Model/PickingPipelineStage.js @@ -2,7 +2,6 @@ import Buffer from "../../Renderer/Buffer.js"; import BufferUsage from "../../Renderer/BufferUsage.js"; import Color from "../../Core/Color.js"; import ComponentDatatype from "../../Core/ComponentDatatype.js"; -import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import ShaderDestination from "../../Renderer/ShaderDestination.js"; import ModelType from "./ModelType.js"; @@ -152,7 +151,7 @@ function processPickTexture(renderResources, primitive, instances) { const batchTexture = featureTable.batchTexture; renderResources.uniformMap.model_pickTexture = function () { - return defaultValue(batchTexture.pickTexture, batchTexture.defaultTexture); + return batchTexture.pickTexture ?? batchTexture.defaultTexture; }; // The feature ID is ignored if it is greater than the number of features. diff --git a/packages/engine/Source/Scene/Model/PntsLoader.js b/packages/engine/Source/Scene/Model/PntsLoader.js index fafb851851c4..b6f07a5f794b 100644 --- a/packages/engine/Source/Scene/Model/PntsLoader.js +++ b/packages/engine/Source/Scene/Model/PntsLoader.js @@ -48,10 +48,10 @@ const MetallicRoughness = ModelComponents.MetallicRoughness; * @param {boolean} [options.loadAttributesFor2D=false] If true, load the positions buffer as a typed array for accurately projecting models to 2D. */ function PntsLoader(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const arrayBuffer = options.arrayBuffer; - const byteOffset = defaultValue(options.byteOffset, 0); + const byteOffset = options.byteOffset ?? 0; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.arrayBuffer", arrayBuffer); @@ -59,7 +59,7 @@ function PntsLoader(options) { this._arrayBuffer = arrayBuffer; this._byteOffset = byteOffset; - this._loadAttributesFor2D = defaultValue(options.loadAttributesFor2D, false); + this._loadAttributesFor2D = options.loadAttributesFor2D ?? false; this._parsedContent = undefined; this._decodePromise = undefined; @@ -416,7 +416,7 @@ function makeAttribute(loader, attributeInfo, context) { attribute.setIndex = attributeInfo.setIndex; attribute.componentDatatype = attributeInfo.componentDatatype; attribute.type = attributeInfo.type; - attribute.normalized = defaultValue(attributeInfo.normalized, false); + attribute.normalized = attributeInfo.normalized ?? false; attribute.min = attributeInfo.min; attribute.max = attributeInfo.max; attribute.quantization = quantization; @@ -556,7 +556,7 @@ function makeStructuralMetadata(parsedContent, customAttributeOutput) { const parseAsPropertyAttributes = !defined(parsedContent.batchIds); if (defined(batchTableBinary) || parsedContent.hasDracoBatchTable) { - const count = defaultValue(batchLength, pointsLength); + const count = batchLength ?? pointsLength; return parseBatchTable({ count: count, batchTable: parsedContent.batchTableJson, diff --git a/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js b/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js index 967e07fcfe98..7a194115fb16 100644 --- a/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js +++ b/packages/engine/Source/Scene/Model/PointCloudStylingPipelineStage.js @@ -3,7 +3,6 @@ import Cartesian4 from "../../Core/Cartesian4.js"; import CesiumMath from "../../Core/Math.js"; import Cesium3DTileRefine from "../Cesium3DTileRefine.js"; import clone from "../../Core/clone.js"; -import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import Matrix4 from "../../Core/Matrix4.js"; import ModelType from "./ModelType.js"; @@ -162,10 +161,7 @@ PointCloudStylingPipelineStage.process = function ( ? 5.0 : content.tileset.memoryAdjustedScreenSpaceError; } - vec4.x = defaultValue( - pointCloudShading.maximumAttenuation, - defaultPointSize, - ); + vec4.x = pointCloudShading.maximumAttenuation ?? defaultPointSize; vec4.x *= frameState.pixelRatio; // Geometric error diff --git a/packages/engine/Source/Scene/Model/PrimitiveOutlineGenerator.js b/packages/engine/Source/Scene/Model/PrimitiveOutlineGenerator.js index d21e59662b7c..daa3d2aae367 100644 --- a/packages/engine/Source/Scene/Model/PrimitiveOutlineGenerator.js +++ b/packages/engine/Source/Scene/Model/PrimitiveOutlineGenerator.js @@ -65,7 +65,7 @@ const MAX_GLTF_UINT8_INDEX = 255; * @private */ function PrimitiveOutlineGenerator(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const triangleIndices = options.triangleIndices; const outlineIndices = options.outlineIndices; const originalVertexCount = options.originalVertexCount; diff --git a/packages/engine/Source/Scene/Model/SelectedFeatureIdPipelineStage.js b/packages/engine/Source/Scene/Model/SelectedFeatureIdPipelineStage.js index 6a95e14384c3..1ef33614782d 100644 --- a/packages/engine/Source/Scene/Model/SelectedFeatureIdPipelineStage.js +++ b/packages/engine/Source/Scene/Model/SelectedFeatureIdPipelineStage.js @@ -1,4 +1,3 @@ -import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import ShaderDestination from "../../Renderer/ShaderDestination.js"; import SelectedFeatureIdStageCommon from "../../Shaders/Model/SelectedFeatureIdStageCommon.js"; @@ -121,7 +120,7 @@ function getSelectedFeatureIds(model, node, primitive) { if (defined(featureIds)) { // Either label could be used here, but prefer label as it may be more // meaningful when debugging - variableName = defaultValue(featureIds.label, featureIds.positionalLabel); + variableName = featureIds.label ?? featureIds.positionalLabel; return { featureIds: featureIds, variableName: variableName, @@ -136,7 +135,7 @@ function getSelectedFeatureIds(model, node, primitive) { model.featureIdLabel, ); // again, prefer label for being more descriptive - variableName = defaultValue(featureIds.label, featureIds.positionalLabel); + variableName = featureIds.label ?? featureIds.positionalLabel; return { featureIds: featureIds, variableName: variableName, diff --git a/packages/engine/Source/Scene/Model/TextureUniform.js b/packages/engine/Source/Scene/Model/TextureUniform.js index a8b6db4b2483..83f8b0213fd0 100644 --- a/packages/engine/Source/Scene/Model/TextureUniform.js +++ b/packages/engine/Source/Scene/Model/TextureUniform.js @@ -29,7 +29,7 @@ import TextureWrap from "../../Renderer/TextureWrap.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function TextureUniform(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); const hasTypedArray = defined(options.typedArray); const hasUrl = defined(options.url); @@ -48,11 +48,8 @@ function TextureUniform(options) { this.typedArray = options.typedArray; this.width = options.width; this.height = options.height; - this.pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGBA); - this.pixelDatatype = defaultValue( - options.pixelDatatype, - PixelDatatype.UNSIGNED_BYTE, - ); + this.pixelFormat = options.pixelFormat ?? PixelFormat.RGBA; + this.pixelDatatype = options.pixelDatatype ?? PixelDatatype.UNSIGNED_BYTE; let resource = options.url; if (typeof resource === "string") { @@ -60,7 +57,7 @@ function TextureUniform(options) { } this.resource = resource; - const repeat = defaultValue(options.repeat, true); + const repeat = options.repeat ?? true; const wrap = repeat ? TextureWrap.REPEAT : TextureWrap.CLAMP_TO_EDGE; this.sampler = new Sampler({ wrapS: wrap, diff --git a/packages/engine/Source/Scene/Model/pickModel.js b/packages/engine/Source/Scene/Model/pickModel.js index 244ea0e3b45f..39c19d49c18c 100644 --- a/packages/engine/Source/Scene/Model/pickModel.js +++ b/packages/engine/Source/Scene/Model/pickModel.js @@ -4,7 +4,6 @@ import Cartesian3 from "../../Core/Cartesian3.js"; import Cartographic from "../../Core/Cartographic.js"; import Check from "../../Core/Check.js"; import ComponentDatatype from "../../Core/ComponentDatatype.js"; -import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import Ellipsoid from "../../Core/Ellipsoid.js"; import IndexDatatype from "../../Core/IndexDatatype.js"; @@ -280,9 +279,9 @@ export default function pickModel( return; } - ellipsoid = defaultValue(ellipsoid, Ellipsoid.default); - verticalExaggeration = defaultValue(verticalExaggeration, 1.0); - relativeHeight = defaultValue(relativeHeight, 0.0); + ellipsoid = ellipsoid ?? Ellipsoid.default; + verticalExaggeration = verticalExaggeration ?? 1.0; + relativeHeight = relativeHeight ?? 0.0; const indicesLength = indices.length; for (let i = 0; i < indicesLength; i += 3) { @@ -333,7 +332,7 @@ export default function pickModel( v0, v1, v2, - defaultValue(model.backFaceCulling, true), + model.backFaceCulling ?? true, ); if (defined(t)) { diff --git a/packages/engine/Source/Scene/Moon.js b/packages/engine/Source/Scene/Moon.js index 879eed33117a..14ec58f41c7b 100644 --- a/packages/engine/Source/Scene/Moon.js +++ b/packages/engine/Source/Scene/Moon.js @@ -30,7 +30,7 @@ import Material from "./Material.js"; * @see Scene#moon */ function Moon(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let url = options.textureUrl; if (!defined(url)) { @@ -43,7 +43,7 @@ function Moon(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * The moon texture. @@ -52,14 +52,14 @@ function Moon(options) { */ this.textureUrl = url; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.MOON); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.MOON; /** * Use the sun as the only light source. * @type {boolean} * @default true */ - this.onlySunLighting = defaultValue(options.onlySunLighting, true); + this.onlySunLighting = options.onlySunLighting ?? true; this._ellipsoidPrimitive = new EllipsoidPrimitive({ radii: this.ellipsoid.radii, diff --git a/packages/engine/Source/Scene/OpenStreetMapImageryProvider.js b/packages/engine/Source/Scene/OpenStreetMapImageryProvider.js index a170c06aebc5..d2e1a62d92f5 100644 --- a/packages/engine/Source/Scene/OpenStreetMapImageryProvider.js +++ b/packages/engine/Source/Scene/OpenStreetMapImageryProvider.js @@ -57,15 +57,15 @@ const defaultCredit = new Credit( * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing} */ function OpenStreetMapImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const resource = Resource.createIfNeeded( - defaultValue(options.url, "https://tile.openstreetmap.org/"), + options.url ?? "https://tile.openstreetmap.org/", ); resource.appendForwardSlash(); resource.url += `{z}/{x}/{y}${ options.retinaTiles ? "@2x" : "" - }.${defaultValue(options.fileExtension, "png")}`; + }.${options.fileExtension ?? "png"}`; const tilingScheme = new WebMercatorTilingScheme({ ellipsoid: options.ellipsoid, @@ -74,10 +74,10 @@ function OpenStreetMapImageryProvider(options) { const tileWidth = 256; const tileHeight = 256; - const minimumLevel = defaultValue(options.minimumLevel, 0); + const minimumLevel = options.minimumLevel ?? 0; const maximumLevel = options.maximumLevel; - const rectangle = defaultValue(options.rectangle, tilingScheme.rectangle); + const rectangle = options.rectangle ?? tilingScheme.rectangle; // Check the number of tiles at the minimum level. If it's more than four, // throw an exception, because starting at the higher minimum @@ -100,7 +100,7 @@ function OpenStreetMapImageryProvider(options) { } //>>includeEnd('debug'); - let credit = defaultValue(options.credit, defaultCredit); + let credit = options.credit ?? defaultCredit; if (typeof credit === "string") { credit = new Credit(credit); } diff --git a/packages/engine/Source/Scene/OrderedGroundPrimitiveCollection.js b/packages/engine/Source/Scene/OrderedGroundPrimitiveCollection.js index 74b5f9df50d8..3853530849b7 100644 --- a/packages/engine/Source/Scene/OrderedGroundPrimitiveCollection.js +++ b/packages/engine/Source/Scene/OrderedGroundPrimitiveCollection.js @@ -1,5 +1,4 @@ import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import PrimitiveCollection from "./PrimitiveCollection.js"; @@ -48,7 +47,7 @@ OrderedGroundPrimitiveCollection.prototype.add = function (primitive, zIndex) { } //>>includeEnd('debug'); - zIndex = defaultValue(zIndex, 0); + zIndex = zIndex ?? 0; let collection = this._collections[zIndex]; if (!defined(collection)) { collection = new PrimitiveCollection({ destroyPrimitives: false }); diff --git a/packages/engine/Source/Scene/Particle.js b/packages/engine/Source/Scene/Particle.js index 26f104eabaea..2773af8218b9 100644 --- a/packages/engine/Source/Scene/Particle.js +++ b/packages/engine/Source/Scene/Particle.js @@ -25,36 +25,32 @@ const defaultSize = new Cartesian2(1.0, 1.0); * @param {Cartesian2} [options.imageSize=new Cartesian2(1.0, 1.0)] The dimensions, width by height, to scale the particle image in pixels. */ function Particle(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The mass of the particle in kilograms. * @type {number} * @default 1.0 */ - this.mass = defaultValue(options.mass, 1.0); + this.mass = options.mass ?? 1.0; /** * The positon of the particle in world coordinates. * @type {Cartesian3} * @default Cartesian3.ZERO */ - this.position = Cartesian3.clone( - defaultValue(options.position, Cartesian3.ZERO), - ); + this.position = Cartesian3.clone(options.position ?? Cartesian3.ZERO); /** * The velocity of the particle in world coordinates. * @type {Cartesian3} * @default Cartesian3.ZERO */ - this.velocity = Cartesian3.clone( - defaultValue(options.velocity, Cartesian3.ZERO), - ); + this.velocity = Cartesian3.clone(options.velocity ?? Cartesian3.ZERO); /** * The life of the particle in seconds. * @type {number} * @default Number.MAX_VALUE */ - this.life = defaultValue(options.life, Number.MAX_VALUE); + this.life = options.life ?? Number.MAX_VALUE; /** * The image to use for the particle. * @type {object} @@ -66,33 +62,31 @@ function Particle(options) { * @type {Color} * @default Color.WHITE */ - this.startColor = Color.clone(defaultValue(options.startColor, Color.WHITE)); + this.startColor = Color.clone(options.startColor ?? Color.WHITE); /** * The color of the particle when it dies. * @type {Color} * @default Color.WHITE */ - this.endColor = Color.clone(defaultValue(options.endColor, Color.WHITE)); + this.endColor = Color.clone(options.endColor ?? Color.WHITE); /** * the scale of the particle when it is born. * @type {number} * @default 1.0 */ - this.startScale = defaultValue(options.startScale, 1.0); + this.startScale = options.startScale ?? 1.0; /** * The scale of the particle when it dies. * @type {number} * @default 1.0 */ - this.endScale = defaultValue(options.endScale, 1.0); + this.endScale = options.endScale ?? 1.0; /** * The dimensions, width by height, to scale the particle image in pixels. * @type {Cartesian2} * @default new Cartesian(1.0, 1.0) */ - this.imageSize = Cartesian2.clone( - defaultValue(options.imageSize, defaultSize), - ); + this.imageSize = Cartesian2.clone(options.imageSize ?? defaultSize); this._age = 0.0; this._normalizedAge = 0.0; diff --git a/packages/engine/Source/Scene/ParticleBurst.js b/packages/engine/Source/Scene/ParticleBurst.js index d1ef8b720c10..d1fd2b7d0e31 100644 --- a/packages/engine/Source/Scene/ParticleBurst.js +++ b/packages/engine/Source/Scene/ParticleBurst.js @@ -12,26 +12,26 @@ import defaultValue from "../Core/defaultValue.js"; * @param {number} [options.maximum=50.0] The maximum number of particles emitted in the burst. */ function ParticleBurst(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The time in seconds after the beginning of the particle system's lifetime that the burst will occur. * @type {number} * @default 0.0 */ - this.time = defaultValue(options.time, 0.0); + this.time = options.time ?? 0.0; /** * The minimum number of particles emitted. * @type {number} * @default 0.0 */ - this.minimum = defaultValue(options.minimum, 0.0); + this.minimum = options.minimum ?? 0.0; /** * The maximum number of particles emitted. * @type {number} * @default 50.0 */ - this.maximum = defaultValue(options.maximum, 50.0); + this.maximum = options.maximum ?? 50.0; this._complete = false; } diff --git a/packages/engine/Source/Scene/ParticleSystem.js b/packages/engine/Source/Scene/ParticleSystem.js index 032755713956..12e7561c6bd8 100644 --- a/packages/engine/Source/Scene/ParticleSystem.js +++ b/packages/engine/Source/Scene/ParticleSystem.js @@ -56,14 +56,14 @@ const defaultImageSize = new Cartesian2(1.0, 1.0); * @demo {@link https://sandcastle.cesium.com/?src=Particle%20System%20Fireworks.html&label=Showcases|Particle Systems Fireworks Demo} */ function ParticleSystem(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * Whether to display the particle system. * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * An array of force callbacks. The callback is passed a {@link Particle} and the difference from the last time @@ -77,14 +77,14 @@ function ParticleSystem(options) { * @type {boolean} * @default true */ - this.loop = defaultValue(options.loop, true); + this.loop = options.loop ?? true; /** * The URI, HTMLImageElement, or HTMLCanvasElement to use for the billboard. * @type {object} * @default undefined */ - this.image = defaultValue(options.image, undefined); + this.image = options.image ?? undefined; let emitter = options.emitter; if (!defined(emitter)) { @@ -94,76 +94,46 @@ function ParticleSystem(options) { this._bursts = options.bursts; - this._modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this._modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._emitterModelMatrix = Matrix4.clone( - defaultValue(options.emitterModelMatrix, Matrix4.IDENTITY), + options.emitterModelMatrix ?? Matrix4.IDENTITY, ); this._matrixDirty = true; this._combinedMatrix = new Matrix4(); this._startColor = Color.clone( - defaultValue(options.color, defaultValue(options.startColor, Color.WHITE)), + options.color ?? options.startColor ?? Color.WHITE, ); this._endColor = Color.clone( - defaultValue(options.color, defaultValue(options.endColor, Color.WHITE)), + options.color ?? options.endColor ?? Color.WHITE, ); - this._startScale = defaultValue( - options.scale, - defaultValue(options.startScale, 1.0), - ); - this._endScale = defaultValue( - options.scale, - defaultValue(options.endScale, 1.0), - ); + this._startScale = options.scale ?? options.startScale ?? 1.0; + this._endScale = options.scale ?? options.endScale ?? 1.0; - this._emissionRate = defaultValue(options.emissionRate, 5.0); + this._emissionRate = options.emissionRate ?? 5.0; - this._minimumSpeed = defaultValue( - options.speed, - defaultValue(options.minimumSpeed, 1.0), - ); - this._maximumSpeed = defaultValue( - options.speed, - defaultValue(options.maximumSpeed, 1.0), - ); + this._minimumSpeed = options.speed ?? options.minimumSpeed ?? 1.0; + this._maximumSpeed = options.speed ?? options.maximumSpeed ?? 1.0; - this._minimumParticleLife = defaultValue( - options.particleLife, - defaultValue(options.minimumParticleLife, 5.0), - ); - this._maximumParticleLife = defaultValue( - options.particleLife, - defaultValue(options.maximumParticleLife, 5.0), - ); + this._minimumParticleLife = + options.particleLife ?? options.minimumParticleLife ?? 5.0; + this._maximumParticleLife = + options.particleLife ?? options.maximumParticleLife ?? 5.0; - this._minimumMass = defaultValue( - options.mass, - defaultValue(options.minimumMass, 1.0), - ); - this._maximumMass = defaultValue( - options.mass, - defaultValue(options.maximumMass, 1.0), - ); + this._minimumMass = options.mass ?? options.minimumMass ?? 1.0; + this._maximumMass = options.mass ?? options.maximumMass ?? 1.0; this._minimumImageSize = Cartesian2.clone( - defaultValue( - options.imageSize, - defaultValue(options.minimumImageSize, defaultImageSize), - ), + options.imageSize ?? options.minimumImageSize ?? defaultImageSize, ); this._maximumImageSize = Cartesian2.clone( - defaultValue( - options.imageSize, - defaultValue(options.maximumImageSize, defaultImageSize), - ), + options.imageSize ?? options.maximumImageSize ?? defaultImageSize, ); - this._sizeInMeters = defaultValue(options.sizeInMeters, false); + this._sizeInMeters = options.sizeInMeters ?? false; - this._lifetime = defaultValue(options.lifetime, Number.MAX_VALUE); + this._lifetime = options.lifetime ?? Number.MAX_VALUE; this._billboardCollection = undefined; this._particles = []; diff --git a/packages/engine/Source/Scene/PerInstanceColorAppearance.js b/packages/engine/Source/Scene/PerInstanceColorAppearance.js index a896ddd43b12..144167b07299 100644 --- a/packages/engine/Source/Scene/PerInstanceColorAppearance.js +++ b/packages/engine/Source/Scene/PerInstanceColorAppearance.js @@ -68,11 +68,11 @@ import Appearance from "./Appearance.js"; * }); */ function PerInstanceColorAppearance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const translucent = defaultValue(options.translucent, true); - const closed = defaultValue(options.closed, false); - const flat = defaultValue(options.flat, false); + const translucent = options.translucent ?? true; + const closed = options.closed ?? false; + const flat = options.flat ?? false; const vs = flat ? PerInstanceFlatColorAppearanceVS : PerInstanceColorAppearanceVS; @@ -103,8 +103,8 @@ function PerInstanceColorAppearance(options) { */ this.translucent = translucent; - this._vertexShaderSource = defaultValue(options.vertexShaderSource, vs); - this._fragmentShaderSource = defaultValue(options.fragmentShaderSource, fs); + this._vertexShaderSource = options.vertexShaderSource ?? vs; + this._fragmentShaderSource = options.fragmentShaderSource ?? fs; this._renderState = Appearance.getDefaultRenderState( translucent, closed, @@ -116,7 +116,7 @@ function PerInstanceColorAppearance(options) { this._vertexFormat = vertexFormat; this._flat = flat; - this._faceForward = defaultValue(options.faceForward, !closed); + this._faceForward = options.faceForward ?? !closed; } Object.defineProperties(PerInstanceColorAppearance.prototype, { diff --git a/packages/engine/Source/Scene/PerformanceDisplay.js b/packages/engine/Source/Scene/PerformanceDisplay.js index d379843b32a1..833b72be1a6f 100644 --- a/packages/engine/Source/Scene/PerformanceDisplay.js +++ b/packages/engine/Source/Scene/PerformanceDisplay.js @@ -9,7 +9,7 @@ import getElement from "../DataSources/getElement.js"; * @private */ function PerformanceDisplay(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const container = getElement(options.container); //>>includeStart('debug', pragmas.debug); @@ -82,7 +82,7 @@ Object.defineProperties(PerformanceDisplay.prototype, { */ PerformanceDisplay.prototype.update = function (renderedThisFrame) { const time = getTimestamp(); - const updateDisplay = defaultValue(renderedThisFrame, true); + const updateDisplay = renderedThisFrame ?? true; this._fpsFrameCount++; const fpsElapsedTime = time - this._lastFpsSampleTime; diff --git a/packages/engine/Source/Scene/PickFramebuffer.js b/packages/engine/Source/Scene/PickFramebuffer.js index 69645bb7cc50..bb9cb777d5fd 100644 --- a/packages/engine/Source/Scene/PickFramebuffer.js +++ b/packages/engine/Source/Scene/PickFramebuffer.js @@ -1,6 +1,5 @@ import BoundingRectangle from "../Core/BoundingRectangle.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import FramebufferManager from "../Renderer/FramebufferManager.js"; @@ -58,8 +57,8 @@ const colorScratchForPickFramebuffer = new Color(); * @returns {object|undefined} The object rendered in the middle of the rectangle, or undefined if nothing was rendered. */ PickFramebuffer.prototype.end = function (screenSpaceRectangle) { - const width = defaultValue(screenSpaceRectangle.width, 1.0); - const height = defaultValue(screenSpaceRectangle.height, 1.0); + const width = screenSpaceRectangle.width ?? 1.0; + const height = screenSpaceRectangle.height ?? 1.0; const context = this._context; const pixels = context.readPixels({ @@ -140,8 +139,8 @@ PickFramebuffer.prototype.end = function (screenSpaceRectangle) { * @returns {Uint8Array} The RGBA components */ PickFramebuffer.prototype.readCenterPixel = function (screenSpaceRectangle) { - const width = defaultValue(screenSpaceRectangle.width, 1.0); - const height = defaultValue(screenSpaceRectangle.height, 1.0); + const width = screenSpaceRectangle.width ?? 1.0; + const height = screenSpaceRectangle.height ?? 1.0; const context = this._context; const pixels = context.readPixels({ diff --git a/packages/engine/Source/Scene/Picking.js b/packages/engine/Source/Scene/Picking.js index fc38a4a90955..d4e094972c27 100644 --- a/packages/engine/Source/Scene/Picking.js +++ b/packages/engine/Source/Scene/Picking.js @@ -5,7 +5,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; import Check from "../Core/Check.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Matrix4 from "../Core/Matrix4.js"; @@ -255,8 +254,8 @@ function computePickingDrawingBufferRectangle( height, result, ) { - result.width = defaultValue(width, 3.0); - result.height = defaultValue(height, result.width); + result.width = width ?? 3.0; + result.height = height ?? result.width; result.x = position.x - (result.width - 1.0) * 0.5; result.y = drawingBufferHeight - position.y - (result.height - 1.0) * 0.5; return result; @@ -846,7 +845,7 @@ function updateOffscreenCameraFromRay(picking, ray, width, camera) { camera.up = up; camera.right = right; - camera.frustum.width = defaultValue(width, offscreenDefaultWidth); + camera.frustum.width = width ?? offscreenDefaultWidth; return camera.frustum.computeCullingVolume( camera.positionWC, camera.directionWC, diff --git a/packages/engine/Source/Scene/PntsParser.js b/packages/engine/Source/Scene/PntsParser.js index e58c52317b33..b1b4c7c622d4 100644 --- a/packages/engine/Source/Scene/PntsParser.js +++ b/packages/engine/Source/Scene/PntsParser.js @@ -3,7 +3,6 @@ import Check from "../Core/Check.js"; import Color from "../Core/Color.js"; import combine from "../Core/combine.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import getJsonFromTypedArray from "../Core/getJsonFromTypedArray.js"; import RuntimeError from "../Core/RuntimeError.js"; @@ -31,7 +30,7 @@ const sizeOfUint32 = Uint32Array.BYTES_PER_ELEMENT; * @returns {object} An object containing a parsed representation of the point cloud */ PntsParser.parse = function (arrayBuffer, byteOffset) { - byteOffset = defaultValue(byteOffset, 0); + byteOffset = byteOffset ?? 0; //>>includeStart('debug', pragmas.debug); Check.defined("arrayBuffer", arrayBuffer); //>>includeEnd('debug'); diff --git a/packages/engine/Source/Scene/PointCloud.js b/packages/engine/Source/Scene/PointCloud.js index 6f41c9fc7330..6ddc01a64da6 100644 --- a/packages/engine/Source/Scene/PointCloud.js +++ b/packages/engine/Source/Scene/PointCloud.js @@ -6,7 +6,6 @@ import clone from "../Core/clone.js"; import Color from "../Core/Color.js"; import combine from "../Core/combine.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import CesiumMath from "../Core/Math.js"; @@ -114,8 +113,8 @@ function PointCloud(options) { this._uniformMapLoaded = options.uniformMapLoaded; this._batchTableLoaded = options.batchTableLoaded; this._pickIdLoaded = options.pickIdLoaded; - this._opaquePass = defaultValue(options.opaquePass, Pass.OPAQUE); - this._cull = defaultValue(options.cull, true); + this._opaquePass = options.opaquePass ?? Pass.OPAQUE; + this._cull = options.cull ?? true; this.style = undefined; this._style = undefined; @@ -150,10 +149,7 @@ function PointCloud(options) { * @type {SplitDirection} * @default {@link SplitDirection.NONE} */ - this.splitDirection = defaultValue( - options.splitDirection, - SplitDirection.NONE, - ); + this.splitDirection = options.splitDirection ?? SplitDirection.NONE; this._splittingEnabled = false; this._error = undefined; @@ -679,10 +675,8 @@ function createUniformMap(pointCloud, frameState) { return Matrix4.IDENTITY; } - const clippingPlanesOriginMatrix = defaultValue( - pointCloud.clippingPlanesOriginMatrix, - pointCloud._modelMatrix, - ); + const clippingPlanesOriginMatrix = + pointCloud.clippingPlanesOriginMatrix ?? pointCloud._modelMatrix; Matrix4.multiply( context.uniformState.view3D, clippingPlanesOriginMatrix, @@ -1243,7 +1237,7 @@ function decodeDraco(pointCloud, context) { }; } - const decodedColors = defaultValue(decodedRgba, decodedRgb); + const decodedColors = decodedRgba ?? decodedRgb; if (defined(decodedColors)) { parsedContent.colors = { typedArray: decodedColors, diff --git a/packages/engine/Source/Scene/PointCloudShading.js b/packages/engine/Source/Scene/PointCloudShading.js index 23a85575ee65..b161dbe0422a 100644 --- a/packages/engine/Source/Scene/PointCloudShading.js +++ b/packages/engine/Source/Scene/PointCloudShading.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import PointCloudEyeDomeLighting from "./PointCloudEyeDomeLighting.js"; /** @@ -20,24 +19,21 @@ import PointCloudEyeDomeLighting from "./PointCloudEyeDomeLighting.js"; * @constructor */ function PointCloudShading(options) { - const pointCloudShading = defaultValue(options, {}); + const pointCloudShading = options ?? {}; /** * Perform point attenuation based on geometric error. * @type {boolean} * @default false */ - this.attenuation = defaultValue(pointCloudShading.attenuation, false); + this.attenuation = pointCloudShading.attenuation ?? false; /** * Scale to be applied to the geometric error before computing attenuation. * @type {number} * @default 1.0 */ - this.geometricErrorScale = defaultValue( - pointCloudShading.geometricErrorScale, - 1.0, - ); + this.geometricErrorScale = pointCloudShading.geometricErrorScale ?? 1.0; /** * Maximum point attenuation in pixels. If undefined, the Cesium3DTileset's maximumScreenSpaceError will be used. @@ -61,27 +57,22 @@ function PointCloudShading(options) { * @type {boolean} * @default true */ - this.eyeDomeLighting = defaultValue(pointCloudShading.eyeDomeLighting, true); + this.eyeDomeLighting = pointCloudShading.eyeDomeLighting ?? true; /** * Eye dome lighting strength (apparent contrast) * @type {number} * @default 1.0 */ - this.eyeDomeLightingStrength = defaultValue( - pointCloudShading.eyeDomeLightingStrength, - 1.0, - ); + this.eyeDomeLightingStrength = + pointCloudShading.eyeDomeLightingStrength ?? 1.0; /** * Thickness of contours from eye dome lighting * @type {number} * @default 1.0 */ - this.eyeDomeLightingRadius = defaultValue( - pointCloudShading.eyeDomeLightingRadius, - 1.0, - ); + this.eyeDomeLightingRadius = pointCloudShading.eyeDomeLightingRadius ?? 1.0; /** * Determines whether back-facing points are hidden. @@ -90,7 +81,7 @@ function PointCloudShading(options) { * @type {boolean} * @default false */ - this.backFaceCulling = defaultValue(pointCloudShading.backFaceCulling, false); + this.backFaceCulling = pointCloudShading.backFaceCulling ?? false; /** * Determines whether a point cloud that contains normals is shaded by the scene's light source. @@ -98,7 +89,7 @@ function PointCloudShading(options) { * @type {boolean} * @default true */ - this.normalShading = defaultValue(pointCloudShading.normalShading, true); + this.normalShading = pointCloudShading.normalShading ?? true; } /** diff --git a/packages/engine/Source/Scene/PointPrimitive.js b/packages/engine/Source/Scene/PointPrimitive.js index db93554292cc..f576cd17de36 100644 --- a/packages/engine/Source/Scene/PointPrimitive.js +++ b/packages/engine/Source/Scene/PointPrimitive.js @@ -42,7 +42,7 @@ import SplitDirection from "./SplitDirection.js"; * @demo {@link https://sandcastle.cesium.com/index.html?src=Points.html|Cesium Sandcastle Points Demo} */ function PointPrimitive(options, pointPrimitiveCollection) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if ( @@ -91,26 +91,19 @@ function PointPrimitive(options, pointPrimitiveCollection) { ); } - this._show = defaultValue(options.show, true); - this._position = Cartesian3.clone( - defaultValue(options.position, Cartesian3.ZERO), - ); + this._show = options.show ?? true; + this._position = Cartesian3.clone(options.position ?? Cartesian3.ZERO); this._actualPosition = Cartesian3.clone(this._position); // For columbus view and 2D - this._color = Color.clone(defaultValue(options.color, Color.WHITE)); - this._outlineColor = Color.clone( - defaultValue(options.outlineColor, Color.TRANSPARENT), - ); - this._outlineWidth = defaultValue(options.outlineWidth, 0.0); - this._pixelSize = defaultValue(options.pixelSize, 10.0); + this._color = Color.clone(options.color ?? Color.WHITE); + this._outlineColor = Color.clone(options.outlineColor ?? Color.TRANSPARENT); + this._outlineWidth = options.outlineWidth ?? 0.0; + this._pixelSize = options.pixelSize ?? 10.0; this._scaleByDistance = scaleByDistance; this._translucencyByDistance = translucencyByDistance; this._distanceDisplayCondition = distanceDisplayCondition; - this._disableDepthTestDistance = defaultValue( - options.disableDepthTestDistance, - 0.0, - ); + this._disableDepthTestDistance = options.disableDepthTestDistance ?? 0.0; this._id = options.id; - this._collection = defaultValue(options.collection, pointPrimitiveCollection); + this._collection = options.collection ?? pointPrimitiveCollection; this._clusterShow = true; @@ -119,10 +112,7 @@ function PointPrimitive(options, pointPrimitiveCollection) { this._dirty = false; this._index = -1; //Used only by PointPrimitiveCollection - this._splitDirection = defaultValue( - options.splitDirection, - SplitDirection.NONE, - ); + this._splitDirection = options.splitDirection ?? SplitDirection.NONE; } const SHOW_INDEX = (PointPrimitive.SHOW_INDEX = 0); diff --git a/packages/engine/Source/Scene/PointPrimitiveCollection.js b/packages/engine/Source/Scene/PointPrimitiveCollection.js index c49029fcc16a..340e6bb17552 100644 --- a/packages/engine/Source/Scene/PointPrimitiveCollection.js +++ b/packages/engine/Source/Scene/PointPrimitiveCollection.js @@ -91,7 +91,7 @@ const attributeLocations = { * @see PointPrimitive */ function PointPrimitiveCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._sp = undefined; this._spTranslucent = undefined; @@ -135,7 +135,7 @@ function PointPrimitiveCollection(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * The 4x4 transformation matrix that transforms each point in this collection from model to world coordinates. @@ -169,9 +169,7 @@ function PointPrimitiveCollection(options) { * * @see Transforms.eastNorthUpToFixedFrame */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY); /** @@ -184,10 +182,7 @@ function PointPrimitiveCollection(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * The point blending option. The default is used for rendering both opaque and translucent points. @@ -197,10 +192,7 @@ function PointPrimitiveCollection(options) { * @type {BlendOption} * @default BlendOption.OPAQUE_AND_TRANSLUCENT */ - this.blendOption = defaultValue( - options.blendOption, - BlendOption.OPAQUE_AND_TRANSLUCENT, - ); + this.blendOption = options.blendOption ?? BlendOption.OPAQUE_AND_TRANSLUCENT; this._blendOption = undefined; this._mode = SceneMode.SCENE3D; diff --git a/packages/engine/Source/Scene/Polyline.js b/packages/engine/Source/Scene/Polyline.js index 3a070db7fc0d..455a9b415665 100644 --- a/packages/engine/Source/Scene/Polyline.js +++ b/packages/engine/Source/Scene/Polyline.js @@ -35,11 +35,11 @@ import Material from "./Material.js"; * */ function Polyline(options, polylineCollection) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - this._show = defaultValue(options.show, true); - this._width = defaultValue(options.width, 1.0); - this._loop = defaultValue(options.loop, false); + this._show = options.show ?? true; + this._width = options.width ?? 1.0; + this._loop = options.loop ?? false; this._distanceDisplayCondition = options.distanceDisplayCondition; this._material = options.material; diff --git a/packages/engine/Source/Scene/PolylineCollection.js b/packages/engine/Source/Scene/PolylineCollection.js index 5805ac5a9f02..880b1b591b08 100644 --- a/packages/engine/Source/Scene/PolylineCollection.js +++ b/packages/engine/Source/Scene/PolylineCollection.js @@ -115,7 +115,7 @@ const attributeLocations = { * }); */ function PolylineCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * Determines if polylines in this collection will be shown. @@ -123,7 +123,7 @@ function PolylineCollection(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * The 4x4 transformation matrix that transforms each polyline in this collection from model to world coordinates. @@ -134,9 +134,7 @@ function PolylineCollection(options) { * @type {Matrix4} * @default {@link Matrix4.IDENTITY} */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._modelMatrix = Matrix4.clone(Matrix4.IDENTITY); /** @@ -149,10 +147,7 @@ function PolylineCollection(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; this._opaqueRS = undefined; this._translucentRS = undefined; diff --git a/packages/engine/Source/Scene/PolylineColorAppearance.js b/packages/engine/Source/Scene/PolylineColorAppearance.js index 1bb49df68936..7d2e69b5598f 100644 --- a/packages/engine/Source/Scene/PolylineColorAppearance.js +++ b/packages/engine/Source/Scene/PolylineColorAppearance.js @@ -50,9 +50,9 @@ if (!FeatureDetection.isInternetExplorer()) { * }); */ function PolylineColorAppearance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const translucent = defaultValue(options.translucent, true); + const translucent = options.translucent ?? true; const closed = false; const vertexFormat = PolylineColorAppearance.VERTEX_FORMAT; @@ -76,14 +76,10 @@ function PolylineColorAppearance(options) { */ this.translucent = translucent; - this._vertexShaderSource = defaultValue( - options.vertexShaderSource, - defaultVertexShaderSource, - ); - this._fragmentShaderSource = defaultValue( - options.fragmentShaderSource, - defaultFragmentShaderSource, - ); + this._vertexShaderSource = + options.vertexShaderSource ?? defaultVertexShaderSource; + this._fragmentShaderSource = + options.fragmentShaderSource ?? defaultFragmentShaderSource; this._renderState = Appearance.getDefaultRenderState( translucent, closed, diff --git a/packages/engine/Source/Scene/PolylineMaterialAppearance.js b/packages/engine/Source/Scene/PolylineMaterialAppearance.js index d47e73d2bb6c..0100227a753e 100644 --- a/packages/engine/Source/Scene/PolylineMaterialAppearance.js +++ b/packages/engine/Source/Scene/PolylineMaterialAppearance.js @@ -48,9 +48,9 @@ if (!FeatureDetection.isInternetExplorer()) { * }); */ function PolylineMaterialAppearance(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const translucent = defaultValue(options.translucent, true); + const translucent = options.translucent ?? true; const closed = false; const vertexFormat = PolylineMaterialAppearance.VERTEX_FORMAT; @@ -78,14 +78,10 @@ function PolylineMaterialAppearance(options) { */ this.translucent = translucent; - this._vertexShaderSource = defaultValue( - options.vertexShaderSource, - defaultVertexShaderSource, - ); - this._fragmentShaderSource = defaultValue( - options.fragmentShaderSource, - defaultFragmentShaderSource, - ); + this._vertexShaderSource = + options.vertexShaderSource ?? defaultVertexShaderSource; + this._fragmentShaderSource = + options.fragmentShaderSource ?? defaultFragmentShaderSource; this._renderState = Appearance.getDefaultRenderState( translucent, closed, diff --git a/packages/engine/Source/Scene/PostProcessStage.js b/packages/engine/Source/Scene/PostProcessStage.js index 44012ca77b56..3b2c0a1aa78b 100644 --- a/packages/engine/Source/Scene/PostProcessStage.js +++ b/packages/engine/Source/Scene/PostProcessStage.js @@ -92,7 +92,7 @@ import PostProcessStageSampleMode from "./PostProcessStageSampleMode.js"; * stage.selected = [cesium3DTileFeature]; */ function PostProcessStage(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { fragmentShader, textureScale = 1.0, @@ -115,17 +115,11 @@ function PostProcessStage(options) { this._fragmentShader = fragmentShader; this._uniforms = options.uniforms; this._textureScale = textureScale; - this._forcePowerOfTwo = defaultValue(options.forcePowerOfTwo, false); - this._sampleMode = defaultValue( - options.sampleMode, - PostProcessStageSampleMode.NEAREST, - ); + this._forcePowerOfTwo = options.forcePowerOfTwo ?? false; + this._sampleMode = options.sampleMode ?? PostProcessStageSampleMode.NEAREST; this._pixelFormat = pixelFormat; - this._pixelDatatype = defaultValue( - options.pixelDatatype, - PixelDatatype.UNSIGNED_BYTE, - ); - this._clearColor = defaultValue(options.clearColor, Color.BLACK); + this._pixelDatatype = options.pixelDatatype ?? PixelDatatype.UNSIGNED_BYTE; + this._clearColor = options.clearColor ?? Color.BLACK; this._uniformMap = undefined; this._command = undefined; diff --git a/packages/engine/Source/Scene/PostProcessStageComposite.js b/packages/engine/Source/Scene/PostProcessStageComposite.js index 6745ac7546d5..692db81dc4eb 100644 --- a/packages/engine/Source/Scene/PostProcessStageComposite.js +++ b/packages/engine/Source/Scene/PostProcessStageComposite.js @@ -74,7 +74,7 @@ import destroyObject from "../Core/destroyObject.js"; * })); */ function PostProcessStageComposite(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.defined("options.stages", options.stages); @@ -86,10 +86,7 @@ function PostProcessStageComposite(options) { //>>includeEnd('debug'); this._stages = options.stages; - this._inputPreviousStageTexture = defaultValue( - options.inputPreviousStageTexture, - true, - ); + this._inputPreviousStageTexture = options.inputPreviousStageTexture ?? true; let name = options.name; if (!defined(name)) { diff --git a/packages/engine/Source/Scene/Primitive.js b/packages/engine/Source/Scene/Primitive.js index 5b9f38b70526..1a6f0dc66300 100644 --- a/packages/engine/Source/Scene/Primitive.js +++ b/packages/engine/Source/Scene/Primitive.js @@ -152,7 +152,7 @@ import ShadowMode from "./ShadowMode.js"; * @see GroundPrimitive */ function Primitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The geometry instances rendered with this primitive. This may @@ -224,9 +224,7 @@ function Primitive(options) { * const origin = Cesium.Cartesian3.fromDegrees(-95.0, 40.0, 200000.0); * p.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(origin); */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); this._modelMatrix = new Matrix4(); /** @@ -237,17 +235,14 @@ function Primitive(options) { * * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; - this._vertexCacheOptimize = defaultValue(options.vertexCacheOptimize, false); - this._interleave = defaultValue(options.interleave, false); - this._releaseGeometryInstances = defaultValue( - options.releaseGeometryInstances, - true, - ); - this._allowPicking = defaultValue(options.allowPicking, true); - this._asynchronous = defaultValue(options.asynchronous, true); - this._compressVertices = defaultValue(options.compressVertices, true); + this._vertexCacheOptimize = options.vertexCacheOptimize ?? false; + this._interleave = options.interleave ?? false; + this._releaseGeometryInstances = options.releaseGeometryInstances ?? true; + this._allowPicking = options.allowPicking ?? true; + this._asynchronous = options.asynchronous ?? true; + this._compressVertices = options.compressVertices ?? true; /** * When true, the renderer frustum culls and horizon culls the primitive's commands @@ -258,7 +253,7 @@ function Primitive(options) { * * @default true */ - this.cull = defaultValue(options.cull, true); + this.cull = options.cull ?? true; /** * This property is for debugging only; it is not for production use nor is it optimized. @@ -270,10 +265,7 @@ function Primitive(options) { * * @default false */ - this.debugShowBoundingVolume = defaultValue( - options.debugShowBoundingVolume, - false, - ); + this.debugShowBoundingVolume = options.debugShowBoundingVolume ?? false; /** * @private @@ -300,7 +292,7 @@ function Primitive(options) { * * @default ShadowMode.DISABLED */ - this.shadows = defaultValue(options.shadows, ShadowMode.DISABLED); + this.shadows = options.shadows ?? ShadowMode.DISABLED; this._translucent = undefined; @@ -648,7 +640,7 @@ function createBatchTable(primitive, context) { } const pickObject = { - primitive: defaultValue(instance.pickPrimitive, primitive), + primitive: instance.pickPrimitive ?? primitive, }; if (defined(instance.id)) { @@ -1211,10 +1203,8 @@ function loadAsynchronous(primitive, frameState) { geometry = subTask.geometry; if (defined(geometry.constructor.pack)) { subTask.offset = packedLength; - packedLength += defaultValue( - geometry.constructor.packedLength, - geometry.packedLength, - ); + packedLength += + geometry.constructor.packedLength ?? geometry.packedLength; } } @@ -2201,26 +2191,17 @@ Primitive.prototype.update = function (frameState) { const twoPasses = appearance.closed && translucent; if (createRS) { - const rsFunc = defaultValue( - this._createRenderStatesFunction, - createRenderStates, - ); + const rsFunc = this._createRenderStatesFunction ?? createRenderStates; rsFunc(this, context, appearance, twoPasses); } if (createSP) { - const spFunc = defaultValue( - this._createShaderProgramFunction, - createShaderProgram, - ); + const spFunc = this._createShaderProgramFunction ?? createShaderProgram; spFunc(this, frameState, appearance); } if (createRS || createSP) { - const commandFunc = defaultValue( - this._createCommandsFunction, - createCommands, - ); + const commandFunc = this._createCommandsFunction ?? createCommands; commandFunc( this, appearance, @@ -2233,10 +2214,8 @@ Primitive.prototype.update = function (frameState) { ); } - const updateAndQueueCommandsFunc = defaultValue( - this._updateAndQueueCommandsFunction, - updateAndQueueCommands, - ); + const updateAndQueueCommandsFunc = + this._updateAndQueueCommandsFunction ?? updateAndQueueCommands; updateAndQueueCommandsFunc( this, frameState, diff --git a/packages/engine/Source/Scene/PrimitiveCollection.js b/packages/engine/Source/Scene/PrimitiveCollection.js index 4dc20383fc36..425f4f5616aa 100644 --- a/packages/engine/Source/Scene/PrimitiveCollection.js +++ b/packages/engine/Source/Scene/PrimitiveCollection.js @@ -28,7 +28,7 @@ import Event from "../Core/Event.js"; * scene.primitives.add(labels); // Add regular primitive */ function PrimitiveCollection(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._primitives = []; this._guid = createGuid(); @@ -44,7 +44,7 @@ function PrimitiveCollection(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * Determines if primitives in the collection are destroyed when they are removed by @@ -70,7 +70,7 @@ function PrimitiveCollection(options) { * const b = labels.isDestroyed(); // false * labels = labels.destroy(); // explicitly destroy */ - this.destroyPrimitives = defaultValue(options.destroyPrimitives, true); + this.destroyPrimitives = options.destroyPrimitives ?? true; } Object.defineProperties(PrimitiveCollection.prototype, { diff --git a/packages/engine/Source/Scene/PrimitivePipeline.js b/packages/engine/Source/Scene/PrimitivePipeline.js index f90dd5058a95..a2cf185a9a80 100644 --- a/packages/engine/Source/Scene/PrimitivePipeline.js +++ b/packages/engine/Source/Scene/PrimitivePipeline.js @@ -1,6 +1,5 @@ import BoundingSphere from "../Core/BoundingSphere.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Ellipsoid from "../Core/Ellipsoid.js"; @@ -472,7 +471,7 @@ PrimitivePipeline.packCreateGeometryResults = function ( packedData[count++] = geometry.primitiveType; packedData[count++] = geometry.geometryType; - packedData[count++] = defaultValue(geometry.offsetAttribute, -1); + packedData[count++] = geometry.offsetAttribute ?? -1; const validBoundingSphere = defined(geometry.boundingSphere) ? 1.0 : 0.0; packedData[count++] = validBoundingSphere; diff --git a/packages/engine/Source/Scene/PropertyAttribute.js b/packages/engine/Source/Scene/PropertyAttribute.js index e3da8c952ed5..da4a63f87a13 100644 --- a/packages/engine/Source/Scene/PropertyAttribute.js +++ b/packages/engine/Source/Scene/PropertyAttribute.js @@ -23,7 +23,7 @@ import PropertyAttributeProperty from "./PropertyAttributeProperty.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function PropertyAttribute(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const propertyAttribute = options.propertyAttribute; const classDefinition = options.class; diff --git a/packages/engine/Source/Scene/PropertyAttributeProperty.js b/packages/engine/Source/Scene/PropertyAttributeProperty.js index 607fb8611470..79a2b8eb98af 100644 --- a/packages/engine/Source/Scene/PropertyAttributeProperty.js +++ b/packages/engine/Source/Scene/PropertyAttributeProperty.js @@ -20,7 +20,7 @@ import defined from "../Core/defined.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function PropertyAttributeProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const property = options.property; const classProperty = options.classProperty; @@ -45,8 +45,8 @@ function PropertyAttributeProperty(options) { // the class property. The class property handles setting the default of // identity: (offset 0, scale 1) with the same scalar/vector/matrix types. // array types are disallowed by the spec. - offset = defaultValue(offset, classProperty.offset); - scale = defaultValue(scale, classProperty.scale); + offset = offset ?? classProperty.offset; + scale = scale ?? classProperty.scale; // offset and scale are applied on the GPU, so unpack the values // as math types we can use in uniform callbacks. diff --git a/packages/engine/Source/Scene/PropertyTable.js b/packages/engine/Source/Scene/PropertyTable.js index cbb73b3cfd9b..7ee3b05c1ebc 100644 --- a/packages/engine/Source/Scene/PropertyTable.js +++ b/packages/engine/Source/Scene/PropertyTable.js @@ -38,7 +38,7 @@ import JsonMetadataTable from "./JsonMetadataTable.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function PropertyTable(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.number("options.count", options.count); diff --git a/packages/engine/Source/Scene/PropertyTexture.js b/packages/engine/Source/Scene/PropertyTexture.js index 4937827330ac..4d93e7019acf 100644 --- a/packages/engine/Source/Scene/PropertyTexture.js +++ b/packages/engine/Source/Scene/PropertyTexture.js @@ -24,7 +24,7 @@ import PropertyTextureProperty from "./PropertyTextureProperty.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function PropertyTexture(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const propertyTexture = options.propertyTexture; const classDefinition = options.class; const textures = options.textures; diff --git a/packages/engine/Source/Scene/PropertyTextureProperty.js b/packages/engine/Source/Scene/PropertyTextureProperty.js index 765c2507313e..88f6e31844c8 100644 --- a/packages/engine/Source/Scene/PropertyTextureProperty.js +++ b/packages/engine/Source/Scene/PropertyTextureProperty.js @@ -26,7 +26,7 @@ import oneTimeWarning from "../Core/oneTimeWarning.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function PropertyTextureProperty(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const property = options.property; const classProperty = options.classProperty; const textures = options.textures; @@ -60,8 +60,8 @@ function PropertyTextureProperty(options) { // the class property. The class property handles setting the default of // identity: (offset 0, scale 1) with the same scalar/vector/matrix types. // array types are disallowed by the spec. - offset = defaultValue(offset, classProperty.offset); - scale = defaultValue(scale, classProperty.scale); + offset = offset ?? classProperty.offset; + scale = scale ?? classProperty.scale; // offset and scale are applied on the GPU, so unpack the values // as math types we can use in uniform callbacks. diff --git a/packages/engine/Source/Scene/QuadtreePrimitive.js b/packages/engine/Source/Scene/QuadtreePrimitive.js index 545b7ecde978..6d45260d8d2e 100644 --- a/packages/engine/Source/Scene/QuadtreePrimitive.js +++ b/packages/engine/Source/Scene/QuadtreePrimitive.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import DeveloperError from "../Core/DeveloperError.js"; import Event from "../Core/Event.js"; @@ -108,10 +107,7 @@ function QuadtreePrimitive(options) { * @type {number} * @default 2 */ - this.maximumScreenSpaceError = defaultValue( - options.maximumScreenSpaceError, - 2, - ); + this.maximumScreenSpaceError = options.maximumScreenSpaceError ?? 2; /** * Gets or sets the maximum number of tiles that will be retained in the tile cache. @@ -121,7 +117,7 @@ function QuadtreePrimitive(options) { * @type {number} * @default 100 */ - this.tileCacheSize = defaultValue(options.tileCacheSize, 100); + this.tileCacheSize = options.tileCacheSize ?? 100; /** * Gets or sets the number of loading descendant tiles that is considered "too many". diff --git a/packages/engine/Source/Scene/ResourceCache.js b/packages/engine/Source/Scene/ResourceCache.js index 8d6c2a6afab6..9f2d5c8d1052 100644 --- a/packages/engine/Source/Scene/ResourceCache.js +++ b/packages/engine/Source/Scene/ResourceCache.js @@ -145,7 +145,7 @@ ResourceCache.unload = function (resourceLoader) { * @private */ ResourceCache.getSchemaLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { schema, resource } = options; //>>includeStart('debug', pragmas.debug); @@ -187,7 +187,7 @@ ResourceCache.getSchemaLoader = function (options) { * @private */ ResourceCache.getEmbeddedBufferLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { parentResource, bufferId, typedArray } = options; //>>includeStart('debug', pragmas.debug); @@ -227,7 +227,7 @@ ResourceCache.getEmbeddedBufferLoader = function (options) { * @private */ ResourceCache.getExternalBufferLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { resource } = options; //>>includeStart('debug', pragmas.debug); @@ -264,7 +264,7 @@ ResourceCache.getExternalBufferLoader = function (options) { * @private */ ResourceCache.getGltfJsonLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltfResource, baseResource, typedArray, gltfJson } = options; //>>includeStart('debug', pragmas.debug); @@ -306,7 +306,7 @@ ResourceCache.getGltfJsonLoader = function (options) { * @private */ ResourceCache.getBufferViewLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, bufferViewId, gltfResource, baseResource } = options; //>>includeStart('debug', pragmas.debug); @@ -353,7 +353,7 @@ ResourceCache.getBufferViewLoader = function (options) { * @private */ ResourceCache.getDracoLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, draco, gltfResource, baseResource } = options; //>>includeStart('debug', pragmas.debug); @@ -411,7 +411,7 @@ ResourceCache.getDracoLoader = function (options) { * @private */ ResourceCache.getVertexBufferLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, gltfResource, @@ -530,7 +530,7 @@ function hasDracoCompression(draco, semantic) { * @private */ ResourceCache.getIndexBufferLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, accessorId, @@ -601,7 +601,7 @@ ResourceCache.getIndexBufferLoader = function (options) { * @private */ ResourceCache.getImageLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, imageId, gltfResource, baseResource } = options; //>>includeStart('debug', pragmas.debug); @@ -651,7 +651,7 @@ ResourceCache.getImageLoader = function (options) { * @private */ ResourceCache.getTextureLoader = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, textureInfo, diff --git a/packages/engine/Source/Scene/ResourceCacheKey.js b/packages/engine/Source/Scene/ResourceCacheKey.js index 085a2d3d0b70..f15cc27fd30b 100644 --- a/packages/engine/Source/Scene/ResourceCacheKey.js +++ b/packages/engine/Source/Scene/ResourceCacheKey.js @@ -24,7 +24,7 @@ function getBufferViewCacheKey(bufferView) { if (hasExtension(bufferView, "EXT_meshopt_compression")) { const meshopt = bufferView.extensions.EXT_meshopt_compression; - byteOffset = defaultValue(meshopt.byteOffset, 0); + byteOffset = meshopt.byteOffset ?? 0; byteLength = meshopt.byteLength; } @@ -148,7 +148,7 @@ ResourceCacheKey.getSchemaCacheKey = function (options) { * @private */ ResourceCacheKey.getExternalBufferCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { resource } = options; //>>includeStart('debug', pragmas.debug); @@ -169,7 +169,7 @@ ResourceCacheKey.getExternalBufferCacheKey = function (options) { * @private */ ResourceCacheKey.getEmbeddedBufferCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { parentResource, bufferId } = options; //>>includeStart('debug', pragmas.debug); @@ -193,7 +193,7 @@ ResourceCacheKey.getEmbeddedBufferCacheKey = function (options) { * @private */ ResourceCacheKey.getGltfCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltfResource } = options; //>>includeStart('debug', pragmas.debug); @@ -216,7 +216,7 @@ ResourceCacheKey.getGltfCacheKey = function (options) { * @private */ ResourceCacheKey.getBufferViewCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, bufferViewId, gltfResource, baseResource } = options; //>>includeStart('debug', pragmas.debug); @@ -259,7 +259,7 @@ ResourceCacheKey.getBufferViewCacheKey = function (options) { * @private */ ResourceCacheKey.getDracoCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, draco, gltfResource, baseResource } = options; //>>includeStart('debug', pragmas.debug); @@ -293,7 +293,7 @@ ResourceCacheKey.getDracoCacheKey = function (options) { * @private */ ResourceCacheKey.getVertexBufferCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, gltfResource, @@ -406,7 +406,7 @@ function hasDracoCompression(draco, semantic) { * @private */ ResourceCacheKey.getIndexBufferCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, accessorId, @@ -483,7 +483,7 @@ ResourceCacheKey.getIndexBufferCacheKey = function (options) { * @private */ ResourceCacheKey.getImageCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, imageId, gltfResource, baseResource } = options; //>>includeStart('debug', pragmas.debug); @@ -518,7 +518,7 @@ ResourceCacheKey.getImageCacheKey = function (options) { * @private */ ResourceCacheKey.getTextureCacheKey = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const { gltf, textureInfo, diff --git a/packages/engine/Source/Scene/Scene.js b/packages/engine/Source/Scene/Scene.js index e751dda94087..4df878622996 100644 --- a/packages/engine/Source/Scene/Scene.js +++ b/packages/engine/Source/Scene/Scene.js @@ -126,7 +126,7 @@ const requestRenderAfterFrame = function (scene) { * }); */ function Scene(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const canvas = options.canvas; let creditContainer = options.creditContainer; let creditViewport = options.creditViewport; @@ -161,7 +161,7 @@ function Scene(options) { new CreditDisplay(creditContainer, "•", creditViewport), this._jobScheduler, ); - this._frameState.scene3DOnly = defaultValue(options.scene3DOnly, false); + this._frameState.scene3DOnly = options.scene3DOnly ?? false; this._removeCreditContainer = !hasCreditContainer; this._creditContainer = creditContainer; @@ -169,7 +169,7 @@ function Scene(options) { this._context = context; this._computeEngine = new ComputeEngine(context); - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.default; this._globe = undefined; this._globeTranslucencyState = new GlobeTranslucencyState(); this._primitives = new PrimitiveCollection(); @@ -192,7 +192,7 @@ function Scene(options) { this._computeCommandList = []; this._overlayCommandList = []; - this._useOIT = defaultValue(options.orderIndependentTranslucency, true); + this._useOIT = options.orderIndependentTranslucency ?? true; /** * The function that will be used for executing translucent commands when * useOIT is true. This is created once in @@ -236,7 +236,7 @@ function Scene(options) { this._minimumDisableDepthTestDistance = 0.0; this._debugInspector = new DebugInspector(); - this._msaaSamples = defaultValue(options.msaaSamples, 4); + this._msaaSamples = options.msaaSamples ?? 4; /** * Exceptions occurring in render are always caught in order to raise the @@ -568,7 +568,7 @@ function Scene(options) { this.shadowMap = new ShadowMap({ context: context, lightCamera: this._shadowMapCamera, - enabled: defaultValue(options.shadows, false), + enabled: options.shadows ?? false, }); /** @@ -618,7 +618,7 @@ function Scene(options) { this._screenSpaceCameraController = new ScreenSpaceCameraController(this); this._cameraUnderground = false; - this._mapMode2D = defaultValue(options.mapMode2D, MapMode2D.INFINITE_SCROLL); + this._mapMode2D = options.mapMode2D ?? MapMode2D.INFINITE_SCROLL; // Keeps track of the state of a frame. FrameState is the state across // the primitives of the scene. This state is for internally keeping track @@ -666,7 +666,7 @@ function Scene(options) { * @type {boolean} * @default false */ - this.requestRenderMode = defaultValue(options.requestRenderMode, false); + this.requestRenderMode = options.requestRenderMode ?? false; this._renderRequested = true; /** @@ -683,10 +683,7 @@ function Scene(options) { * @type {number} * @default 0.0 */ - this.maximumRenderTimeChange = defaultValue( - options.maximumRenderTimeChange, - 0.0, - ); + this.maximumRenderTimeChange = options.maximumRenderTimeChange ?? 0.0; this._lastRenderTime = undefined; this._frameRateMonitor = undefined; @@ -3104,8 +3101,8 @@ function executeWebVRCommands(scene, passState) { savedCamera.frustum = camera.frustum; const near = camera.frustum.near; - const fo = near * defaultValue(scene.focalLength, 5.0); - const eyeSeparation = defaultValue(scene.eyeSeparation, fo / 30.0); + const fo = near * (scene.focalLength ?? 5.0); + const eyeSeparation = scene.eyeSeparation ?? fo / 30.0; const eyeTranslation = Cartesian3.multiplyByScalar( savedCamera.right, eyeSeparation * 0.5, @@ -3768,9 +3765,8 @@ Scene.prototype.resolveFramebuffers = function (passState) { const postProcess = this.postProcessStages; const colorTexture = inputFramebuffer.getColorTexture(0); const idTexture = idFramebuffer.getColorTexture(0); - const depthTexture = defaultValue( - globeFramebuffer, - sceneFramebuffer, + const depthTexture = ( + globeFramebuffer ?? sceneFramebuffer ).getDepthStencilTexture(); postProcess.execute(context, colorTexture, depthTexture, idTexture); postProcess.copy(context, originalFramebuffer); @@ -4101,7 +4097,7 @@ function render(scene) { frameState.passes.postProcess = scene.postProcessStages.hasSelected; frameState.tilesetPassState = renderTilesetPassState; - let backgroundColor = defaultValue(scene.backgroundColor, Color.BLACK); + let backgroundColor = scene.backgroundColor ?? Color.BLACK; if (scene._hdr) { backgroundColor = Color.clone(backgroundColor, scratchBackgroundColor); backgroundColor.red = Math.pow(backgroundColor.red, scene.gamma); @@ -4880,7 +4876,7 @@ Scene.prototype.completeMorph = function () { * @param {number} [duration=2.0] The amount of time, in seconds, for transition animations to complete. */ Scene.prototype.morphTo2D = function (duration) { - duration = defaultValue(duration, 2.0); + duration = duration ?? 2.0; this._transitioner.morphTo2D(duration, this._ellipsoid); }; @@ -4889,7 +4885,7 @@ Scene.prototype.morphTo2D = function (duration) { * @param {number} [duration=2.0] The amount of time, in seconds, for transition animations to complete. */ Scene.prototype.morphToColumbusView = function (duration) { - duration = defaultValue(duration, 2.0); + duration = duration ?? 2.0; this._transitioner.morphToColumbusView(duration, this._ellipsoid); }; @@ -4898,7 +4894,7 @@ Scene.prototype.morphToColumbusView = function (duration) { * @param {number} [duration=2.0] The amount of time, in seconds, for transition animations to complete. */ Scene.prototype.morphTo3D = function (duration) { - duration = defaultValue(duration, 2.0); + duration = duration ?? 2.0; this._transitioner.morphTo3D(duration, this._ellipsoid); }; diff --git a/packages/engine/Source/Scene/ScreenSpaceCameraController.js b/packages/engine/Source/Scene/ScreenSpaceCameraController.js index 869bb9ac1c93..c790291143ef 100644 --- a/packages/engine/Source/Scene/ScreenSpaceCameraController.js +++ b/packages/engine/Source/Scene/ScreenSpaceCameraController.js @@ -2,7 +2,6 @@ import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Cartesian4 from "../Core/Cartesian4.js"; import Cartographic from "../Core/Cartographic.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -225,7 +224,7 @@ function ScreenSpaceCameraController(scene) { modifier: KeyboardEventModifier.SHIFT, }; - const ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.default); + const ellipsoid = scene.ellipsoid ?? Ellipsoid.default; /** * The minimum height the camera must be before picking the terrain or scene content instead of the ellipsoid. Defaults to scene.ellipsoid.minimumRadius * 0.025 when another ellipsoid than WGS84 is used. @@ -631,10 +630,9 @@ function handleZoom( return; } - const sameStartPosition = defaultValue( - movement.inertiaEnabled, - Cartesian2.equals(startPosition, object._zoomMouseStart), - ); + const sameStartPosition = + movement.inertiaEnabled ?? + Cartesian2.equals(startPosition, object._zoomMouseStart); let zoomingOnVector = object._zoomingOnVector; let rotatingZoom = object._rotatingZoom; let pickedPosition; @@ -1210,7 +1208,7 @@ function getDistanceFromSurface(controller) { } else { height = camera.position.z; } - const globeHeight = defaultValue(controller._scene.globeHeight, 0.0); + const globeHeight = controller._scene.globeHeight ?? 0.0; const distanceFromSurface = Math.abs(globeHeight - height); return distanceFromSurface; } @@ -2038,8 +2036,8 @@ function rotate3D( rotateOnlyVertical, rotateOnlyHorizontal, ) { - rotateOnlyVertical = defaultValue(rotateOnlyVertical, false); - rotateOnlyHorizontal = defaultValue(rotateOnlyHorizontal, false); + rotateOnlyVertical = rotateOnlyVertical ?? false; + rotateOnlyHorizontal = rotateOnlyHorizontal ?? false; const scene = controller._scene; const camera = scene.camera; @@ -2826,7 +2824,7 @@ function look3D(controller, startPosition, movement, rotationAxis) { } angle = movement.startPosition.y > movement.endPosition.y ? -angle : angle; - rotationAxis = defaultValue(rotationAxis, horizontalRotationAxis); + rotationAxis = rotationAxis ?? horizontalRotationAxis; if (defined(rotationAxis)) { const direction = camera.direction; const negativeRotationAxis = Cartesian3.negate( @@ -2913,7 +2911,7 @@ function adjustHeightForTerrain(controller, cameraChanged) { } const camera = scene.camera; - const ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.WGS84); + const ellipsoid = scene.ellipsoid ?? Ellipsoid.WGS84; const projection = scene.mapProjection; let transform; @@ -3012,7 +3010,7 @@ ScreenSpaceCameraController.prototype.update = function () { this._ellipsoid = Ellipsoid.UNIT_SPHERE; } else { this._globe = globe; - this._ellipsoid = defaultValue(scene.ellipsoid, Ellipsoid.default); + this._ellipsoid = scene.ellipsoid ?? Ellipsoid.default; } const { verticalExaggeration, verticalExaggerationRelativeHeight } = scene; diff --git a/packages/engine/Source/Scene/ShadowMap.js b/packages/engine/Source/Scene/ShadowMap.js index 448d9816bf1e..0f7aae25ccce 100644 --- a/packages/engine/Source/Scene/ShadowMap.js +++ b/packages/engine/Source/Scene/ShadowMap.js @@ -79,7 +79,7 @@ import ShadowMapShader from "./ShadowMapShader.js"; * @demo {@link https://sandcastle.cesium.com/index.html?src=Shadows.html|Cesium Sandcastle Shadows Demo} */ function ShadowMap(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const context = options.context; //>>includeStart('debug', pragmas.debug); @@ -98,9 +98,9 @@ function ShadowMap(options) { } //>>includeEnd('debug'); - this._enabled = defaultValue(options.enabled, true); - this._softShadows = defaultValue(options.softShadows, false); - this._normalOffset = defaultValue(options.normalOffset, true); + this._enabled = options.enabled ?? true; + this._softShadows = options.softShadows ?? false; + this._normalOffset = options.normalOffset ?? true; this.dirty = true; /** @@ -109,7 +109,7 @@ function ShadowMap(options) { * * @private */ - this.fromLightSource = defaultValue(options.fromLightSource, true); + this.fromLightSource = options.fromLightSource ?? true; /** * Determines the darkness of the shadows. @@ -117,7 +117,7 @@ function ShadowMap(options) { * @type {number} * @default 0.3 */ - this.darkness = defaultValue(options.darkness, 0.3); + this.darkness = options.darkness ?? 0.3; this._darkness = this.darkness; /** @@ -126,7 +126,7 @@ function ShadowMap(options) { * @type {boolean} * @default true */ - this.fadingEnabled = defaultValue(options.fadingEnabled, true); + this.fadingEnabled = options.fadingEnabled ?? true; /** * Determines the maximum distance of the shadow map. Only applicable for cascaded shadows. Larger distances may result in lower quality shadows. @@ -134,7 +134,7 @@ function ShadowMap(options) { * @type {number} * @default 5000.0 */ - this.maximumDistance = defaultValue(options.maximumDistance, 5000.0); + this.maximumDistance = options.maximumDistance ?? 5000.0; this._outOfView = false; this._outOfViewPrevious = false; @@ -205,15 +205,15 @@ function ShadowMap(options) { this._sceneCamera = undefined; this._boundingSphere = new BoundingSphere(); - this._isPointLight = defaultValue(options.isPointLight, false); - this._pointLightRadius = defaultValue(options.pointLightRadius, 100.0); + this._isPointLight = options.isPointLight ?? false; + this._pointLightRadius = options.pointLightRadius ?? 100.0; this._cascadesEnabled = this._isPointLight ? false - : defaultValue(options.cascadesEnabled, true); + : (options.cascadesEnabled ?? true); this._numberOfCascades = !this._cascadesEnabled ? 0 - : defaultValue(options.numberOfCascades, 4); + : (options.numberOfCascades ?? 4); this._fitNearFar = true; this._maximumCascadeDistances = [25.0, 150.0, 700.0, Number.MAX_VALUE]; @@ -281,7 +281,7 @@ function ShadowMap(options) { this._clearPassState = new PassState(context); - this._size = defaultValue(options.size, 2048); + this._size = options.size ?? 2048; this.size = this._size; } @@ -657,7 +657,7 @@ function updateFramebuffer(shadowMap, context) { } function clearFramebuffer(shadowMap, context, shadowPass) { - shadowPass = defaultValue(shadowPass, 0); + shadowPass = shadowPass ?? 0; if (shadowMap._isPointLight || shadowPass === 0) { shadowMap._clearCommand.framebuffer = shadowMap._passes[shadowPass].framebuffer; diff --git a/packages/engine/Source/Scene/ShadowVolumeAppearance.js b/packages/engine/Source/Scene/ShadowVolumeAppearance.js index 0e16baa57971..be7124557c69 100644 --- a/packages/engine/Source/Scene/ShadowVolumeAppearance.js +++ b/packages/engine/Source/Scene/ShadowVolumeAppearance.js @@ -3,7 +3,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; import Check from "../Core/Check.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import EncodedCartesian3 from "../Core/EncodedCartesian3.js"; import GeometryInstanceAttribute from "../Core/GeometryInstanceAttribute.js"; @@ -704,7 +703,7 @@ ShadowVolumeAppearance.getPlanarTextureCoordinateAttributes = function ( computeRectangleBounds( boundingRectangle, ellipsoid, - defaultValue(height, 0.0), + height ?? 0.0, corner, eastward, northward, diff --git a/packages/engine/Source/Scene/SingleTileImageryProvider.js b/packages/engine/Source/Scene/SingleTileImageryProvider.js index 6e51fb8d22dc..561c14ee20ff 100644 --- a/packages/engine/Source/Scene/SingleTileImageryProvider.js +++ b/packages/engine/Source/Scene/SingleTileImageryProvider.js @@ -43,7 +43,7 @@ import ImageryProvider from "./ImageryProvider.js"; * @see UrlTemplateImageryProvider */ function SingleTileImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; @@ -56,7 +56,7 @@ function SingleTileImageryProvider(options) { this._defaultMinificationFilter = undefined; this._defaultMagnificationFilter = undefined; - const rectangle = defaultValue(options.rectangle, Rectangle.MAX_VALUE); + const rectangle = options.rectangle ?? Rectangle.MAX_VALUE; const tilingScheme = new GeographicTilingScheme({ rectangle: rectangle, numberOfLevelZeroTilesX: 1, @@ -309,7 +309,7 @@ SingleTileImageryProvider.fromUrl = async function (url, options) { const resource = Resource.createIfNeeded(url); const image = await doRequest(resource); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const provider = new SingleTileImageryProvider({ ...options, url: url, diff --git a/packages/engine/Source/Scene/SkyAtmosphere.js b/packages/engine/Source/Scene/SkyAtmosphere.js index 62bffed2f0ef..9863027c96c8 100644 --- a/packages/engine/Source/Scene/SkyAtmosphere.js +++ b/packages/engine/Source/Scene/SkyAtmosphere.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import Ellipsoid from "../Core/Ellipsoid.js"; @@ -41,7 +40,7 @@ import SceneMode from "./SceneMode.js"; * @see Scene.skyAtmosphere */ function SkyAtmosphere(ellipsoid) { - ellipsoid = defaultValue(ellipsoid, Ellipsoid.WGS84); + ellipsoid = ellipsoid ?? Ellipsoid.WGS84; /** * Determines if the atmosphere is shown. diff --git a/packages/engine/Source/Scene/SkyBox.js b/packages/engine/Source/Scene/SkyBox.js index 39ca3c8b942e..52a016f7cfc2 100644 --- a/packages/engine/Source/Scene/SkyBox.js +++ b/packages/engine/Source/Scene/SkyBox.js @@ -2,7 +2,6 @@ import buildModuleUrl from "../Core/buildModuleUrl.js"; import BoxGeometry from "../Core/BoxGeometry.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -71,7 +70,7 @@ function SkyBox(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; this._command = new DrawCommand({ modelMatrix: Matrix4.clone(Matrix4.IDENTITY), diff --git a/packages/engine/Source/Scene/SphereEmitter.js b/packages/engine/Source/Scene/SphereEmitter.js index bb58256c0168..5d184603cf13 100644 --- a/packages/engine/Source/Scene/SphereEmitter.js +++ b/packages/engine/Source/Scene/SphereEmitter.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Check from "../Core/Check.js"; -import defaultValue from "../Core/defaultValue.js"; import CesiumMath from "../Core/Math.js"; /** @@ -13,13 +12,13 @@ import CesiumMath from "../Core/Math.js"; * @param {number} [radius=1.0] The radius of the sphere in meters. */ function SphereEmitter(radius) { - radius = defaultValue(radius, 1.0); + radius = radius ?? 1.0; //>>includeStart('debug', pragmas.debug); Check.typeOf.number.greaterThan("radius", radius, 0.0); //>>includeEnd('debug'); - this._radius = defaultValue(radius, 1.0); + this._radius = radius ?? 1.0; } Object.defineProperties(SphereEmitter.prototype, { diff --git a/packages/engine/Source/Scene/StructuralMetadata.js b/packages/engine/Source/Scene/StructuralMetadata.js index f97c513041ad..25a9365b477c 100644 --- a/packages/engine/Source/Scene/StructuralMetadata.js +++ b/packages/engine/Source/Scene/StructuralMetadata.js @@ -25,7 +25,7 @@ import defined from "../Core/defined.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function StructuralMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.schema", options.schema); //>>includeEnd('debug'); diff --git a/packages/engine/Source/Scene/SunLight.js b/packages/engine/Source/Scene/SunLight.js index a0441da23979..744876a002c8 100644 --- a/packages/engine/Source/Scene/SunLight.js +++ b/packages/engine/Source/Scene/SunLight.js @@ -12,20 +12,20 @@ import defaultValue from "../Core/defaultValue.js"; * @constructor */ function SunLight(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * The color of the light. * @type {Color} * @default Color.WHITE */ - this.color = Color.clone(defaultValue(options.color, Color.WHITE)); + this.color = Color.clone(options.color ?? Color.WHITE); /** * The intensity of the light. * @type {number} * @default 2.0 */ - this.intensity = defaultValue(options.intensity, 2.0); + this.intensity = options.intensity ?? 2.0; } export default SunLight; diff --git a/packages/engine/Source/Scene/SupportedImageFormats.js b/packages/engine/Source/Scene/SupportedImageFormats.js index f98a33e32015..bec28dbd7fcb 100644 --- a/packages/engine/Source/Scene/SupportedImageFormats.js +++ b/packages/engine/Source/Scene/SupportedImageFormats.js @@ -10,9 +10,9 @@ import defaultValue from "../Core/defaultValue.js"; * @private */ function SupportedImageFormats(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - this.webp = defaultValue(options.webp, false); - this.basis = defaultValue(options.basis, false); + options = options ?? defaultValue.EMPTY_OBJECT; + this.webp = options.webp ?? false; + this.basis = options.basis ?? false; } export default SupportedImageFormats; diff --git a/packages/engine/Source/Scene/TextureAtlas.js b/packages/engine/Source/Scene/TextureAtlas.js index e094cd7f3de7..15a569cc889e 100644 --- a/packages/engine/Source/Scene/TextureAtlas.js +++ b/packages/engine/Source/Scene/TextureAtlas.js @@ -19,8 +19,8 @@ function TextureAtlasNode( childNode2, imageIndex, ) { - this.bottomLeft = defaultValue(bottomLeft, Cartesian2.ZERO); - this.topRight = defaultValue(topRight, Cartesian2.ZERO); + this.bottomLeft = bottomLeft ?? Cartesian2.ZERO; + this.topRight = topRight ?? Cartesian2.ZERO; this.childNode1 = childNode1; this.childNode2 = childNode2; this.imageIndex = imageIndex; @@ -50,9 +50,9 @@ const defaultInitialSize = new Cartesian2(16.0, 16.0); * @private */ function TextureAtlas(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const borderWidthInPixels = defaultValue(options.borderWidthInPixels, 1.0); - const initialSize = defaultValue(options.initialSize, defaultInitialSize); + options = options ?? defaultValue.EMPTY_OBJECT; + const borderWidthInPixels = options.borderWidthInPixels ?? 1.0; + const initialSize = options.initialSize ?? defaultInitialSize; //>>includeStart('debug', pragmas.debug); if (!defined(options.context)) { @@ -69,7 +69,7 @@ function TextureAtlas(options) { //>>includeEnd('debug'); this._context = options.context; - this._pixelFormat = defaultValue(options.pixelFormat, PixelFormat.RGBA); + this._pixelFormat = options.pixelFormat ?? PixelFormat.RGBA; this._borderWidthInPixels = borderWidthInPixels; this._textureCoordinates = []; this._guid = createGuid(); diff --git a/packages/engine/Source/Scene/TileBoundingRegion.js b/packages/engine/Source/Scene/TileBoundingRegion.js index 34fd5847aaa0..cf349322d04b 100644 --- a/packages/engine/Source/Scene/TileBoundingRegion.js +++ b/packages/engine/Source/Scene/TileBoundingRegion.js @@ -3,7 +3,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; import Check from "../Core/Check.js"; import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Ellipsoid from "../Core/Ellipsoid.js"; import GeometryInstance from "../Core/GeometryInstance.js"; @@ -40,8 +39,8 @@ function TileBoundingRegion(options) { //>>includeEnd('debug'); this.rectangle = Rectangle.clone(options.rectangle); - this.minimumHeight = defaultValue(options.minimumHeight, 0.0); - this.maximumHeight = defaultValue(options.maximumHeight, 0.0); + this.minimumHeight = options.minimumHeight ?? 0.0; + this.maximumHeight = options.maximumHeight ?? 0.0; /** * The world coordinates of the southwest corner of the tile's rectangle. @@ -99,13 +98,13 @@ function TileBoundingRegion(options) { */ this.northNormal = new Cartesian3(); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + const ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84; computeBox(this, options.rectangle, ellipsoid); this._orientedBoundingBox = undefined; this._boundingSphere = undefined; - if (defaultValue(options.computeBoundingVolumes, true)) { + if (options.computeBoundingVolumes ?? true) { this.computeBoundingVolumes(ellipsoid); } } diff --git a/packages/engine/Source/Scene/TileBoundingS2Cell.js b/packages/engine/Source/Scene/TileBoundingS2Cell.js index 2656f5817517..1d1bccfd1e10 100644 --- a/packages/engine/Source/Scene/TileBoundingS2Cell.js +++ b/packages/engine/Source/Scene/TileBoundingS2Cell.js @@ -9,7 +9,6 @@ import CoplanarPolygonOutlineGeometry from "../Core/CoplanarPolygonOutlineGeomet import BoundingSphere from "../Core/BoundingSphere.js"; import Check from "../Core/Check.js"; import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js"; -import defaultValue from "../Core/defaultValue.js"; import GeometryInstance from "../Core/GeometryInstance.js"; import Matrix4 from "../Core/Matrix4.js"; import PerInstanceColorAppearance from "./PerInstanceColorAppearance.js"; @@ -40,9 +39,9 @@ function TileBoundingS2Cell(options) { //>>includeEnd('debug'); const s2Cell = S2Cell.fromToken(options.token); - const minimumHeight = defaultValue(options.minimumHeight, 0.0); - const maximumHeight = defaultValue(options.maximumHeight, 0.0); - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + const minimumHeight = options.minimumHeight ?? 0.0; + const maximumHeight = options.maximumHeight ?? 0.0; + const ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84; this.s2Cell = s2Cell; this.minimumHeight = minimumHeight; diff --git a/packages/engine/Source/Scene/TileCoordinatesImageryProvider.js b/packages/engine/Source/Scene/TileCoordinatesImageryProvider.js index 5983a38e3e89..dd8a67411fbd 100644 --- a/packages/engine/Source/Scene/TileCoordinatesImageryProvider.js +++ b/packages/engine/Source/Scene/TileCoordinatesImageryProvider.js @@ -29,15 +29,15 @@ import GeographicTilingScheme from "../Core/GeographicTilingScheme.js"; * @param {TileCoordinatesImageryProvider.ConstructorOptions} [options] Object describing initialization options */ function TileCoordinatesImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._tilingScheme = defined(options.tilingScheme) ? options.tilingScheme : new GeographicTilingScheme({ ellipsoid: options.ellipsoid }); - this._color = defaultValue(options.color, Color.YELLOW); + this._color = options.color ?? Color.YELLOW; this._errorEvent = new Event(); - this._tileWidth = defaultValue(options.tileWidth, 256); - this._tileHeight = defaultValue(options.tileHeight, 256); + this._tileWidth = options.tileWidth ?? 256; + this._tileHeight = options.tileHeight ?? 256; this._defaultAlpha = undefined; this._defaultNightAlpha = undefined; diff --git a/packages/engine/Source/Scene/TileMapServiceImageryProvider.js b/packages/engine/Source/Scene/TileMapServiceImageryProvider.js index b195701fbe0f..df36589e72ed 100644 --- a/packages/engine/Source/Scene/TileMapServiceImageryProvider.js +++ b/packages/engine/Source/Scene/TileMapServiceImageryProvider.js @@ -139,7 +139,7 @@ TileMapServiceImageryProvider.fromUrl = async function (url, options) { url: "tilemapresource.xml", }); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const metadata = await TileMapServiceImageryProvider._requestMetadata( options, tmsResource, @@ -262,26 +262,17 @@ TileMapServiceImageryProvider._metadataSuccess = function ( throw new RuntimeError(message); } - const fileExtension = defaultValue( - options.fileExtension, - format.getAttribute("extension"), - ); - const tileWidth = defaultValue( - options.tileWidth, - parseInt(format.getAttribute("width"), 10), - ); - const tileHeight = defaultValue( - options.tileHeight, - parseInt(format.getAttribute("height"), 10), - ); - let minimumLevel = defaultValue( - options.minimumLevel, - parseInt(tilesetsList[0].getAttribute("order"), 10), - ); - const maximumLevel = defaultValue( - options.maximumLevel, - parseInt(tilesetsList[tilesetsList.length - 1].getAttribute("order"), 10), - ); + const fileExtension = + options.fileExtension ?? format.getAttribute("extension"); + const tileWidth = + options.tileWidth ?? parseInt(format.getAttribute("width"), 10); + const tileHeight = + options.tileHeight ?? parseInt(format.getAttribute("height"), 10); + let minimumLevel = + options.minimumLevel ?? parseInt(tilesetsList[0].getAttribute("order"), 10); + const maximumLevel = + options.maximumLevel ?? + parseInt(tilesetsList[tilesetsList.length - 1].getAttribute("order"), 10); const tilingSchemeName = tilesets.getAttribute("profile"); let tilingScheme = options.tilingScheme; @@ -326,7 +317,7 @@ TileMapServiceImageryProvider._metadataSuccess = function ( // In older versions of gdal x and y values were flipped, which is why we check for an option to flip // the values here as well. Unfortunately there is no way to autodetect whether flipping is needed. - const flipXY = defaultValue(options.flipXY, false); + const flipXY = options.flipXY ?? false; if (flipXY) { swXY = new Cartesian2( parseFloat(bbox.getAttribute("miny")), @@ -412,15 +403,15 @@ TileMapServiceImageryProvider._metadataFailure = function ( tmsResource, ) { // Can't load XML, still allow options and defaults - const fileExtension = defaultValue(options.fileExtension, "png"); - const tileWidth = defaultValue(options.tileWidth, 256); - const tileHeight = defaultValue(options.tileHeight, 256); + const fileExtension = options.fileExtension ?? "png"; + const tileWidth = options.tileWidth ?? 256; + const tileHeight = options.tileHeight ?? 256; const maximumLevel = options.maximumLevel; const tilingScheme = defined(options.tilingScheme) ? options.tilingScheme : new WebMercatorTilingScheme({ ellipsoid: options.ellipsoid }); - let rectangle = defaultValue(options.rectangle, tilingScheme.rectangle); + let rectangle = options.rectangle ?? tilingScheme.rectangle; // The rectangle must not be outside the bounds allowed by the tiling scheme. rectangle = confineRectangleToTilingScheme(rectangle, tilingScheme); diff --git a/packages/engine/Source/Scene/TileMetadata.js b/packages/engine/Source/Scene/TileMetadata.js index c93462c1a578..d5ed9c7b7c40 100644 --- a/packages/engine/Source/Scene/TileMetadata.js +++ b/packages/engine/Source/Scene/TileMetadata.js @@ -19,7 +19,7 @@ import MetadataEntity from "./MetadataEntity.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function TileMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const tile = options.tile; const metadataClass = options.class; diff --git a/packages/engine/Source/Scene/TilesetMetadata.js b/packages/engine/Source/Scene/TilesetMetadata.js index f5f23d1d6315..0c0ddf180379 100644 --- a/packages/engine/Source/Scene/TilesetMetadata.js +++ b/packages/engine/Source/Scene/TilesetMetadata.js @@ -19,7 +19,7 @@ import MetadataEntity from "./MetadataEntity.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function TilesetMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const tileset = options.tileset; const metadataClass = options.class; diff --git a/packages/engine/Source/Scene/TimeDynamicImagery.js b/packages/engine/Source/Scene/TimeDynamicImagery.js index 93c31eb5eede..d50219257bf2 100644 --- a/packages/engine/Source/Scene/TimeDynamicImagery.js +++ b/packages/engine/Source/Scene/TimeDynamicImagery.js @@ -19,7 +19,7 @@ import RequestType from "../Core/RequestType.js"; * @param {Function} options.reloadFunction A function that will be called when all imagery tiles need to be reloaded. */ function TimeDynamicImagery(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.clock", options.clock); diff --git a/packages/engine/Source/Scene/TimeDynamicPointCloud.js b/packages/engine/Source/Scene/TimeDynamicPointCloud.js index 2d52a8ef21cd..1bdbfe4712a3 100644 --- a/packages/engine/Source/Scene/TimeDynamicPointCloud.js +++ b/packages/engine/Source/Scene/TimeDynamicPointCloud.js @@ -39,7 +39,7 @@ import ShadowMode from "./ShadowMode.js"; * @param {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the point cloud. */ function TimeDynamicPointCloud(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.clock", options.clock); @@ -52,7 +52,7 @@ function TimeDynamicPointCloud(options) { * @type {boolean} * @default true */ - this.show = defaultValue(options.show, true); + this.show = options.show ?? true; /** * A 4x4 transformation matrix that transforms the point cloud. @@ -60,9 +60,7 @@ function TimeDynamicPointCloud(options) { * @type {Matrix4} * @default Matrix4.IDENTITY */ - this.modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this.modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); /** * Determines whether the point cloud casts or receives shadows from light sources. @@ -76,7 +74,7 @@ function TimeDynamicPointCloud(options) { * @type {ShadowMode} * @default ShadowMode.ENABLED */ - this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED); + this.shadows = options.shadows ?? ShadowMode.ENABLED; /** * The maximum amount of GPU memory (in MB) that may be used to cache point cloud frames. @@ -92,7 +90,7 @@ function TimeDynamicPointCloud(options) { * * @see TimeDynamicPointCloud#totalMemoryUsageInBytes */ - this.maximumMemoryUsage = defaultValue(options.maximumMemoryUsage, 256); + this.maximumMemoryUsage = options.maximumMemoryUsage ?? 256; /** * Options for controlling point size based on geometric error and eye dome lighting. @@ -468,9 +466,9 @@ function getMaximumAttenuation(that) { const defaultShading = new PointCloudShading(); function renderFrame(that, frame, updateState, frameState) { - const shading = defaultValue(that.shading, defaultShading); + const shading = that.shading ?? defaultShading; const pointCloud = frame.pointCloud; - const transform = defaultValue(frame.transform, Matrix4.IDENTITY); + const transform = frame.transform ?? Matrix4.IDENTITY; pointCloud.modelMatrix = Matrix4.multiplyTransformation( that.modelMatrix, transform, diff --git a/packages/engine/Source/Scene/TweenCollection.js b/packages/engine/Source/Scene/TweenCollection.js index 8ace4f73ed8f..cbeaaf590b14 100644 --- a/packages/engine/Source/Scene/TweenCollection.js +++ b/packages/engine/Source/Scene/TweenCollection.js @@ -212,7 +212,7 @@ Object.defineProperties(TweenCollection.prototype, { * @exception {DeveloperError} options.duration must be positive. */ TweenCollection.prototype.add = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.startObject) || !defined(options.stopObject)) { @@ -236,12 +236,9 @@ TweenCollection.prototype.add = function (options) { } const duration = options.duration / TimeConstants.SECONDS_PER_MILLISECOND; - const delayInSeconds = defaultValue(options.delay, 0.0); + const delayInSeconds = options.delay ?? 0.0; const delay = delayInSeconds / TimeConstants.SECONDS_PER_MILLISECOND; - const easingFunction = defaultValue( - options.easingFunction, - EasingFunction.LINEAR_NONE, - ); + const easingFunction = options.easingFunction ?? EasingFunction.LINEAR_NONE; const value = options.startObject; const tweenjs = new TweenJS(value); @@ -253,8 +250,8 @@ TweenCollection.prototype.add = function (options) { options.update(value); }); } - tweenjs.onComplete(defaultValue(options.complete, null)); - tweenjs.repeat(defaultValue(options._repeat, 0.0)); + tweenjs.onComplete(options.complete ?? null); + tweenjs.repeat(options._repeat ?? 0.0); const tween = new Tween( this, @@ -293,7 +290,7 @@ TweenCollection.prototype.add = function (options) { * @exception {DeveloperError} options.duration must be positive. */ TweenCollection.prototype.addProperty = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const object = options.object; const property = options.property; @@ -329,7 +326,7 @@ TweenCollection.prototype.addProperty = function (options) { stopObject: { value: stopValue, }, - duration: defaultValue(options.duration, 3.0), + duration: options.duration ?? 3.0, delay: options.delay, easingFunction: options.easingFunction, update: update, @@ -359,7 +356,7 @@ TweenCollection.prototype.addProperty = function (options) { * @exception {DeveloperError} options.duration must be positive. */ TweenCollection.prototype.addAlpha = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const material = options.material; @@ -398,12 +395,12 @@ TweenCollection.prototype.addAlpha = function (options) { return this.add({ startObject: { - alpha: defaultValue(options.startValue, 0.0), // Default to fade in + alpha: options.startValue ?? 0.0, // Default to fade in }, stopObject: { - alpha: defaultValue(options.stopValue, 1.0), + alpha: options.stopValue ?? 1.0, }, - duration: defaultValue(options.duration, 3.0), + duration: options.duration ?? 3.0, delay: options.delay, easingFunction: options.easingFunction, update: update, @@ -431,7 +428,7 @@ TweenCollection.prototype.addAlpha = function (options) { * @exception {DeveloperError} options.duration must be positive. */ TweenCollection.prototype.addOffsetIncrement = function (options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const material = options.material; diff --git a/packages/engine/Source/Scene/UrlTemplateImageryProvider.js b/packages/engine/Source/Scene/UrlTemplateImageryProvider.js index 48dcab645f46..7399a94f378b 100644 --- a/packages/engine/Source/Scene/UrlTemplateImageryProvider.js +++ b/packages/engine/Source/Scene/UrlTemplateImageryProvider.js @@ -187,7 +187,7 @@ const pickFeaturesTags = combine(tags, { * @see WebMapTileServiceImageryProvider */ function UrlTemplateImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._errorEvent = new Event(); @@ -213,19 +213,15 @@ function UrlTemplateImageryProvider(options) { } this._subdomains = subdomains; - this._tileWidth = defaultValue(options.tileWidth, 256); - this._tileHeight = defaultValue(options.tileHeight, 256); - this._minimumLevel = defaultValue(options.minimumLevel, 0); + this._tileWidth = options.tileWidth ?? 256; + this._tileHeight = options.tileHeight ?? 256; + this._minimumLevel = options.minimumLevel ?? 0; this._maximumLevel = options.maximumLevel; - this._tilingScheme = defaultValue( - options.tilingScheme, - new WebMercatorTilingScheme({ ellipsoid: options.ellipsoid }), - ); + this._tilingScheme = + options.tilingScheme ?? + new WebMercatorTilingScheme({ ellipsoid: options.ellipsoid }); - this._rectangle = defaultValue( - options.rectangle, - this._tilingScheme.rectangle, - ); + this._rectangle = options.rectangle ?? this._tilingScheme.rectangle; this._rectangle = Rectangle.intersection( this._rectangle, this._tilingScheme.rectangle, @@ -238,7 +234,7 @@ function UrlTemplateImageryProvider(options) { credit = new Credit(credit); } this._credit = credit; - this._hasAlphaChannel = defaultValue(options.hasAlphaChannel, true); + this._hasAlphaChannel = options.hasAlphaChannel ?? true; const customTags = options.customTags; const allTags = combine(tags, customTags); @@ -266,7 +262,7 @@ function UrlTemplateImageryProvider(options) { * @type {boolean} * @default true */ - this.enablePickFeatures = defaultValue(options.enablePickFeatures, true); + this.enablePickFeatures = options.enablePickFeatures ?? true; } Object.defineProperties(UrlTemplateImageryProvider.prototype, { diff --git a/packages/engine/Source/Scene/Vector3DTileClampedPolylines.js b/packages/engine/Source/Scene/Vector3DTileClampedPolylines.js index 30a07500ce07..e89eb1711f3b 100644 --- a/packages/engine/Source/Scene/Vector3DTileClampedPolylines.js +++ b/packages/engine/Source/Scene/Vector3DTileClampedPolylines.js @@ -3,7 +3,6 @@ import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Color from "../Core/Color.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import Ellipsoid from "../Core/Ellipsoid.js"; @@ -62,7 +61,7 @@ function Vector3DTileClampedPolylines(options) { this._counts = options.counts; this._batchIds = options.batchIds; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84; this._minimumHeight = options.minimumHeight; this._maximumHeight = options.maximumHeight; this._center = options.center; diff --git a/packages/engine/Source/Scene/Vector3DTileContent.js b/packages/engine/Source/Scene/Vector3DTileContent.js index 1975f60b6055..0eb72e749b1b 100644 --- a/packages/engine/Source/Scene/Vector3DTileContent.js +++ b/packages/engine/Source/Scene/Vector3DTileContent.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import DeveloperError from "../Core/DeveloperError.js"; @@ -193,9 +192,9 @@ function getBatchIds(featureTableJson, featureTableBinary) { let pointBatchIds; let i; - const numberOfPolygons = defaultValue(featureTableJson.POLYGONS_LENGTH, 0); - const numberOfPolylines = defaultValue(featureTableJson.POLYLINES_LENGTH, 0); - const numberOfPoints = defaultValue(featureTableJson.POINTS_LENGTH, 0); + const numberOfPolygons = featureTableJson.POLYGONS_LENGTH ?? 0; + const numberOfPolylines = featureTableJson.POLYLINES_LENGTH ?? 0; + const numberOfPoints = featureTableJson.POINTS_LENGTH ?? 0; if (numberOfPolygons > 0 && defined(featureTableJson.POLYGON_BATCH_IDS)) { const polygonBatchIdsByteOffset = @@ -289,7 +288,7 @@ function createClampedPolylines(options) { } function initialize(content, arrayBuffer, byteOffset) { - byteOffset = defaultValue(byteOffset, 0); + byteOffset = byteOffset ?? 0; const uint8Array = new Uint8Array(arrayBuffer); const view = new DataView(arrayBuffer); @@ -377,9 +376,9 @@ function initialize(content, arrayBuffer, byteOffset) { } } - const numberOfPolygons = defaultValue(featureTableJson.POLYGONS_LENGTH, 0); - const numberOfPolylines = defaultValue(featureTableJson.POLYLINES_LENGTH, 0); - const numberOfPoints = defaultValue(featureTableJson.POINTS_LENGTH, 0); + const numberOfPolygons = featureTableJson.POLYGONS_LENGTH ?? 0; + const numberOfPolylines = featureTableJson.POLYLINES_LENGTH ?? 0; + const numberOfPoints = featureTableJson.POINTS_LENGTH ?? 0; const totalPrimitives = numberOfPolygons + numberOfPolylines + numberOfPoints; const batchTable = new Cesium3DTileBatchTable( @@ -431,18 +430,17 @@ function initialize(content, arrayBuffer, byteOffset) { if (numberOfPolygons > 0) { featureTable.featuresLength = numberOfPolygons; - const polygonCounts = defaultValue( + const polygonCounts = featureTable.getPropertyArray( "POLYGON_COUNTS", ComponentDatatype.UNSIGNED_INT, 1, - ), + ) ?? featureTable.getPropertyArray( "POLYGON_COUNT", ComponentDatatype.UNSIGNED_INT, 1, - ), // Workaround for old vector tilesets using the non-plural name - ); + ); // Workaround for old vector tilesets using the non-plural name if (!defined(polygonCounts)) { throw new RuntimeError( @@ -450,18 +448,17 @@ function initialize(content, arrayBuffer, byteOffset) { ); } - const polygonIndexCounts = defaultValue( + const polygonIndexCounts = featureTable.getPropertyArray( "POLYGON_INDEX_COUNTS", ComponentDatatype.UNSIGNED_INT, 1, - ), + ) ?? featureTable.getPropertyArray( "POLYGON_INDEX_COUNT", ComponentDatatype.UNSIGNED_INT, 1, - ), // Workaround for old vector tilesets using the non-plural name - ); + ); // Workaround for old vector tilesets using the non-plural name if (!defined(polygonIndexCounts)) { throw new RuntimeError( @@ -531,18 +528,17 @@ function initialize(content, arrayBuffer, byteOffset) { if (numberOfPolylines > 0) { featureTable.featuresLength = numberOfPolylines; - const polylineCounts = defaultValue( + const polylineCounts = featureTable.getPropertyArray( "POLYLINE_COUNTS", ComponentDatatype.UNSIGNED_INT, 1, - ), + ) ?? featureTable.getPropertyArray( "POLYLINE_COUNT", ComponentDatatype.UNSIGNED_INT, 1, - ), // Workaround for old vector tilesets using the non-plural name - ); + ); // Workaround for old vector tilesets using the non-plural name if (!defined(polylineCounts)) { throw new RuntimeError( diff --git a/packages/engine/Source/Scene/Vector3DTileGeometry.js b/packages/engine/Source/Scene/Vector3DTileGeometry.js index 682ca7dbb5e5..af0ff1f12ac0 100644 --- a/packages/engine/Source/Scene/Vector3DTileGeometry.js +++ b/packages/engine/Source/Scene/Vector3DTileGeometry.js @@ -1,7 +1,6 @@ import BoundingSphere from "../Core/BoundingSphere.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import Matrix4 from "../Core/Matrix4.js"; @@ -365,7 +364,7 @@ function finishPrimitive(geometries) { boundingVolume: geometries._boundingVolume, boundingVolumes: geometries._boundingVolumes, center: geometries._center, - pickObject: defaultValue(geometries._pickObject, geometries), + pickObject: geometries._pickObject ?? geometries, }); geometries._boxes = undefined; diff --git a/packages/engine/Source/Scene/Vector3DTilePolygons.js b/packages/engine/Source/Scene/Vector3DTilePolygons.js index d11e4424a339..bbc853dfc760 100644 --- a/packages/engine/Source/Scene/Vector3DTilePolygons.js +++ b/packages/engine/Source/Scene/Vector3DTilePolygons.js @@ -1,6 +1,5 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Color from "../Core/Color.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import Ellipsoid from "../Core/Ellipsoid.js"; @@ -58,12 +57,12 @@ function Vector3DTilePolygons(options) { this._transferrableBatchIds = undefined; this._vertexBatchIds = undefined; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84; this._minimumHeight = options.minimumHeight; this._maximumHeight = options.maximumHeight; this._polygonMinimumHeights = options.polygonMinimumHeights; this._polygonMaximumHeights = options.polygonMaximumHeights; - this._center = defaultValue(options.center, Cartesian3.ZERO); + this._center = options.center ?? Cartesian3.ZERO; this._rectangle = options.rectangle; this._center = undefined; diff --git a/packages/engine/Source/Scene/Vector3DTilePolylines.js b/packages/engine/Source/Scene/Vector3DTilePolylines.js index d495a024efcd..1aaedc3b7589 100644 --- a/packages/engine/Source/Scene/Vector3DTilePolylines.js +++ b/packages/engine/Source/Scene/Vector3DTilePolylines.js @@ -1,7 +1,6 @@ import Cartesian3 from "../Core/Cartesian3.js"; import Color from "../Core/Color.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; import Ellipsoid from "../Core/Ellipsoid.js"; @@ -51,7 +50,7 @@ function Vector3DTilePolylines(options) { this._counts = options.counts; this._batchIds = options.batchIds; - this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84); + this._ellipsoid = options.ellipsoid ?? Ellipsoid.WGS84; this._minimumHeight = options.minimumHeight; this._maximumHeight = options.maximumHeight; this._center = options.center; diff --git a/packages/engine/Source/Scene/Vector3DTilePrimitive.js b/packages/engine/Source/Scene/Vector3DTilePrimitive.js index bb5cb4825a57..3f194c0e57e7 100644 --- a/packages/engine/Source/Scene/Vector3DTilePrimitive.js +++ b/packages/engine/Source/Scene/Vector3DTilePrimitive.js @@ -51,7 +51,7 @@ import Vector3DTileBatch from "./Vector3DTileBatch.js"; * @private */ function Vector3DTilePrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; this._batchTable = options.batchTable; this._batchIds = options.batchIds; @@ -70,7 +70,7 @@ function Vector3DTilePrimitive(options) { this._boundingVolume = options.boundingVolume; this._boundingVolumes = options.boundingVolumes; - this._center = defaultValue(options.center, Cartesian3.ZERO); + this._center = options.center ?? Cartesian3.ZERO; this._va = undefined; this._sp = undefined; @@ -127,10 +127,8 @@ function Vector3DTilePrimitive(options) { * @type {ClassificationType} * @default ClassificationType.BOTH */ - this.classificationType = defaultValue( - options.classificationType, - ClassificationType.BOTH, - ); + this.classificationType = + options.classificationType ?? ClassificationType.BOTH; // Hidden options this._vertexShaderSource = options._vertexShaderSource; @@ -257,10 +255,8 @@ function createShaders(primitive, context) { } const batchTable = primitive._batchTable; - const attributeLocations = defaultValue( - primitive._attributeLocations, - defaultAttributeLocations, - ); + const attributeLocations = + primitive._attributeLocations ?? defaultAttributeLocations; let pickId = primitive._pickId; const vertexShaderSource = primitive._vertexShaderSource; @@ -769,7 +765,7 @@ function createColorCommands(primitive, context) { const vertexArray = primitive._va; const sp = primitive._sp; - const modelMatrix = defaultValue(primitive._modelMatrix, Matrix4.IDENTITY); + const modelMatrix = primitive._modelMatrix ?? Matrix4.IDENTITY; const uniformMap = primitive._uniformMap; const bv = primitive._boundingVolume; @@ -876,7 +872,7 @@ function createPickCommands(primitive) { const vertexArray = primitive._va; const spStencil = primitive._spStencil; const spPick = primitive._spPick; - const modelMatrix = defaultValue(primitive._modelMatrix, Matrix4.IDENTITY); + const modelMatrix = primitive._modelMatrix ?? Matrix4.IDENTITY; const uniformMap = primitive._uniformMap; for (let j = 0; j < length; ++j) { diff --git a/packages/engine/Source/Scene/VoxelBoxShape.js b/packages/engine/Source/Scene/VoxelBoxShape.js index fb17d83cc36d..8d328b602489 100644 --- a/packages/engine/Source/Scene/VoxelBoxShape.js +++ b/packages/engine/Source/Scene/VoxelBoxShape.js @@ -5,7 +5,6 @@ import Check from "../Core/Check.js"; import Matrix3 from "../Core/Matrix3.js"; import Matrix4 from "../Core/Matrix4.js"; import OrientedBoundingBox from "../Core/OrientedBoundingBox.js"; -import defaultValue from "../Core/defaultValue.js"; /** * A box {@link VoxelShape}. @@ -130,8 +129,8 @@ VoxelBoxShape.prototype.update = function ( clipMinBounds, clipMaxBounds, ) { - clipMinBounds = defaultValue(clipMinBounds, VoxelBoxShape.DefaultMinBounds); - clipMaxBounds = defaultValue(clipMaxBounds, VoxelBoxShape.DefaultMaxBounds); + clipMinBounds = clipMinBounds ?? VoxelBoxShape.DefaultMinBounds; + clipMaxBounds = clipMaxBounds ?? VoxelBoxShape.DefaultMaxBounds; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("modelMatrix", modelMatrix); Check.typeOf.object("minBounds", minBounds); diff --git a/packages/engine/Source/Scene/VoxelCylinderShape.js b/packages/engine/Source/Scene/VoxelCylinderShape.js index 7418193bdfc9..97830dc2a736 100644 --- a/packages/engine/Source/Scene/VoxelCylinderShape.js +++ b/packages/engine/Source/Scene/VoxelCylinderShape.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import BoundingSphere from "../Core/BoundingSphere.js"; import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; @@ -157,14 +156,8 @@ VoxelCylinderShape.prototype.update = function ( clipMinBounds, clipMaxBounds, ) { - clipMinBounds = defaultValue( - clipMinBounds, - VoxelCylinderShape.DefaultMinBounds, - ); - clipMaxBounds = defaultValue( - clipMaxBounds, - VoxelCylinderShape.DefaultMaxBounds, - ); + clipMinBounds = clipMinBounds ?? VoxelCylinderShape.DefaultMinBounds; + clipMaxBounds = clipMaxBounds ?? VoxelCylinderShape.DefaultMaxBounds; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("modelMatrix", modelMatrix); Check.typeOf.object("minBounds", minBounds); diff --git a/packages/engine/Source/Scene/VoxelEllipsoidShape.js b/packages/engine/Source/Scene/VoxelEllipsoidShape.js index efa1fac04658..c7ca6b99be10 100644 --- a/packages/engine/Source/Scene/VoxelEllipsoidShape.js +++ b/packages/engine/Source/Scene/VoxelEllipsoidShape.js @@ -8,7 +8,6 @@ import Matrix3 from "../Core/Matrix3.js"; import Matrix4 from "../Core/Matrix4.js"; import OrientedBoundingBox from "../Core/OrientedBoundingBox.js"; import Rectangle from "../Core/Rectangle.js"; -import defaultValue from "../Core/defaultValue.js"; /** * An ellipsoid {@link VoxelShape}. @@ -173,8 +172,8 @@ VoxelEllipsoidShape.prototype.update = function ( clipMaxBounds, ) { const { DefaultMinBounds, DefaultMaxBounds } = VoxelEllipsoidShape; - clipMinBounds = defaultValue(clipMinBounds, DefaultMinBounds); - clipMaxBounds = defaultValue(clipMaxBounds, DefaultMaxBounds); + clipMinBounds = clipMinBounds ?? DefaultMinBounds; + clipMaxBounds = clipMaxBounds ?? DefaultMaxBounds; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("modelMatrix", modelMatrix); Check.typeOf.object("minBounds", minBounds); diff --git a/packages/engine/Source/Scene/VoxelPrimitive.js b/packages/engine/Source/Scene/VoxelPrimitive.js index 0942fbb817a4..2e08e7819b7d 100644 --- a/packages/engine/Source/Scene/VoxelPrimitive.js +++ b/packages/engine/Source/Scene/VoxelPrimitive.js @@ -45,7 +45,7 @@ import VerticalExaggeration from "../Core/VerticalExaggeration.js"; * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. */ function VoxelPrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * @type {boolean} @@ -57,10 +57,7 @@ function VoxelPrimitive(options) { * @type {VoxelProvider} * @private */ - this._provider = defaultValue( - options.provider, - VoxelPrimitive.DefaultProvider, - ); + this._provider = options.provider ?? VoxelPrimitive.DefaultProvider; /** * This member is not created until the provider and shape are ready. @@ -230,9 +227,7 @@ function VoxelPrimitive(options) { * @type {Matrix4} * @private */ - this._modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); + this._modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); /** * Model matrix with vertical exaggeration applied. Only used for BOX shape type. @@ -264,10 +259,8 @@ function VoxelPrimitive(options) { * @type {CustomShader} * @private */ - this._customShader = defaultValue( - options.customShader, - VoxelPrimitive.DefaultCustomShader, - ); + this._customShader = + options.customShader ?? VoxelPrimitive.DefaultCustomShader; /** * @type {Event} @@ -1278,7 +1271,7 @@ function initFromProvider(primitive, provider, context) { uniforms.dimensions, ); primitive._paddingBefore = Cartesian3.clone( - defaultValue(provider.paddingBefore, Cartesian3.ZERO), + provider.paddingBefore ?? Cartesian3.ZERO, primitive._paddingBefore, ); uniforms.paddingBefore = Cartesian3.clone( @@ -1286,7 +1279,7 @@ function initFromProvider(primitive, provider, context) { uniforms.paddingBefore, ); primitive._paddingAfter = Cartesian3.clone( - defaultValue(provider.paddingAfter, Cartesian3.ZERO), + provider.paddingAfter ?? Cartesian3.ZERO, primitive._paddingBefore, ); uniforms.paddingAfter = Cartesian3.clone( @@ -1307,14 +1300,8 @@ function initFromProvider(primitive, provider, context) { * @private */ function checkTransformAndBounds(primitive, provider) { - const shapeTransform = defaultValue( - provider.shapeTransform, - Matrix4.IDENTITY, - ); - const globalTransform = defaultValue( - provider.globalTransform, - Matrix4.IDENTITY, - ); + const shapeTransform = provider.shapeTransform ?? Matrix4.IDENTITY; + const globalTransform = provider.globalTransform ?? Matrix4.IDENTITY; // Compound model matrix = global transform * model matrix * shape transform Matrix4.multiplyTransformation( @@ -1457,7 +1444,7 @@ function setupTraversal(primitive, provider, context) { ) : undefined; - const keyframeCount = defaultValue(provider.keyframeCount, 1); + const keyframeCount = provider.keyframeCount ?? 1; return new VoxelTraversal( primitive, @@ -1950,7 +1937,7 @@ function DefaultVoxelProvider() { } DefaultVoxelProvider.prototype.requestData = function (options) { - const tileLevel = defined(options) ? defaultValue(options.tileLevel, 0) : 0; + const tileLevel = defined(options) ? (options.tileLevel ?? 0) : 0; if (tileLevel >= 1) { return undefined; } diff --git a/packages/engine/Source/Scene/WebMapServiceImageryProvider.js b/packages/engine/Source/Scene/WebMapServiceImageryProvider.js index 09fe189a73d8..8c18a6220845 100644 --- a/packages/engine/Source/Scene/WebMapServiceImageryProvider.js +++ b/packages/engine/Source/Scene/WebMapServiceImageryProvider.js @@ -101,7 +101,7 @@ const excludesReverseAxis = [ * viewer.imageryLayers.add(imageryLayer); */ function WebMapServiceImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.url)) { @@ -129,10 +129,7 @@ function WebMapServiceImageryProvider(options) { this._defaultMinificationFilter = undefined; this._defaultMagnificationFilter = undefined; - this._getFeatureInfoUrl = defaultValue( - options.getFeatureInfoUrl, - options.url, - ); + this._getFeatureInfoUrl = options.getFeatureInfoUrl ?? options.url; const resource = Resource.createIfNeeded(options.url); const pickFeatureResource = Resource.createIfNeeded(this._getFeatureInfoUrl); @@ -185,13 +182,12 @@ function WebMapServiceImageryProvider(options) { // Use CRS with 1.3.0 and going forward. // For GeographicTilingScheme, use CRS:84 vice EPSG:4326 to specify lon, lat (x, y) ordering for // bbox requests. - parameters.crs = defaultValue( - options.crs, - options.tilingScheme && - options.tilingScheme.projection instanceof WebMercatorProjection + parameters.crs = + options.crs ?? + (options.tilingScheme && + options.tilingScheme.projection instanceof WebMercatorProjection ? "EPSG:3857" - : "CRS:84", - ); + : "CRS:84"); // The axis order in previous versions of the WMS specifications was to always use easting (x or lon ) and northing (y or // lat). WMS 1.3.0 specifies that, depending on the particular CRS, the x axis may or may not be oriented West-to-East, @@ -213,13 +209,12 @@ function WebMapServiceImageryProvider(options) { } } else { // SRS for WMS 1.1.0 or 1.1.1. - parameters.srs = defaultValue( - options.srs, - options.tilingScheme && - options.tilingScheme.projection instanceof WebMercatorProjection + parameters.srs = + options.srs ?? + (options.tilingScheme && + options.tilingScheme.projection instanceof WebMercatorProjection ? "EPSG:3857" - : "EPSG:4326", - ); + : "EPSG:4326"); } resource.setQueryParameters(parameters, true); @@ -247,10 +242,9 @@ function WebMapServiceImageryProvider(options) { this._tileProvider = new UrlTemplateImageryProvider({ url: resource, pickFeaturesUrl: pickFeatureResource, - tilingScheme: defaultValue( - options.tilingScheme, + tilingScheme: + options.tilingScheme ?? new GeographicTilingScheme({ ellipsoid: options.ellipsoid }), - ), rectangle: options.rectangle, tileWidth: options.tileWidth, tileHeight: options.tileHeight, @@ -259,10 +253,9 @@ function WebMapServiceImageryProvider(options) { subdomains: options.subdomains, tileDiscardPolicy: options.tileDiscardPolicy, credit: options.credit, - getFeatureInfoFormats: defaultValue( - options.getFeatureInfoFormats, + getFeatureInfoFormats: + options.getFeatureInfoFormats ?? WebMapServiceImageryProvider.DefaultGetFeatureInfoFormats, - ), enablePickFeatures: options.enablePickFeatures, }); } diff --git a/packages/engine/Source/Scene/WebMapTileServiceImageryProvider.js b/packages/engine/Source/Scene/WebMapTileServiceImageryProvider.js index 690a7ea59b13..c83cb38c7c09 100644 --- a/packages/engine/Source/Scene/WebMapTileServiceImageryProvider.js +++ b/packages/engine/Source/Scene/WebMapTileServiceImageryProvider.js @@ -114,7 +114,7 @@ const defaultParameters = Object.freeze({ * @see UrlTemplateImageryProvider */ function WebMapTileServiceImageryProvider(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if (!defined(options.url)) { @@ -176,22 +176,19 @@ function WebMapTileServiceImageryProvider(options) { this._style = style; this._tileMatrixSetID = tileMatrixSetID; this._tileMatrixLabels = options.tileMatrixLabels; - this._format = defaultValue(options.format, "image/jpeg"); + this._format = options.format ?? "image/jpeg"; this._tileDiscardPolicy = options.tileDiscardPolicy; this._tilingScheme = defined(options.tilingScheme) ? options.tilingScheme : new WebMercatorTilingScheme({ ellipsoid: options.ellipsoid }); - this._tileWidth = defaultValue(options.tileWidth, 256); - this._tileHeight = defaultValue(options.tileHeight, 256); + this._tileWidth = options.tileWidth ?? 256; + this._tileHeight = options.tileHeight ?? 256; - this._minimumLevel = defaultValue(options.minimumLevel, 0); + this._minimumLevel = options.minimumLevel ?? 0; this._maximumLevel = options.maximumLevel; - this._rectangle = defaultValue( - options.rectangle, - this._tilingScheme.rectangle, - ); + this._rectangle = options.rectangle ?? this._tilingScheme.rectangle; this._dimensions = options.dimensions; const that = this; diff --git a/packages/engine/Source/Scene/createElevationBandMaterial.js b/packages/engine/Source/Scene/createElevationBandMaterial.js index 94d0e8a39ee3..1443fc1e8b3a 100644 --- a/packages/engine/Source/Scene/createElevationBandMaterial.js +++ b/packages/engine/Source/Scene/createElevationBandMaterial.js @@ -159,8 +159,8 @@ function preprocess(layers) { }); } - let extendDownwards = defaultValue(layer.extendDownwards, false); - let extendUpwards = defaultValue(layer.extendUpwards, false); + let extendDownwards = layer.extendDownwards ?? false; + let extendUpwards = layer.extendUpwards ?? false; // Interpret a single entry to extend all the way up and down. if (entries.length === 1 && !extendDownwards && !extendUpwards) { @@ -462,7 +462,7 @@ function createLayeredEntries(layers) { * }); */ function createElevationBandMaterial(options) { - const { scene, layers } = defaultValue(options, defaultValue.EMPTY_OBJECT); + const { scene, layers } = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); Check.typeOf.object("options.scene", scene); diff --git a/packages/engine/Source/Scene/createGooglePhotorealistic3DTileset.js b/packages/engine/Source/Scene/createGooglePhotorealistic3DTileset.js index f762d748dc36..49cf6dda3c37 100644 --- a/packages/engine/Source/Scene/createGooglePhotorealistic3DTileset.js +++ b/packages/engine/Source/Scene/createGooglePhotorealistic3DTileset.js @@ -1,5 +1,4 @@ import Cesium3DTileset from "./Cesium3DTileset.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import IonResource from "../Core/IonResource.js"; import GoogleMaps from "../Core/GoogleMaps.js"; @@ -40,15 +39,13 @@ import Resource from "../Core/Resource.js"; * } */ async function createGooglePhotorealistic3DTileset(key, options) { - options = defaultValue(options, {}); - options.cacheBytes = defaultValue(options.cacheBytes, 1536 * 1024 * 1024); - options.maximumCacheOverflowBytes = defaultValue( - options.maximumCacheOverflowBytes, - 1024 * 1024 * 1024, - ); - options.enableCollision = defaultValue(options.enableCollision, true); + options = options ?? {}; + options.cacheBytes = options.cacheBytes ?? 1536 * 1024 * 1024; + options.maximumCacheOverflowBytes = + options.maximumCacheOverflowBytes ?? 1024 * 1024 * 1024; + options.enableCollision = options.enableCollision ?? true; - key = defaultValue(key, GoogleMaps.defaultApiKey); + key = key ?? GoogleMaps.defaultApiKey; if (!defined(key)) { return requestCachedIonTileset(options); } diff --git a/packages/engine/Source/Scene/createOsmBuildingsAsync.js b/packages/engine/Source/Scene/createOsmBuildingsAsync.js index e3b2908277f3..be27fa9d3d01 100644 --- a/packages/engine/Source/Scene/createOsmBuildingsAsync.js +++ b/packages/engine/Source/Scene/createOsmBuildingsAsync.js @@ -60,15 +60,12 @@ import Cesium3DTileStyle from "./Cesium3DTileStyle.js"; async function createOsmBuildingsAsync(options) { const tileset = await Cesium3DTileset.fromIonAssetId(96188, options); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; let style = options.style; if (!defined(style)) { - const color = defaultValue( - options.defaultColor, - Color.WHITE, - ).toCssColorString(); + const color = (options.defaultColor ?? Color.WHITE).toCssColorString(); style = new Cesium3DTileStyle({ color: `Boolean(\${feature['cesium#color']}) ? color(\${feature['cesium#color']}) : ${color}`, }); diff --git a/packages/engine/Source/Scene/createTangentSpaceDebugPrimitive.js b/packages/engine/Source/Scene/createTangentSpaceDebugPrimitive.js index c5d8175dd2a0..2835cda43c63 100644 --- a/packages/engine/Source/Scene/createTangentSpaceDebugPrimitive.js +++ b/packages/engine/Source/Scene/createTangentSpaceDebugPrimitive.js @@ -30,7 +30,7 @@ import Primitive from "./Primitive.js"; * })); */ function createTangentSpaceDebugPrimitive(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const instances = []; let geometry = options.geometry; @@ -47,10 +47,8 @@ function createTangentSpaceDebugPrimitive(options) { } const attributes = geometry.attributes; - const modelMatrix = Matrix4.clone( - defaultValue(options.modelMatrix, Matrix4.IDENTITY), - ); - const length = defaultValue(options.length, 10000.0); + const modelMatrix = Matrix4.clone(options.modelMatrix ?? Matrix4.IDENTITY); + const length = options.length ?? 10000.0; if (defined(attributes.normal)) { instances.push( diff --git a/packages/engine/Source/Scene/createWorldImageryAsync.js b/packages/engine/Source/Scene/createWorldImageryAsync.js index 24151b0a8df4..0c393f764a66 100644 --- a/packages/engine/Source/Scene/createWorldImageryAsync.js +++ b/packages/engine/Source/Scene/createWorldImageryAsync.js @@ -32,8 +32,8 @@ import IonWorldImageryStyle from "./IonWorldImageryStyle.js"; * } */ function createWorldImageryAsync(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const style = defaultValue(options.style, IonWorldImageryStyle.AERIAL); + options = options ?? defaultValue.EMPTY_OBJECT; + const style = options.style ?? IonWorldImageryStyle.AERIAL; return IonImageryProvider.fromAssetId(style); } export default createWorldImageryAsync; diff --git a/packages/engine/Source/Scene/findContentMetadata.js b/packages/engine/Source/Scene/findContentMetadata.js index dd8e96327d2d..7a95a14ab5a0 100644 --- a/packages/engine/Source/Scene/findContentMetadata.js +++ b/packages/engine/Source/Scene/findContentMetadata.js @@ -34,10 +34,7 @@ function findContentMetadata(tileset, contentHeader) { return undefined; } - const classes = defaultValue( - tileset.schema.classes, - defaultValue.EMPTY_OBJECT, - ); + const classes = tileset.schema.classes ?? defaultValue.EMPTY_OBJECT; if (defined(metadataJson.class)) { const contentClass = classes[metadataJson.class]; return new ContentMetadata({ diff --git a/packages/engine/Source/Scene/findTileMetadata.js b/packages/engine/Source/Scene/findTileMetadata.js index c91a3df7ae93..3c7d0821d1f7 100644 --- a/packages/engine/Source/Scene/findTileMetadata.js +++ b/packages/engine/Source/Scene/findTileMetadata.js @@ -36,10 +36,7 @@ function findTileMetadata(tileset, tileHeader) { return undefined; } - const classes = defaultValue( - tileset.schema.classes, - defaultValue.EMPTY_OBJECT, - ); + const classes = tileset.schema.classes ?? defaultValue.EMPTY_OBJECT; if (defined(metadataJson.class)) { const tileClass = classes[metadataJson.class]; return new TileMetadata({ diff --git a/packages/engine/Source/Scene/parseBatchTable.js b/packages/engine/Source/Scene/parseBatchTable.js index 6105f587abaf..8d65cccb422a 100644 --- a/packages/engine/Source/Scene/parseBatchTable.js +++ b/packages/engine/Source/Scene/parseBatchTable.js @@ -1,7 +1,6 @@ import Check from "../Core/Check.js"; import ComponentDatatype from "../Core/ComponentDatatype.js"; import defined from "../Core/defined.js"; -import defaultValue from "../Core/defaultValue.js"; import deprecationWarning from "../Core/deprecationWarning.js"; import DeveloperError from "../Core/DeveloperError.js"; import RuntimeError from "../Core/RuntimeError.js"; @@ -45,10 +44,7 @@ function parseBatchTable(options) { const featureCount = options.count; const batchTable = options.batchTable; const binaryBody = options.binaryBody; - const parseAsPropertyAttributes = defaultValue( - options.parseAsPropertyAttributes, - false, - ); + const parseAsPropertyAttributes = options.parseAsPropertyAttributes ?? false; const customAttributeOutput = options.customAttributeOutput; //>>includeStart('debug', pragmas.debug); diff --git a/packages/engine/Source/Scene/parseFeatureMetadataLegacy.js b/packages/engine/Source/Scene/parseFeatureMetadataLegacy.js index 9d20d691a5d9..09815240ffd4 100644 --- a/packages/engine/Source/Scene/parseFeatureMetadataLegacy.js +++ b/packages/engine/Source/Scene/parseFeatureMetadataLegacy.js @@ -21,7 +21,7 @@ import MetadataTable from "./MetadataTable.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function parseFeatureMetadataLegacy(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const extension = options.extension; // The calling code is responsible for loading the schema. diff --git a/packages/engine/Source/Scene/parseStructuralMetadata.js b/packages/engine/Source/Scene/parseStructuralMetadata.js index 415de8929f3a..1f03bbc3fa71 100644 --- a/packages/engine/Source/Scene/parseStructuralMetadata.js +++ b/packages/engine/Source/Scene/parseStructuralMetadata.js @@ -21,7 +21,7 @@ import MetadataTable from "./MetadataTable.js"; * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy. */ function parseStructuralMetadata(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const extension = options.extension; // The calling code is responsible for loading the schema. diff --git a/packages/engine/Source/Widget/CesiumWidget.js b/packages/engine/Source/Widget/CesiumWidget.js index 4e08a9beffc7..41d3ec2000b0 100644 --- a/packages/engine/Source/Widget/CesiumWidget.js +++ b/packages/engine/Source/Widget/CesiumWidget.js @@ -212,7 +212,7 @@ function CesiumWidget(container, options) { container = getElement(container); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //Configure the widget DOM elements const element = document.createElement("div"); @@ -248,10 +248,8 @@ function CesiumWidget(container, options) { } } - const blurActiveElementOnCanvasFocus = defaultValue( - options.blurActiveElementOnCanvasFocus, - true, - ); + const blurActiveElementOnCanvasFocus = + options.blurActiveElementOnCanvasFocus ?? true; if (blurActiveElementOnCanvasFocus) { canvas.addEventListener("mousedown", blurActiveElement); @@ -272,12 +270,10 @@ function CesiumWidget(container, options) { ? getElement(options.creditViewport) : element; - const showRenderLoopErrors = defaultValue(options.showRenderLoopErrors, true); + const showRenderLoopErrors = options.showRenderLoopErrors ?? true; - const useBrowserRecommendedResolution = defaultValue( - options.useBrowserRecommendedResolution, - true, - ); + const useBrowserRecommendedResolution = + options.useBrowserRecommendedResolution ?? true; this._element = element; this._container = container; @@ -314,7 +310,7 @@ function CesiumWidget(container, options) { configureCanvasSize(this); try { - const ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.default); + const ellipsoid = options.ellipsoid ?? Ellipsoid.default; const scene = new Scene({ canvas: canvas, @@ -324,7 +320,7 @@ function CesiumWidget(container, options) { ellipsoid: ellipsoid, mapProjection: options.mapProjection, orderIndependentTranslucency: options.orderIndependentTranslucency, - scene3DOnly: defaultValue(options.scene3DOnly, false), + scene3DOnly: options.scene3DOnly ?? false, shadows: options.shadows, mapMode2D: options.mapMode2D, requestRenderMode: options.requestRenderMode, @@ -345,10 +341,7 @@ function CesiumWidget(container, options) { } if (globe !== false) { scene.globe = globe; - scene.globe.shadows = defaultValue( - options.terrainShadows, - ShadowMode.RECEIVE_ONLY, - ); + scene.globe.shadows = options.terrainShadows ?? ShadowMode.RECEIVE_ONLY; } let skyBox = options.skyBox; @@ -412,10 +405,7 @@ function CesiumWidget(container, options) { } this._useDefaultRenderLoop = undefined; - this.useDefaultRenderLoop = defaultValue( - options.useDefaultRenderLoop, - true, - ); + this.useDefaultRenderLoop = options.useDefaultRenderLoop ?? true; this._targetFrameRate = undefined; this.targetFrameRate = options.targetFrameRate; diff --git a/packages/engine/Source/Workers/createGeometry.js b/packages/engine/Source/Workers/createGeometry.js index e0a458a5a0cf..a6abcfd0e3b5 100644 --- a/packages/engine/Source/Workers/createGeometry.js +++ b/packages/engine/Source/Workers/createGeometry.js @@ -1,5 +1,4 @@ import DeveloperError from "../Core/DeveloperError.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import PrimitivePipeline from "../Scene/PrimitivePipeline.js"; import createTaskProcessorWorker from "./createTaskProcessorWorker.js"; @@ -8,7 +7,7 @@ import createTaskProcessorWorker from "./createTaskProcessorWorker.js"; const moduleCache = {}; async function getModule(moduleName, modulePath) { - let module = defaultValue(moduleCache[modulePath], moduleCache[moduleName]); + let module = moduleCache[modulePath] ?? moduleCache[moduleName]; if (defined(module)) { return module; diff --git a/packages/engine/Source/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js b/packages/engine/Source/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js index fbffcb40ba47..0297a8895ba3 100644 --- a/packages/engine/Source/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +++ b/packages/engine/Source/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js @@ -3,7 +3,6 @@ import BoundingSphere from "../Core/BoundingSphere.js"; import Cartesian2 from "../Core/Cartesian2.js"; import Cartesian3 from "../Core/Cartesian3.js"; import Cartographic from "../Core/Cartographic.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Ellipsoid from "../Core/Ellipsoid.js"; import EllipsoidalOccluder from "../Core/EllipsoidalOccluder.js"; @@ -24,7 +23,7 @@ const sizeOfFloat = Float32Array.BYTES_PER_ELEMENT; const sizeOfDouble = Float64Array.BYTES_PER_ELEMENT; function indexOfEpsilon(arr, elem, elemType) { - elemType = defaultValue(elemType, CesiumMath); + elemType = elemType ?? CesiumMath; const count = arr.length; for (let i = 0; i < count; ++i) { if (elemType.equalsEpsilon(arr[i], elem, CesiumMath.EPSILON12)) { diff --git a/packages/engine/Source/Workers/decodeI3S.js b/packages/engine/Source/Workers/decodeI3S.js index 89c1b130b94d..3d1330e63743 100644 --- a/packages/engine/Source/Workers/decodeI3S.js +++ b/packages/engine/Source/Workers/decodeI3S.js @@ -1,5 +1,4 @@ import createTaskProcessorWorker from "./createTaskProcessorWorker.js"; -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import WebMercatorProjection from "../Core/WebMercatorProjection.js"; import Ellipsoid from "../Core/Ellipsoid.js"; @@ -274,10 +273,7 @@ function getFeatureHash(symbologyData, outlinesHash, featureIndex) { indices: {}, edges: {}, }); - const featureSymbology = defaultValue( - symbologyData[featureIndex], - symbologyData.default, - ); + const featureSymbology = symbologyData[featureIndex] ?? symbologyData.default; newFeatureHash.hasOutline = defined(featureSymbology?.edges); return newFeatureHash; } diff --git a/packages/engine/Source/Workers/transcodeKTX2.js b/packages/engine/Source/Workers/transcodeKTX2.js index b92a5a9c240d..4e3836bd8754 100644 --- a/packages/engine/Source/Workers/transcodeKTX2.js +++ b/packages/engine/Source/Workers/transcodeKTX2.js @@ -1,4 +1,3 @@ -import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import Check from "../Core/Check.js"; import PixelFormat from "../Core/PixelFormat.js"; @@ -285,7 +284,7 @@ function transcodeCompressed( async function initWorker(parameters, transferableObjects) { // Require and compile WebAssembly module, or use fallback if not supported const wasmConfig = parameters.webAssemblyConfig; - const basisTranscoder = defaultValue(basis, self.BASIS); + const basisTranscoder = basis ?? self.BASIS; if (defined(wasmConfig.wasmBinaryFile)) { transcoderModule = await basisTranscoder(wasmConfig); } else { diff --git a/packages/engine/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js b/packages/engine/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js index ba106dde17b9..64486d31c634 100644 --- a/packages/engine/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js +++ b/packages/engine/Specs/Core/GoogleEarthEnterpriseMetadataSpec.js @@ -1,6 +1,5 @@ import { decodeGoogleEarthEnterpriseData, - defaultValue, GoogleEarthEnterpriseMetadata, GoogleEarthEnterpriseTileInformation, Math as CesiumMath, @@ -115,7 +114,7 @@ describe("Core/GoogleEarthEnterpriseMetadata", function () { GoogleEarthEnterpriseMetadata.prototype, "getQuadTreePacket", ).and.callFake(function (quadKey, version, request) { - quadKey = defaultValue(quadKey, "") + index.toString(); + quadKey = (quadKey ?? "") + index.toString(); this._tileInfo[quadKey] = new GoogleEarthEnterpriseTileInformation( 0xff, 1, diff --git a/packages/engine/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js b/packages/engine/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js index 57ccdbf5ae7a..9f59459f2f4a 100644 --- a/packages/engine/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js +++ b/packages/engine/Specs/Core/GoogleEarthEnterpriseTerrainProviderSpec.js @@ -1,5 +1,4 @@ import { - defaultValue, Ellipsoid, GeographicTilingScheme, GoogleEarthEnterpriseMetadata, @@ -22,7 +21,7 @@ describe("Core/GoogleEarthEnterpriseTerrainProvider", function () { GoogleEarthEnterpriseMetadata.prototype, "getQuadTreePacket", ).and.callFake(function (quadKey, version) { - quadKey = defaultValue(quadKey, ""); + quadKey = quadKey ?? ""; let t = new GoogleEarthEnterpriseTileInformation(0xff, 1, 1, 1); t.ancestorHasTerrain = true; this._tileInfo[`${quadKey}0`] = t; diff --git a/packages/engine/Specs/Core/PolylineGeometrySpec.js b/packages/engine/Specs/Core/PolylineGeometrySpec.js index 4cbbaac0309f..0bea4775cbfe 100644 --- a/packages/engine/Specs/Core/PolylineGeometrySpec.js +++ b/packages/engine/Specs/Core/PolylineGeometrySpec.js @@ -2,7 +2,6 @@ import { ArcType, Cartesian3, Color, - defaultValue, Ellipsoid, Math as CesiumMath, PolylineGeometry, @@ -282,7 +281,7 @@ describe("Core/PolylineGeometry", function () { colorArray, colorsPerVertex, ) { - colorsPerVertex = defaultValue(colorsPerVertex, false); + colorsPerVertex = colorsPerVertex ?? false; let i; let j; let color; diff --git a/packages/engine/Specs/Core/ResourceSpec.js b/packages/engine/Specs/Core/ResourceSpec.js index c4e50c3d2744..7c3c0a6071c7 100644 --- a/packages/engine/Specs/Core/ResourceSpec.js +++ b/packages/engine/Specs/Core/ResourceSpec.js @@ -1,7 +1,6 @@ import Uri from "urijs"; import { DefaultProxy, - defaultValue, defer, defined, queryToObject, @@ -1967,7 +1966,7 @@ describe("Core/Resource", function () { return resource._makeRequest({ responseType: options.responseType, overrideMimeType: options.overrideMimeType, - method: defaultValue(options.method, "GET"), + method: options.method ?? "GET", data: options.data, }); }; diff --git a/packages/engine/Specs/Core/TimeIntervalCollectionSpec.js b/packages/engine/Specs/Core/TimeIntervalCollectionSpec.js index f365491cb12f..6f9fd108201a 100644 --- a/packages/engine/Specs/Core/TimeIntervalCollectionSpec.js +++ b/packages/engine/Specs/Core/TimeIntervalCollectionSpec.js @@ -1,5 +1,4 @@ import { - defaultValue, Iso8601, JulianDate, TimeInterval, @@ -28,7 +27,7 @@ describe("Core/TimeIntervalCollection", function () { isStopIncluded, dataCallback, ) { - dataCallback = defaultValue(dataCallback, defaultDataCallback); + dataCallback = dataCallback ?? defaultDataCallback; const length = intervals.length; expect(length).toEqual(julianDates.length - 1); for (let i = 0; i < length; ++i) { diff --git a/packages/engine/Specs/Core/defaultValueSpec.js b/packages/engine/Specs/Core/defaultValueSpec.js index f304c8e00943..eaf802f8efea 100644 --- a/packages/engine/Specs/Core/defaultValueSpec.js +++ b/packages/engine/Specs/Core/defaultValueSpec.js @@ -1,15 +1,15 @@ -import { defaultValue } from "../../index.js"; - -describe("Core/defaultValue", function () { - it("Works with first parameter undefined", function () { - expect(defaultValue(undefined, 5)).toEqual(5); - }); - - it("Works with first parameter null", function () { - expect(defaultValue(null, 5)).toEqual(5); - }); - - it("Works with first parameter not undefined and not null", function () { - expect(defaultValue(1, 5)).toEqual(1); - }); -}); +// import { defaultValue } from "../../index.js"; +// +// describe("Core/defaultValue", function () { +// it("Works with first parameter undefined", function () { +// expect(defaultValue(undefined, 5)).toEqual(5); +// }); +// +// it("Works with first parameter null", function () { +// expect(defaultValue(null, 5)).toEqual(5); +// }); +// +// it("Works with first parameter not undefined and not null", function () { +// expect(defaultValue(1, 5)).toEqual(1); +// }); +// }); diff --git a/packages/engine/Specs/DataSources/GpxDataSourceSpec.js b/packages/engine/Specs/DataSources/GpxDataSourceSpec.js old mode 100755 new mode 100644 diff --git a/packages/engine/Specs/DataSources/exportKmlSpec.js b/packages/engine/Specs/DataSources/exportKmlSpec.js index f6bfc44557fe..bc3e138438c9 100644 --- a/packages/engine/Specs/DataSources/exportKmlSpec.js +++ b/packages/engine/Specs/DataSources/exportKmlSpec.js @@ -4,7 +4,6 @@ import { Cartesian3, Cartographic, Color, - defaultValue, defined, Iso8601, JulianDate, @@ -28,7 +27,7 @@ import { describe("DataSources/exportKml", function () { let kmlDoc; function checkKmlDoc(entities, properties, options) { - options = defaultValue(options, {}); + options = options ?? {}; options.entities = entities; const promise = exportKml(options); const kml = kmlDoc.documentElement; diff --git a/packages/engine/Specs/Renderer/AutomaticUniformSpec.js b/packages/engine/Specs/Renderer/AutomaticUniformSpec.js index b994a15a43af..297ae181cbed 100644 --- a/packages/engine/Specs/Renderer/AutomaticUniformSpec.js +++ b/packages/engine/Specs/Renderer/AutomaticUniformSpec.js @@ -3,7 +3,6 @@ import { Cartesian3, Cartographic, Color, - defaultValue, DirectionalLight, DynamicAtmosphereLightingType, Ellipsoid, @@ -44,9 +43,9 @@ describe( up, ) { return { - viewMatrix: defaultValue(view, Matrix4.clone(Matrix4.IDENTITY)), + viewMatrix: view ?? Matrix4.clone(Matrix4.IDENTITY), inverseViewMatrix: Matrix4.inverseTransformation( - defaultValue(view, Matrix4.clone(Matrix4.IDENTITY)), + view ?? Matrix4.clone(Matrix4.IDENTITY), new Matrix4(), ), frustum: { @@ -56,14 +55,9 @@ describe( bottom: -2.0, left: -1.0, right: 1.0, - projectionMatrix: defaultValue( - projection, - Matrix4.clone(Matrix4.IDENTITY), - ), - infiniteProjectionMatrix: defaultValue( - infiniteProjection, - Matrix4.clone(Matrix4.IDENTITY), - ), + projectionMatrix: projection ?? Matrix4.clone(Matrix4.IDENTITY), + infiniteProjectionMatrix: + infiniteProjection ?? Matrix4.clone(Matrix4.IDENTITY), computeCullingVolume: function () { return undefined; }, @@ -71,14 +65,11 @@ describe( return new Cartesian2(1.0, 0.1); }, }, - position: defaultValue(position, Cartesian3.clone(Cartesian3.ZERO)), - positionWC: defaultValue(position, Cartesian3.clone(Cartesian3.ZERO)), - directionWC: defaultValue( - direction, - Cartesian3.clone(Cartesian3.UNIT_Z), - ), - rightWC: defaultValue(right, Cartesian3.clone(Cartesian3.UNIT_X)), - upWC: defaultValue(up, Cartesian3.clone(Cartesian3.UNIT_Y)), + position: position ?? Cartesian3.clone(Cartesian3.ZERO), + positionWC: position ?? Cartesian3.clone(Cartesian3.ZERO), + directionWC: direction ?? Cartesian3.clone(Cartesian3.UNIT_Z), + rightWC: right ?? Cartesian3.clone(Cartesian3.UNIT_X), + upWC: up ?? Cartesian3.clone(Cartesian3.UNIT_Y), positionCartographic: new Cartographic(0.0, 0.0, 10.0), }; } diff --git a/packages/engine/Specs/Scene/CameraSpec.js b/packages/engine/Specs/Scene/CameraSpec.js index c56dccef6e45..b212481ec517 100644 --- a/packages/engine/Specs/Scene/CameraSpec.js +++ b/packages/engine/Specs/Scene/CameraSpec.js @@ -4,7 +4,6 @@ import { Cartesian3, Cartesian4, Cartographic, - defaultValue, Ellipsoid, GeographicProjection, HeadingPitchRange, @@ -45,7 +44,7 @@ describe("Scene/Camera", function () { }; this.drawingBufferWidth = 1024; this.drawingBufferHeight = 768; - this.mapProjection = defaultValue(projection, new GeographicProjection()); + this.mapProjection = projection ?? new GeographicProjection(); this.tweens = new TweenCollection(); this.screenSpaceCameraController = { minimumZoomDistance: 0, diff --git a/packages/engine/Specs/Scene/DebugAppearanceSpec.js b/packages/engine/Specs/Scene/DebugAppearanceSpec.js index 4301b7025c18..d0f747bc05c5 100644 --- a/packages/engine/Specs/Scene/DebugAppearanceSpec.js +++ b/packages/engine/Specs/Scene/DebugAppearanceSpec.js @@ -1,6 +1,5 @@ import { ComponentDatatype, - defaultValue, GeometryInstance, GeometryInstanceAttribute, Rectangle, @@ -42,7 +41,7 @@ describe( function createInstance(vertexFormat) { return new GeometryInstance({ geometry: new RectangleGeometry({ - vertexFormat: defaultValue(vertexFormat, VertexFormat.ALL), + vertexFormat: vertexFormat ?? VertexFormat.ALL, rectangle: rectangle, }), }); diff --git a/packages/engine/Specs/Scene/GlobeSurfaceTileProviderSpec.js b/packages/engine/Specs/Scene/GlobeSurfaceTileProviderSpec.js index a108ae40c1e0..6e0b5459842b 100644 --- a/packages/engine/Specs/Scene/GlobeSurfaceTileProviderSpec.js +++ b/packages/engine/Specs/Scene/GlobeSurfaceTileProviderSpec.js @@ -5,7 +5,6 @@ import { Color, Credit, CreditDisplay, - defaultValue, defined, Ellipsoid, EllipsoidTerrainProvider, @@ -175,10 +174,9 @@ describe( function (tile) { expect(tile.data.imagery.length).toBeGreaterThan(0); for (let i = 0; i < tile.data.imagery.length; ++i) { - const imagery = defaultValue( - tile.data.imagery[i].readyImagery, - tile.data.imagery[i].loadingImagery, - ); + const imagery = + tile.data.imagery[i].readyImagery ?? + tile.data.imagery[i].loadingImagery; expect(imagery.imageryLayer).toEqual(layer); } }, @@ -254,10 +252,9 @@ describe( let indexOfLastLayer1 = -1; let indexOfFirstLayer2 = tile.data.imagery.length; for (let i = 0; i < tile.data.imagery.length; ++i) { - const imagery = defaultValue( - tile.data.imagery[i].readyImagery, - tile.data.imagery[i].loadingImagery, - ); + const imagery = + tile.data.imagery[i].readyImagery ?? + tile.data.imagery[i].loadingImagery; if (imagery.imageryLayer === layer1) { indexOfFirstLayer1 = Math.min(indexOfFirstLayer1, i); indexOfLastLayer1 = i; diff --git a/packages/engine/Specs/Scene/GltfLoaderSpec.js b/packages/engine/Specs/Scene/GltfLoaderSpec.js index 8a6bae03d5c7..78ec829a8ed8 100644 --- a/packages/engine/Specs/Scene/GltfLoaderSpec.js +++ b/packages/engine/Specs/Scene/GltfLoaderSpec.js @@ -194,9 +194,9 @@ describe( } async function loadGltf(gltfPath, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const gltfLoader = new GltfLoader(getOptions(gltfPath, options)); - const targetScene = defaultValue(options.scene, scene); + const targetScene = options.scene ?? scene; gltfLoaders.push(gltfLoader); await gltfLoader.load(); await waitForLoaderProcess(gltfLoader, targetScene); @@ -2187,12 +2187,9 @@ describe( }); function verifyBoxInstancedAttributes(loader, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const interleaved = defaultValue(options.interleaved, false); - const instancingDisabled = defaultValue( - options.instancingDisabled, - false, - ); + options = options ?? defaultValue.EMPTY_OBJECT; + const interleaved = options.interleaved ?? false; + const instancingDisabled = options.instancingDisabled ?? false; const components = loader.components; const scene = components.scene; diff --git a/packages/engine/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js b/packages/engine/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js index 416514c4a68e..1c563af317c5 100644 --- a/packages/engine/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js +++ b/packages/engine/Specs/Scene/GoogleEarthEnterpriseImageryProviderSpec.js @@ -1,7 +1,6 @@ import Uri from "urijs"; import { decodeGoogleEarthEnterpriseData, - defaultValue, defined, DiscardMissingTileImagePolicy, GeographicTilingScheme, @@ -58,7 +57,7 @@ describe("Scene/GoogleEarthEnterpriseImageryProvider", function () { GoogleEarthEnterpriseMetadata.prototype, "getQuadTreePacket", ).and.callFake(function (quadKey, version) { - quadKey = defaultValue(quadKey, ""); + quadKey = quadKey ?? ""; this._tileInfo[`${quadKey}0`] = new GoogleEarthEnterpriseTileInformation( 0xff, 1, diff --git a/packages/engine/Specs/Scene/ImplicitTileCoordinatesSpec.js b/packages/engine/Specs/Scene/ImplicitTileCoordinatesSpec.js index 5f941647832a..6699c9cb6585 100644 --- a/packages/engine/Specs/Scene/ImplicitTileCoordinatesSpec.js +++ b/packages/engine/Specs/Scene/ImplicitTileCoordinatesSpec.js @@ -1,5 +1,4 @@ import { - defaultValue, ImplicitSubdivisionScheme, ImplicitTileCoordinates, } from "../../index.js"; @@ -16,7 +15,7 @@ describe("Scene/ImplicitTileCoordinates", function () { function quadtreeCoordinates(level, x, y, subtreeLevels) { return new ImplicitTileCoordinates({ subdivisionScheme: ImplicitSubdivisionScheme.QUADTREE, - subtreeLevels: defaultValue(subtreeLevels, 2), + subtreeLevels: subtreeLevels ?? 2, level: level, x: x, y: y, @@ -35,7 +34,7 @@ describe("Scene/ImplicitTileCoordinates", function () { function octreeCoordinates(level, x, y, z, subtreeLevels) { return new ImplicitTileCoordinates({ subdivisionScheme: ImplicitSubdivisionScheme.OCTREE, - subtreeLevels: defaultValue(subtreeLevels, 2), + subtreeLevels: subtreeLevels ?? 2, level: level, x: x, y: y, diff --git a/packages/engine/Specs/Scene/IonImageryProviderSpec.js b/packages/engine/Specs/Scene/IonImageryProviderSpec.js index 4b8a589ac020..d5561a092e80 100644 --- a/packages/engine/Specs/Scene/IonImageryProviderSpec.js +++ b/packages/engine/Specs/Scene/IonImageryProviderSpec.js @@ -1,6 +1,5 @@ import { Credit, - defaultValue, IonResource, RequestScheduler, Resource, @@ -19,12 +18,12 @@ import { describe("Scene/IonImageryProvider", function () { async function createTestProviderAsync(endpointData) { - endpointData = defaultValue(endpointData, { + endpointData = endpointData ?? { type: "IMAGERY", url: "http://test.invalid/layer", accessToken: "not_really_a_refresh_token", attributions: [], - }); + }; const assetId = 12335; const options = {}; diff --git a/packages/engine/Specs/Scene/MaterialAppearanceSpec.js b/packages/engine/Specs/Scene/MaterialAppearanceSpec.js index bad1a970b4c4..f5601b483396 100644 --- a/packages/engine/Specs/Scene/MaterialAppearanceSpec.js +++ b/packages/engine/Specs/Scene/MaterialAppearanceSpec.js @@ -1,7 +1,6 @@ import { Color, ColorGeometryInstanceAttribute, - defaultValue, GeometryInstance, Rectangle, RectangleGeometry, @@ -38,10 +37,8 @@ describe( }); function createPrimitive(vertexFormat) { - vertexFormat = defaultValue( - vertexFormat, - MaterialAppearance.MaterialSupport.ALL.vertexFormat, - ); + vertexFormat = + vertexFormat ?? MaterialAppearance.MaterialSupport.ALL.vertexFormat; primitive = new Primitive({ geometryInstances: new GeometryInstance({ geometry: new RectangleGeometry({ diff --git a/packages/engine/Specs/Scene/MaterialSpec.js b/packages/engine/Specs/Scene/MaterialSpec.js index 9b940ef30994..17348b402bba 100644 --- a/packages/engine/Specs/Scene/MaterialSpec.js +++ b/packages/engine/Specs/Scene/MaterialSpec.js @@ -1,7 +1,6 @@ import { Cartesian3, Color, - defaultValue, defined, Ellipsoid, GeometryInstance, @@ -84,7 +83,7 @@ describe( }); function renderMaterial(material, ignoreBackground, callback) { - ignoreBackground = defaultValue(ignoreBackground, false); + ignoreBackground = ignoreBackground ?? false; polygon.appearance.material = material; if (!ignoreBackground) { expect(scene).toRender(backgroundColor); diff --git a/packages/engine/Specs/Scene/MetadataTablePropertySpec.js b/packages/engine/Specs/Scene/MetadataTablePropertySpec.js index 1d64a16bc1d0..a4f5a81b75ac 100644 --- a/packages/engine/Specs/Scene/MetadataTablePropertySpec.js +++ b/packages/engine/Specs/Scene/MetadataTablePropertySpec.js @@ -320,7 +320,7 @@ describe("Scene/MetadataTableProperty", function () { }); function testGetUint64(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const disableBigIntSupport = options.disableBigIntSupport; const disableBigUint64ArraySupport = options.disableBigUint64ArraySupport; @@ -358,7 +358,7 @@ describe("Scene/MetadataTableProperty", function () { } function testGetInt64(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const disableBigIntSupport = options.disableBigIntSupport; const disableBigInt64ArraySupport = options.disableBigInt64ArraySupport; diff --git a/packages/engine/Specs/Scene/Model/AlphaPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/AlphaPipelineStageSpec.js index de6ed67e7d2d..ff70a04da3f5 100644 --- a/packages/engine/Specs/Scene/Model/AlphaPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/AlphaPipelineStageSpec.js @@ -1,7 +1,6 @@ import { AlphaPipelineStage, BlendingState, - defaultValue, ModelAlphaOptions, Pass, RenderState, @@ -22,7 +21,7 @@ describe( return { model: mockModel, shaderBuilder: new ShaderBuilder(), - alphaOptions: defaultValue(alphaOptions, new ModelAlphaOptions()), + alphaOptions: alphaOptions ?? new ModelAlphaOptions(), uniformMap: {}, renderStateOptions: RenderState.getState(RenderState.fromCache()), }; diff --git a/packages/engine/Specs/Scene/Model/ClassificationModelDrawCommandSpec.js b/packages/engine/Specs/Scene/Model/ClassificationModelDrawCommandSpec.js index adfa295c7948..6d86ab5906f2 100644 --- a/packages/engine/Specs/Scene/Model/ClassificationModelDrawCommandSpec.js +++ b/packages/engine/Specs/Scene/Model/ClassificationModelDrawCommandSpec.js @@ -6,7 +6,6 @@ import { ClassificationType, clone, Color, - defaultValue, DepthFunction, DrawCommand, Matrix4, @@ -52,8 +51,8 @@ describe( }; function mockRenderResources(options) { - const debugWireframe = defaultValue(options.debugWireframe, false); - const allowPicking = defaultValue(options.allowPicking, false); + const debugWireframe = options.debugWireframe ?? false; + const allowPicking = options.allowPicking ?? false; return { model: { classificationType: options.classificationType, @@ -71,7 +70,7 @@ describe( } function createDrawCommand(options) { - options = defaultValue(options, {}); + options = options ?? {}; options.modelMatrix = Matrix4.clone(Matrix4.IDENTITY); const boundingSphere = new BoundingSphere(Cartesian3.ZERO, 1.0); @@ -81,10 +80,7 @@ describe( boundingSphere, ); - options.renderState = defaultValue( - options.renderState, - RenderState.fromCache(), - ); + options.renderState = options.renderState ?? RenderState.fromCache(); options.pass = Pass.OPAQUE; options.uniformMap = {}; @@ -98,7 +94,7 @@ describe( expectedStencilFunction, testForPicking, ) { - testForPicking = defaultValue(testForPicking, false); + testForPicking = testForPicking ?? false; expect(command.pass).toBe(expectedPass); expect(command.pickId).toBeUndefined(); @@ -155,7 +151,7 @@ describe( expectedColorCommandBlending.color = noColor; function verifyColorCommand(command, expectedPass, testForPicking) { - testForPicking = defaultValue(testForPicking, false); + testForPicking = testForPicking ?? false; expect(command.pass).toBe(expectedPass); @@ -223,7 +219,7 @@ describe( const numBatches = batchLengths.length; expect(commandList.length).toEqual(numBatches * 2); - testForPicking = defaultValue(testForPicking, false); + testForPicking = testForPicking ?? false; for (let i = 0; i < numBatches; i++) { const stencilDepthCommand = commandList[i * 2]; diff --git a/packages/engine/Specs/Scene/Model/Model3DTileContentSpec.js b/packages/engine/Specs/Scene/Model/Model3DTileContentSpec.js index 289dc253d350..06b047d78b1b 100644 --- a/packages/engine/Specs/Scene/Model/Model3DTileContentSpec.js +++ b/packages/engine/Specs/Scene/Model/Model3DTileContentSpec.js @@ -13,7 +13,6 @@ import { Color, ColorGeometryInstanceAttribute, ContentMetadata, - defaultValue, destroyObject, Ellipsoid, GeometryInstance, @@ -200,7 +199,7 @@ describe( }); function picksGeoJson(url, hasProperties, expectedFeatureId) { - expectedFeatureId = defaultValue(expectedFeatureId, 0); + expectedFeatureId = expectedFeatureId ?? 0; return Cesium3DTilesTester.loadTileset(scene, url).then( function (tileset) { const content = tileset.root.content; diff --git a/packages/engine/Specs/Scene/Model/ModelDrawCommandSpec.js b/packages/engine/Specs/Scene/Model/ModelDrawCommandSpec.js index 565e227470e5..16f04b8e31be 100644 --- a/packages/engine/Specs/Scene/Model/ModelDrawCommandSpec.js +++ b/packages/engine/Specs/Scene/Model/ModelDrawCommandSpec.js @@ -57,12 +57,12 @@ describe( }; function mockModel(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const modelColor = defaultValue(options.color, Color.WHITE); - const silhouetteColor = defaultValue(options.silhouetteColor, Color.RED); - const silhouetteSize = defaultValue(options.silhouetteSize, 0.0); - const skipLevelOfDetail = defaultValue(options.skipLevelOfDetail, false); + const modelColor = options.color ?? Color.WHITE; + const silhouetteColor = options.silhouetteColor ?? Color.RED; + const silhouetteSize = options.silhouetteSize ?? 0.0; + const skipLevelOfDetail = options.skipLevelOfDetail ?? false; return { sceneGraph: { @@ -100,7 +100,7 @@ describe( } function mockRenderResources(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const model = mockModel(options.modelOptions); const resources = { @@ -117,10 +117,8 @@ describe( hasSkipLevelOfDetail: model.hasSkipLevelOfDetail(), }; - const boundingSphereTransform2D = defaultValue( - options.boundingSphereTransform2D, - Matrix4.IDENTITY, - ); + const boundingSphereTransform2D = + options.boundingSphereTransform2D ?? Matrix4.IDENTITY; const sceneGraph = resources.model.sceneGraph; sceneGraph._boundingSphere2D = BoundingSphere.transform( @@ -133,12 +131,10 @@ describe( } function createDrawCommand(options) { - options = defaultValue(options, {}); + options = options ?? {}; - options.modelMatrix = defaultValue( - options.modelMatrix, - Matrix4.clone(Matrix4.IDENTITY), - ); + options.modelMatrix = + options.modelMatrix ?? Matrix4.clone(Matrix4.IDENTITY); const boundingSphere = new BoundingSphere(Cartesian3.ZERO, 1.0); options.boundingVolume = BoundingSphere.transform( @@ -147,17 +143,16 @@ describe( boundingSphere, ); - options.renderState = defaultValue( - options.renderState, + options.renderState = + options.renderState ?? RenderState.fromCache({ depthTest: { enabled: true, func: DepthFunction.LESS_OR_EQUAL, }, - }), - ); + }); - options.pass = defaultValue(options.pass, Pass.OPAQUE); + options.pass = options.pass ?? Pass.OPAQUE; options.uniformMap = {}; return new DrawCommand(options); @@ -176,7 +171,7 @@ describe( // Creates a ModelDrawCommand with the specified derived commands. function createModelDrawCommand(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const deriveSilhouette = options.deriveSilhouette; const derive2D = options.derive2D; @@ -232,22 +227,19 @@ describe( function verifyDerivedCommandsDefined(drawCommand, expected) { // Verify if the translucent command is defined / undefined. - const translucentDefined = defaultValue(expected.translucent, false); + const translucentDefined = expected.translucent ?? false; const translucentCommand = drawCommand._translucentCommand; expect(defined(translucentCommand)).toBe(translucentDefined); // Verify if the skip level of detail commands are defined / undefined. - const skipLevelOfDetailDefined = defaultValue( - expected.skipLevelOfDetail, - false, - ); + const skipLevelOfDetailDefined = expected.skipLevelOfDetail ?? false; const skipLodBackfaceCommand = drawCommand._skipLodBackfaceCommand; const skipLodStencilCommand = drawCommand._skipLodStencilCommand; expect(defined(skipLodBackfaceCommand)).toBe(skipLevelOfDetailDefined); expect(defined(skipLodStencilCommand)).toBe(skipLevelOfDetailDefined); // Verify if the silhouette commands are defined / undefined. - const silhouetteDefined = defaultValue(expected.silhouette, false); + const silhouetteDefined = expected.silhouette ?? false; const silhouetteModelCommand = drawCommand._silhouetteModelCommand; const silhouetteColorCommand = drawCommand._silhouetteColorCommand; expect(defined(silhouetteModelCommand)).toBe(silhouetteDefined); diff --git a/packages/engine/Specs/Scene/Model/ModelRuntimeNodeSpec.js b/packages/engine/Specs/Scene/Model/ModelRuntimeNodeSpec.js index 6f73a0ca076c..67bb34860a04 100644 --- a/packages/engine/Specs/Scene/Model/ModelRuntimeNodeSpec.js +++ b/packages/engine/Specs/Scene/Model/ModelRuntimeNodeSpec.js @@ -1,7 +1,6 @@ import { Axis, Cartesian3, - defaultValue, InstancingPipelineStage, Matrix3, Matrix4, @@ -42,7 +41,7 @@ describe("Scene/Model/ModelRuntimeNode", function () { runtimeNode, originalTransform, ) { - originalTransform = defaultValue(originalTransform, transform); + originalTransform = originalTransform ?? transform; expect(runtimeNode.transform).toEqual(transform); expect(runtimeNode.originalTransform).toEqual(originalTransform); diff --git a/packages/engine/Specs/Scene/Model/ModelSpec.js b/packages/engine/Specs/Scene/Model/ModelSpec.js index 7af9758fdad9..aaf484b7237c 100644 --- a/packages/engine/Specs/Scene/Model/ModelSpec.js +++ b/packages/engine/Specs/Scene/Model/ModelSpec.js @@ -166,7 +166,7 @@ describe( }); function zoomTo(model, zoom) { - zoom = defaultValue(zoom, 4.0); + zoom = zoom ?? 4.0; const camera = scene.camera; const center = model.boundingSphere.center; @@ -182,24 +182,21 @@ describe( function verifyRender(model, shouldRender, options) { expect(model.ready).toBe(true); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; - const zoomToModel = defaultValue(options.zoomToModel, true); + const zoomToModel = options.zoomToModel ?? true; if (zoomToModel) { zoomTo(model); } - const backgroundColor = defaultValue( - options.backgroundColor, - Color.BLACK, - ); + const backgroundColor = options.backgroundColor ?? Color.BLACK; - const targetScene = defaultValue(options.scene, scene); + const targetScene = options.scene ?? scene; targetScene.backgroundColor = backgroundColor; const backgroundColorBytes = backgroundColor.toBytes(scratchBytes); - const time = defaultValue(options.time, defaultDate); + const time = options.time ?? defaultDate; expect({ scene: targetScene, @@ -216,9 +213,9 @@ describe( } function verifyDebugWireframe(model, primitiveType, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); - const modelHasIndices = defaultValue(options.hasIndices, true); - const targetScene = defaultValue(options.scene, scene); + options = options ?? defaultValue.EMPTY_OBJECT; + const modelHasIndices = options.hasIndices ?? true; + const targetScene = options.scene ?? scene; const commandList = targetScene.frameState.commandList; const commandCounts = []; diff --git a/packages/engine/Specs/Scene/Model/PntsLoaderSpec.js b/packages/engine/Specs/Scene/Model/PntsLoaderSpec.js index f3ac4d570a39..d6e15568b3bf 100644 --- a/packages/engine/Specs/Scene/Model/PntsLoaderSpec.js +++ b/packages/engine/Specs/Scene/Model/PntsLoaderSpec.js @@ -80,7 +80,7 @@ describe( }); async function loadPntsArrayBuffer(arrayBuffer, options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const loader = new PntsLoader({ arrayBuffer: arrayBuffer, loadAttributesFor2D: options.loadAttributesFor2D, diff --git a/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js b/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js index 11cf22014bd7..20731ce8b88b 100644 --- a/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js +++ b/packages/engine/Specs/Scene/Model/PointCloudStylingPipelineStageSpec.js @@ -3,7 +3,6 @@ import { Cartesian3, Cesium3DTileRefine, Cesium3DTileStyle, - defaultValue, Math as CesiumMath, Matrix4, ModelType, @@ -78,10 +77,8 @@ describe( } function mockPntsRenderResources(options) { - const pointCloudShading = defaultValue( - options.pointCloudShading, - new PointCloudShading(), - ); + const pointCloudShading = + options.pointCloudShading ?? new PointCloudShading(); const shaderBuilder = new ShaderBuilder(); const uniformMap = {}; const mockModel = { diff --git a/packages/engine/Specs/Scene/MultifrustumSpec.js b/packages/engine/Specs/Scene/MultifrustumSpec.js index f981a3de2845..5eeb2ffb5e34 100644 --- a/packages/engine/Specs/Scene/MultifrustumSpec.js +++ b/packages/engine/Specs/Scene/MultifrustumSpec.js @@ -4,7 +4,6 @@ import { Cartesian2, Cartesian3, Color, - defaultValue, defined, destroyObject, GeometryPipeline, @@ -207,8 +206,8 @@ describe( }); function createPrimitive(bounded, closestFrustum) { - bounded = defaultValue(bounded, true); - closestFrustum = defaultValue(closestFrustum, false); + bounded = bounded ?? true; + closestFrustum = closestFrustum ?? false; function Primitive() { this._va = undefined; diff --git a/packages/engine/Specs/Scene/PrimitiveCollectionSpec.js b/packages/engine/Specs/Scene/PrimitiveCollectionSpec.js index 2a3394e1274f..625251ebec69 100644 --- a/packages/engine/Specs/Scene/PrimitiveCollectionSpec.js +++ b/packages/engine/Specs/Scene/PrimitiveCollectionSpec.js @@ -1,6 +1,5 @@ import { ColorGeometryInstanceAttribute, - defaultValue, defined, GeometryInstance, Rectangle, @@ -59,11 +58,11 @@ describe( } function createLabels(position) { - position = defaultValue(position, { + position = position ?? { x: -1.0, y: 0.0, z: 0.0, - }); + }; const labels = new LabelCollection(); labels.add({ position: position, diff --git a/packages/engine/Specs/Scene/PrimitiveCullingSpec.js b/packages/engine/Specs/Scene/PrimitiveCullingSpec.js index de04c8934e0c..c6d5e3a1a8ea 100644 --- a/packages/engine/Specs/Scene/PrimitiveCullingSpec.js +++ b/packages/engine/Specs/Scene/PrimitiveCullingSpec.js @@ -2,7 +2,6 @@ import { Cartesian3, Color, ColorGeometryInstanceAttribute, - defaultValue, defined, GeometryInstance, Math as CesiumMath, @@ -116,7 +115,7 @@ describe( } function createPrimitive(height) { - height = defaultValue(height, 0); + height = height ?? 0; const primitive = new Primitive({ geometryInstances: new GeometryInstance({ geometry: new RectangleGeometry({ @@ -168,7 +167,7 @@ describe( } function createLabels(height) { - height = defaultValue(height, 0); + height = height ?? 0; const labels = new LabelCollection(); const center = Cartesian3.fromDegrees(-96.5, 33.5, height); labels.modelMatrix = Transforms.eastNorthUpToFixedFrame(center); @@ -233,7 +232,7 @@ describe( }); function createBillboard(height) { - height = defaultValue(height, 0); + height = height ?? 0; const billboards = new BillboardCollection(); billboards.add({ position: Cartesian3.fromDegrees(-96.5, 33.5, height), @@ -297,7 +296,7 @@ describe( }); function createPolylines(height) { - height = defaultValue(height, 0); + height = height ?? 0; const material = Material.fromType("Color"); material.translucent = false; diff --git a/packages/engine/Specs/Scene/TimeDynamicPointCloudSpec.js b/packages/engine/Specs/Scene/TimeDynamicPointCloudSpec.js index d43be3ed576e..0daeb2b35ff5 100644 --- a/packages/engine/Specs/Scene/TimeDynamicPointCloudSpec.js +++ b/packages/engine/Specs/Scene/TimeDynamicPointCloudSpec.js @@ -3,7 +3,6 @@ import { Cartesian3, Clock, ClockStep, - defaultValue, defined, HeadingPitchRange, HeadingPitchRoll, @@ -114,9 +113,9 @@ describe( } function createTimeDynamicPointCloud(options) { - options = defaultValue(options, {}); - const useTransforms = defaultValue(options.useTransforms, false); - const useDraco = defaultValue(options.useDraco, false); + options = options ?? {}; + const useTransforms = options.useTransforms ?? false; + const useDraco = options.useDraco ?? false; options.intervals = createIntervals(useTransforms, useDraco); options.clock = clock; if (!defined(options.style)) { @@ -133,7 +132,7 @@ describe( } function loadFrame(pointCloud, index) { - index = defaultValue(index, 0); + index = index ?? 0; goToFrame(index); return pollToPromise(function () { scene.renderForSpecs(); diff --git a/packages/engine/Specs/Widget/CesiumWidgetSpec.js b/packages/engine/Specs/Widget/CesiumWidgetSpec.js index 00fc6aef71fe..f1382ee3e151 100644 --- a/packages/engine/Specs/Widget/CesiumWidgetSpec.js +++ b/packages/engine/Specs/Widget/CesiumWidgetSpec.js @@ -72,12 +72,9 @@ describe( }; function createCesiumWidget(container, options) { - options = defaultValue(options, {}); - options.contextOptions = defaultValue(options.contextOptions, {}); - options.contextOptions.webgl = defaultValue( - options.contextOptions.webgl, - {}, - ); + options = options ?? {}; + options.contextOptions = options.contextOptions ?? {}; + options.contextOptions.webgl = options.contextOptions.webgl ?? {}; if (!!window.webglStub) { options.contextOptions.getWebGLStub = getWebGLStub; } diff --git a/packages/widgets/Source/BaseLayerPicker/BaseLayerPickerViewModel.js b/packages/widgets/Source/BaseLayerPicker/BaseLayerPickerViewModel.js index 3297b1f97a56..47ca6538e4c1 100644 --- a/packages/widgets/Source/BaseLayerPicker/BaseLayerPickerViewModel.js +++ b/packages/widgets/Source/BaseLayerPicker/BaseLayerPickerViewModel.js @@ -25,17 +25,11 @@ import createCommand from "../createCommand.js"; * @exception {DeveloperError} terrainProviderViewModels must be an array. */ function BaseLayerPickerViewModel(options) { - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const globe = options.globe; - const imageryProviderViewModels = defaultValue( - options.imageryProviderViewModels, - [], - ); - const terrainProviderViewModels = defaultValue( - options.terrainProviderViewModels, - [], - ); + const imageryProviderViewModels = options.imageryProviderViewModels ?? []; + const terrainProviderViewModels = options.terrainProviderViewModels ?? []; //>>includeStart('debug', pragmas.debug); if (!defined(globe)) { @@ -302,10 +296,8 @@ function BaseLayerPickerViewModel(options) { that.dropDownVisible = !that.dropDownVisible; }); - this.selectedImagery = defaultValue( - options.selectedImageryProviderViewModel, - imageryProviderViewModels[0], - ); + this.selectedImagery = + options.selectedImageryProviderViewModel ?? imageryProviderViewModels[0]; this.selectedTerrain = options.selectedTerrainProviderViewModel; } diff --git a/packages/widgets/Source/BaseLayerPicker/ProviderViewModel.js b/packages/widgets/Source/BaseLayerPicker/ProviderViewModel.js index 0e43a3ce5f58..8ac79343f2db 100644 --- a/packages/widgets/Source/BaseLayerPicker/ProviderViewModel.js +++ b/packages/widgets/Source/BaseLayerPicker/ProviderViewModel.js @@ -1,4 +1,4 @@ -import { defaultValue, defined, DeveloperError } from "@cesium/engine"; +import { defined, DeveloperError } from "@cesium/engine"; import knockout from "../ThirdParty/knockout.js"; import createCommand from "../createCommand.js"; @@ -61,7 +61,7 @@ function ProviderViewModel(options) { */ this.iconUrl = options.iconUrl; - this._category = defaultValue(options.category, ""); + this._category = options.category ?? ""; knockout.track(this, ["name", "tooltip", "iconUrl"]); } diff --git a/packages/widgets/Source/FullscreenButton/FullscreenButtonViewModel.js b/packages/widgets/Source/FullscreenButton/FullscreenButtonViewModel.js index eca4b52bce4e..7e4b3e09f414 100644 --- a/packages/widgets/Source/FullscreenButton/FullscreenButtonViewModel.js +++ b/packages/widgets/Source/FullscreenButton/FullscreenButtonViewModel.js @@ -1,5 +1,4 @@ import { - defaultValue, defined, destroyObject, DeveloperError, @@ -82,10 +81,7 @@ function FullscreenButtonViewModel(fullscreenElement, container) { knockout.getObservable(this, "isFullscreenEnabled"), ); - this._fullscreenElement = defaultValue( - getElement(fullscreenElement), - ownerDocument.body, - ); + this._fullscreenElement = getElement(fullscreenElement) ?? ownerDocument.body; this._callback = function () { tmpIsFullscreen(Fullscreen.fullscreen); diff --git a/packages/widgets/Source/Geocoder/GeocoderViewModel.js b/packages/widgets/Source/Geocoder/GeocoderViewModel.js index 441031338431..865b2e0db705 100644 --- a/packages/widgets/Source/Geocoder/GeocoderViewModel.js +++ b/packages/widgets/Source/Geocoder/GeocoderViewModel.js @@ -1,6 +1,5 @@ import { computeFlyToLocationForRectangle, - defaultValue, defined, DeveloperError, destroyObject, @@ -71,7 +70,7 @@ function GeocoderViewModel(options) { }); this._searchCommand = createCommand(function (geocodeType) { - geocodeType = defaultValue(geocodeType, GeocodeType.SEARCH); + geocodeType = geocodeType ?? GeocodeType.SEARCH; that._focusTextbox = false; if (defined(that._selectedSuggestion)) { that.activateSuggestion(that._selectedSuggestion); @@ -153,16 +152,14 @@ function GeocoderViewModel(options) { * @type {boolean} * @default true */ - this.autoComplete = defaultValue(options.autocomplete, true); + this.autoComplete = options.autocomplete ?? true; /** * Gets and sets the command called when a geocode destination is found * @type {Geocoder.DestinationFoundFunction} */ - this.destinationFound = defaultValue( - options.destinationFound, - GeocoderViewModel.flyToDestination, - ); + this.destinationFound = + options.destinationFound ?? GeocoderViewModel.flyToDestination; this._focusTextbox = false; diff --git a/packages/widgets/Source/InspectorShared.js b/packages/widgets/Source/InspectorShared.js index 8fe28ca7b7ca..eafb8151c602 100644 --- a/packages/widgets/Source/InspectorShared.js +++ b/packages/widgets/Source/InspectorShared.js @@ -1,4 +1,4 @@ -import { Check, defaultValue, defined } from "@cesium/engine"; +import { Check, defined } from "@cesium/engine"; /** * A static class with helper functions used by CesiumInspector, Cesium3DTilesInspector, and VoxelInspector @@ -109,7 +109,7 @@ InspectorShared.createRangeInput = function ( Check.typeOf.number("max", max); //>>includeEnd('debug'); - inputValueBinding = defaultValue(inputValueBinding, sliderValueBinding); + inputValueBinding = inputValueBinding ?? sliderValueBinding; const input = document.createElement("input"); input.setAttribute("data-bind", `value: ${inputValueBinding}`); input.type = "number"; @@ -118,7 +118,7 @@ InspectorShared.createRangeInput = function ( slider.type = "range"; slider.min = min; slider.max = max; - slider.step = defaultValue(step, "any"); + slider.step = step ?? "any"; slider.setAttribute( "data-bind", `valueUpdate: "input", value: ${sliderValueBinding}`, diff --git a/packages/widgets/Source/NavigationHelpButton/NavigationHelpButton.js b/packages/widgets/Source/NavigationHelpButton/NavigationHelpButton.js index 1babb8aa1c6d..b71258cdb5c3 100644 --- a/packages/widgets/Source/NavigationHelpButton/NavigationHelpButton.js +++ b/packages/widgets/Source/NavigationHelpButton/NavigationHelpButton.js @@ -1,6 +1,5 @@ import { buildModuleUrl, - defaultValue, defined, destroyObject, DeveloperError, @@ -42,10 +41,7 @@ function NavigationHelpButton(options) { const viewModel = new NavigationHelpButtonViewModel(); - const showInsructionsDefault = defaultValue( - options.instructionsInitiallyVisible, - false, - ); + const showInsructionsDefault = options.instructionsInitiallyVisible ?? false; viewModel.showInstructions = showInsructionsDefault; viewModel._svgPath = diff --git a/packages/widgets/Source/PerformanceWatchdog/PerformanceWatchdogViewModel.js b/packages/widgets/Source/PerformanceWatchdog/PerformanceWatchdogViewModel.js index 653c344c088c..3174eac2c05d 100644 --- a/packages/widgets/Source/PerformanceWatchdog/PerformanceWatchdogViewModel.js +++ b/packages/widgets/Source/PerformanceWatchdog/PerformanceWatchdogViewModel.js @@ -1,5 +1,4 @@ import { - defaultValue, defined, destroyObject, DeveloperError, @@ -33,10 +32,9 @@ function PerformanceWatchdogViewModel(options) { * Gets or sets the message to display when a low frame rate is detected. This string will be interpreted as HTML. * @type {string} */ - this.lowFrameRateMessage = defaultValue( - options.lowFrameRateMessage, - "This application appears to be performing poorly on your system. Please try using a different web browser or updating your video drivers.", - ); + this.lowFrameRateMessage = + options.lowFrameRateMessage ?? + "This application appears to be performing poorly on your system. Please try using a different web browser or updating your video drivers."; /** * Gets or sets a value indicating whether the low frame rate message has previously been dismissed by the user. If it has diff --git a/packages/widgets/Source/SceneModePicker/SceneModePickerViewModel.js b/packages/widgets/Source/SceneModePicker/SceneModePickerViewModel.js index 33884b8902ff..84f2a48f954d 100644 --- a/packages/widgets/Source/SceneModePicker/SceneModePickerViewModel.js +++ b/packages/widgets/Source/SceneModePicker/SceneModePickerViewModel.js @@ -1,5 +1,4 @@ import { - defaultValue, defined, destroyObject, DeveloperError, @@ -36,7 +35,7 @@ function SceneModePickerViewModel(scene, duration) { this._eventHelper = new EventHelper(); this._eventHelper.add(scene.morphStart, morphStart); - this._duration = defaultValue(duration, 2.0); + this._duration = duration ?? 2.0; /** * Gets or sets the current SceneMode. This property is observable. diff --git a/packages/widgets/Source/SelectionIndicator/SelectionIndicatorViewModel.js b/packages/widgets/Source/SelectionIndicator/SelectionIndicatorViewModel.js index e5d5c63137be..0156030dacea 100644 --- a/packages/widgets/Source/SelectionIndicator/SelectionIndicatorViewModel.js +++ b/packages/widgets/Source/SelectionIndicator/SelectionIndicatorViewModel.js @@ -1,6 +1,5 @@ import { Cartesian2, - defaultValue, defined, DeveloperError, EasingFunction, @@ -43,7 +42,7 @@ function SelectionIndicatorViewModel( this._screenPositionX = offScreen; this._screenPositionY = offScreen; this._tweens = scene.tweens; - this._container = defaultValue(container, document.body); + this._container = container ?? document.body; this._selectionIndicatorElement = selectionIndicatorElement; this._scale = 1; diff --git a/packages/widgets/Source/Timeline/TimelineHighlightRange.js b/packages/widgets/Source/Timeline/TimelineHighlightRange.js index de11a00d388d..81a8554ddeae 100644 --- a/packages/widgets/Source/Timeline/TimelineHighlightRange.js +++ b/packages/widgets/Source/Timeline/TimelineHighlightRange.js @@ -1,4 +1,4 @@ -import { defaultValue, JulianDate } from "@cesium/engine"; +import { JulianDate } from "@cesium/engine"; /** * @private @@ -6,7 +6,7 @@ import { defaultValue, JulianDate } from "@cesium/engine"; function TimelineHighlightRange(color, heightInPx, base) { this._color = color; this._height = heightInPx; - this._base = defaultValue(base, 0); + this._base = base ?? 0; } TimelineHighlightRange.prototype.getHeight = function () { diff --git a/packages/widgets/Source/ToggleButtonViewModel.js b/packages/widgets/Source/ToggleButtonViewModel.js index b8f339a16e5c..fc5ce62b807b 100644 --- a/packages/widgets/Source/ToggleButtonViewModel.js +++ b/packages/widgets/Source/ToggleButtonViewModel.js @@ -20,21 +20,21 @@ function ToggleButtonViewModel(command, options) { this._command = command; - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; /** * Gets or sets whether the button is currently toggled. This property is observable. * @type {boolean} * @default false */ - this.toggled = defaultValue(options.toggled, false); + this.toggled = options.toggled ?? false; /** * Gets or sets the button's tooltip. This property is observable. * @type {string} * @default '' */ - this.tooltip = defaultValue(options.tooltip, ""); + this.tooltip = options.tooltip ?? ""; knockout.track(this, ["toggled", "tooltip"]); } diff --git a/packages/widgets/Source/VRButton/VRButtonViewModel.js b/packages/widgets/Source/VRButton/VRButtonViewModel.js index 21cc736d0813..55e3e8efb58c 100644 --- a/packages/widgets/Source/VRButton/VRButtonViewModel.js +++ b/packages/widgets/Source/VRButton/VRButtonViewModel.js @@ -1,5 +1,4 @@ import { - defaultValue, defined, destroyObject, DeveloperError, @@ -156,7 +155,7 @@ function VRButtonViewModel(scene, vrElement) { knockout.getObservable(this, "isVREnabled"), ); - this._vrElement = defaultValue(getElement(vrElement), document.body); + this._vrElement = getElement(vrElement) ?? document.body; this._callback = function () { if (!Fullscreen.fullscreen && isVRMode()) { diff --git a/packages/widgets/Source/Viewer/Viewer.js b/packages/widgets/Source/Viewer/Viewer.js index 41f76c1bb495..e46d69f42992 100644 --- a/packages/widgets/Source/Viewer/Viewer.js +++ b/packages/widgets/Source/Viewer/Viewer.js @@ -103,7 +103,7 @@ function getCesium3DTileFeatureName(feature) { function pickEntity(viewer, e) { const picked = viewer.scene.pick(e.position); if (defined(picked)) { - const id = defaultValue(picked.id, picked.primitive.id); + const id = picked.id ?? picked.primitive.id; if (id instanceof Entity) { return id; } @@ -400,7 +400,7 @@ function Viewer(container, options) { //>>includeEnd('debug'); container = getElement(container); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //>>includeStart('debug', pragmas.debug); if ( @@ -457,7 +457,7 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to viewerContainer.appendChild(bottomContainer); - const scene3DOnly = defaultValue(options.scene3DOnly, false); + const scene3DOnly = options.scene3DOnly ?? false; let clock; let clockViewModel; @@ -634,14 +634,12 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to let baseLayerPicker; let baseLayerPickerDropDown; if (createBaseLayerPicker) { - const imageryProviderViewModels = defaultValue( - options.imageryProviderViewModels, - createDefaultImageryProviderViewModels(), - ); - const terrainProviderViewModels = defaultValue( - options.terrainProviderViewModels, - createDefaultTerrainProviderViewModels(), - ); + const imageryProviderViewModels = + options.imageryProviderViewModels ?? + createDefaultImageryProviderViewModels(); + const terrainProviderViewModels = + options.terrainProviderViewModels ?? + createDefaultTerrainProviderViewModels(); baseLayerPicker = new BaseLayerPicker(toolbar, { globe: scene.globe, @@ -718,10 +716,8 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to } navigationHelpButton = new NavigationHelpButton({ container: toolbar, - instructionsInitiallyVisible: defaultValue( - options.navigationInstructionsInitiallyVisible, - showNavHelp, - ), + instructionsInitiallyVisible: + options.navigationInstructionsInitiallyVisible ?? showNavHelp, }); } @@ -822,6 +818,8 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to this._vrSubscription = vrSubscription; this._vrModeSubscription = vrModeSubscription; this._dataSourceChangedListeners = {}; + this._automaticallyTrackDataSourceClocks = + options.automaticallyTrackDataSourceClocks ?? true; this._container = container; this._bottomContainer = bottomContainer; this._element = viewerContainer; @@ -1845,10 +1843,7 @@ Viewer.prototype._onTick = function (clock) { this.trackedEntity === this.selectedEntity; if (showSelection) { - infoBoxViewModel.titleText = defaultValue( - selectedEntity.name, - selectedEntity.id, - ); + infoBoxViewModel.titleText = selectedEntity.name ?? selectedEntity.id; infoBoxViewModel.description = Property.getValueOrDefault( selectedEntity.description, time, @@ -2014,6 +2009,322 @@ Viewer.prototype.flyTo = function (target, options) { return this._cesiumWidget.flyTo(target, options); }; +function zoomToOrFly(that, zoomTarget, options, isFlight) { + //>>includeStart('debug', pragmas.debug); + if (!defined(zoomTarget)) { + throw new DeveloperError("zoomTarget is required."); + } + //>>includeEnd('debug'); + + cancelZoom(that); + + //We can't actually perform the zoom until all visualization is ready and + //bounding spheres have been computed. Therefore we create and return + //a deferred which will be resolved as part of the post-render step in the + //frame that actually performs the zoom. + const zoomPromise = new Promise((resolve) => { + that._completeZoom = function (value) { + resolve(value); + }; + }); + that._zoomPromise = zoomPromise; + that._zoomIsFlight = isFlight; + that._zoomOptions = options; + + Promise.resolve(zoomTarget).then(function (zoomTarget) { + //Only perform the zoom if it wasn't cancelled before the promise resolved. + if (that._zoomPromise !== zoomPromise) { + return; + } + + //If the zoom target is a rectangular imagery in an ImageLayer + if (zoomTarget instanceof ImageryLayer) { + let rectanglePromise; + + if (defined(zoomTarget.imageryProvider)) { + rectanglePromise = Promise.resolve(zoomTarget.getImageryRectangle()); + } else { + rectanglePromise = new Promise((resolve) => { + const removeListener = zoomTarget.readyEvent.addEventListener(() => { + removeListener(); + resolve(zoomTarget.getImageryRectangle()); + }); + }); + } + rectanglePromise + .then(function (rectangle) { + return computeFlyToLocationForRectangle(rectangle, that.scene); + }) + .then(function (position) { + //Only perform the zoom if it wasn't cancelled before the promise was resolved + if (that._zoomPromise === zoomPromise) { + that._zoomTarget = position; + } + }); + return; + } + + if ( + zoomTarget instanceof Cesium3DTileset || + zoomTarget instanceof TimeDynamicPointCloud || + zoomTarget instanceof VoxelPrimitive + ) { + that._zoomTarget = zoomTarget; + return; + } + + //If the zoom target is a data source, and it's in the middle of loading, wait for it to finish loading. + if (zoomTarget.isLoading && defined(zoomTarget.loadingEvent)) { + const removeEvent = zoomTarget.loadingEvent.addEventListener(function () { + removeEvent(); + + //Only perform the zoom if it wasn't cancelled before the data source finished. + if (that._zoomPromise === zoomPromise) { + that._zoomTarget = zoomTarget.entities.values.slice(0); + } + }); + return; + } + + //Zoom target is already an array, just copy it and return. + if (Array.isArray(zoomTarget)) { + that._zoomTarget = zoomTarget.slice(0); + return; + } + + //If zoomTarget is an EntityCollection, this will retrieve the array + zoomTarget = zoomTarget.values ?? zoomTarget; + + //If zoomTarget is a DataSource, this will retrieve the array. + if (defined(zoomTarget.entities)) { + zoomTarget = zoomTarget.entities.values; + } + + //Zoom target is already an array, just copy it and return. + if (Array.isArray(zoomTarget)) { + that._zoomTarget = zoomTarget.slice(0); + } else { + //Single entity + that._zoomTarget = [zoomTarget]; + } + }); + + that.scene.requestRender(); + return zoomPromise; +} + +function clearZoom(viewer) { + viewer._zoomPromise = undefined; + viewer._zoomTarget = undefined; + viewer._zoomOptions = undefined; +} + +function cancelZoom(viewer) { + const zoomPromise = viewer._zoomPromise; + if (defined(zoomPromise)) { + clearZoom(viewer); + viewer._completeZoom(false); + } +} + +/** + * @private + */ +Viewer.prototype._postRender = function () { + updateZoomTarget(this); + updateTrackedEntity(this); +}; + +function updateZoomTarget(viewer) { + const target = viewer._zoomTarget; + if (!defined(target) || viewer.scene.mode === SceneMode.MORPHING) { + return; + } + + const scene = viewer.scene; + const camera = scene.camera; + const zoomOptions = viewer._zoomOptions ?? {}; + let options; + function zoomToBoundingSphere(boundingSphere) { + // If offset was originally undefined then give it base value instead of empty object + if (!defined(zoomOptions.offset)) { + zoomOptions.offset = new HeadingPitchRange( + 0.0, + -0.5, + boundingSphere.radius, + ); + } + + options = { + offset: zoomOptions.offset, + duration: zoomOptions.duration, + maximumHeight: zoomOptions.maximumHeight, + complete: function () { + viewer._completeZoom(true); + }, + cancel: function () { + viewer._completeZoom(false); + }, + }; + + if (viewer._zoomIsFlight) { + camera.flyToBoundingSphere(target.boundingSphere, options); + } else { + camera.viewBoundingSphere(boundingSphere, zoomOptions.offset); + camera.lookAtTransform(Matrix4.IDENTITY); + + // Finish the promise + viewer._completeZoom(true); + } + + clearZoom(viewer); + } + + if (target instanceof TimeDynamicPointCloud) { + if (defined(target.boundingSphere)) { + zoomToBoundingSphere(target.boundingSphere); + return; + } + + // Otherwise, the first "frame" needs to have been rendered + const removeEventListener = target.frameChanged.addEventListener( + function (timeDynamicPointCloud) { + zoomToBoundingSphere(timeDynamicPointCloud.boundingSphere); + removeEventListener(); + }, + ); + return; + } + + if (target instanceof Cesium3DTileset || target instanceof VoxelPrimitive) { + zoomToBoundingSphere(target.boundingSphere); + return; + } + + // If zoomTarget was an ImageryLayer + if (target instanceof Cartographic) { + options = { + destination: scene.ellipsoid.cartographicToCartesian(target), + duration: zoomOptions.duration, + maximumHeight: zoomOptions.maximumHeight, + complete: function () { + viewer._completeZoom(true); + }, + cancel: function () { + viewer._completeZoom(false); + }, + }; + + if (viewer._zoomIsFlight) { + camera.flyTo(options); + } else { + camera.setView(options); + viewer._completeZoom(true); + } + clearZoom(viewer); + return; + } + + const entities = target; + + const boundingSpheres = []; + for (let i = 0, len = entities.length; i < len; i++) { + const state = viewer._dataSourceDisplay.getBoundingSphere( + entities[i], + false, + boundingSphereScratch, + ); + + if (state === BoundingSphereState.PENDING) { + return; + } else if (state !== BoundingSphereState.FAILED) { + boundingSpheres.push(BoundingSphere.clone(boundingSphereScratch)); + } + } + + if (boundingSpheres.length === 0) { + cancelZoom(viewer); + return; + } + + // Stop tracking the current entity. + viewer.trackedEntity = undefined; + + const boundingSphere = BoundingSphere.fromBoundingSpheres(boundingSpheres); + + if (!viewer._zoomIsFlight) { + camera.viewBoundingSphere(boundingSphere, zoomOptions.offset); + camera.lookAtTransform(Matrix4.IDENTITY); + clearZoom(viewer); + viewer._completeZoom(true); + } else { + clearZoom(viewer); + camera.flyToBoundingSphere(boundingSphere, { + duration: zoomOptions.duration, + maximumHeight: zoomOptions.maximumHeight, + complete: function () { + viewer._completeZoom(true); + }, + cancel: function () { + viewer._completeZoom(false); + }, + offset: zoomOptions.offset, + }); + } +} + +function updateTrackedEntity(viewer) { + if (!viewer._needTrackedEntityUpdate) { + return; + } + + const trackedEntity = viewer._trackedEntity; + const currentTime = viewer.clock.currentTime; + + //Verify we have a current position at this time. This is only triggered if a position + //has become undefined after trackedEntity is set but before the boundingSphere has been + //computed. In this case, we will track the entity once it comes back into existence. + const currentPosition = Property.getValueOrUndefined( + trackedEntity.position, + currentTime, + ); + + if (!defined(currentPosition)) { + return; + } + + const scene = viewer.scene; + + const state = viewer._dataSourceDisplay.getBoundingSphere( + trackedEntity, + false, + boundingSphereScratch, + ); + if (state === BoundingSphereState.PENDING) { + return; + } + + const sceneMode = scene.mode; + if ( + sceneMode === SceneMode.COLUMBUS_VIEW || + sceneMode === SceneMode.SCENE2D + ) { + scene.screenSpaceCameraController.enableTranslate = false; + } + + if ( + sceneMode === SceneMode.COLUMBUS_VIEW || + sceneMode === SceneMode.SCENE3D + ) { + scene.screenSpaceCameraController.enableTilt = false; + } + + const bs = + state !== BoundingSphereState.FAILED ? boundingSphereScratch : undefined; + viewer._entityView = new EntityView(trackedEntity, scene, scene.ellipsoid); + viewer._entityView.update(currentTime, bs); + viewer._needTrackedEntityUpdate = false; +} /** * A function that augments a Viewer instance with additional functionality. * @callback Viewer.ViewerMixin diff --git a/packages/widgets/Source/Viewer/viewerDragDropMixin.js b/packages/widgets/Source/Viewer/viewerDragDropMixin.js index 6e11d882c7b0..32db22f5ed8f 100644 --- a/packages/widgets/Source/Viewer/viewerDragDropMixin.js +++ b/packages/widgets/Source/Viewer/viewerDragDropMixin.js @@ -66,15 +66,15 @@ function viewerDragDropMixin(viewer, options) { } //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; //Local variables to be closed over by defineProperties. let dropEnabled = true; - let flyToOnDrop = defaultValue(options.flyToOnDrop, true); + let flyToOnDrop = options.flyToOnDrop ?? true; const dropError = new Event(); - let clearOnDrop = defaultValue(options.clearOnDrop, true); - let dropTarget = defaultValue(options.dropTarget, viewer.container); - let clampToGround = defaultValue(options.clampToGround, true); + let clearOnDrop = options.clearOnDrop ?? true; + let dropTarget = options.dropTarget ?? viewer.container; + let clampToGround = options.clampToGround ?? true; let proxy = options.proxy; dropTarget = getElement(dropTarget); diff --git a/packages/widgets/Source/Viewer/viewerPerformanceWatchdogMixin.js b/packages/widgets/Source/Viewer/viewerPerformanceWatchdogMixin.js index accaf51a8d55..c6b557a8686c 100644 --- a/packages/widgets/Source/Viewer/viewerPerformanceWatchdogMixin.js +++ b/packages/widgets/Source/Viewer/viewerPerformanceWatchdogMixin.js @@ -28,7 +28,7 @@ function viewerPerformanceWatchdogMixin(viewer, options) { } //>>includeEnd('debug'); - options = defaultValue(options, defaultValue.EMPTY_OBJECT); + options = options ?? defaultValue.EMPTY_OBJECT; const performanceWatchdog = new PerformanceWatchdog({ scene: viewer.scene, diff --git a/packages/widgets/Source/createCommand.js b/packages/widgets/Source/createCommand.js index 305905a3c9c3..f98d7ecacac9 100644 --- a/packages/widgets/Source/createCommand.js +++ b/packages/widgets/Source/createCommand.js @@ -1,4 +1,4 @@ -import { defaultValue, defined, DeveloperError, Event } from "@cesium/engine"; +import { defined, DeveloperError, Event } from "@cesium/engine"; import knockout from "./ThirdParty/knockout.js"; /** @@ -21,7 +21,7 @@ function createCommand(func, canExecute) { } //>>includeEnd('debug'); - canExecute = defaultValue(canExecute, true); + canExecute = canExecute ?? true; const beforeExecute = new Event(); const afterExecute = new Event(); diff --git a/packages/widgets/Specs/createViewer.js b/packages/widgets/Specs/createViewer.js index 6a55487f99aa..bcc65f813c6a 100644 --- a/packages/widgets/Specs/createViewer.js +++ b/packages/widgets/Specs/createViewer.js @@ -1,12 +1,11 @@ -import { defaultValue } from "@cesium/engine"; import { Viewer } from "../index.js"; import getWebGLStub from "../../../Specs/getWebGLStub.js"; function createViewer(container, options) { - options = defaultValue(options, {}); - options.contextOptions = defaultValue(options.contextOptions, {}); - options.contextOptions.webgl = defaultValue(options.contextOptions.webgl, {}); + options = options ?? {}; + options.contextOptions = options.contextOptions ?? {}; + options.contextOptions.webgl = options.contextOptions.webgl ?? {}; if (!!window.webglStub) { options.contextOptions.getWebGLStub = getWebGLStub; } diff --git a/scripts/ContextCache.js b/scripts/ContextCache.js index 6d392d096555..14232eec585a 100644 --- a/scripts/ContextCache.js +++ b/scripts/ContextCache.js @@ -24,4 +24,4 @@ class ContextCache { } } - export default ContextCache; \ No newline at end of file + export default ContextCache; diff --git a/scripts/createRoute.js b/scripts/createRoute.js index 987be17f4314..be9712c76bd4 100644 --- a/scripts/createRoute.js +++ b/scripts/createRoute.js @@ -69,4 +69,4 @@ function createRoute(app, name, route, context, dependantCaches) { return cache; } -export default createRoute; \ No newline at end of file +export default createRoute;