Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use function shorthand in objects #5948

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/guid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const guid = {
*
* @returns {string} A new GUID.
*/
create: function () {
create() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0;
const v = (c === 'x') ? r : (r & 0x3 | 0x8);
Expand Down
30 changes: 15 additions & 15 deletions src/core/math/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const math = {
* @param {number} max - Max value.
* @returns {number} The clamped value.
*/
clamp: function (value, min, max) {
clamp(value, min, max) {
if (value >= max) return max;
if (value <= min) return min;
return value;
Expand All @@ -41,7 +41,7 @@ const math = {
* // Set bytes to [0x11, 0x22, 0x33]
* const bytes = pc.math.intToBytes24(0x112233);
*/
intToBytes24: function (i) {
intToBytes24(i) {
const r = (i >> 16) & 0xff;
const g = (i >> 8) & 0xff;
const b = (i) & 0xff;
Expand All @@ -58,7 +58,7 @@ const math = {
* // Set bytes to [0x11, 0x22, 0x33, 0x44]
* const bytes = pc.math.intToBytes32(0x11223344);
*/
intToBytes32: function (i) {
intToBytes32(i) {
const r = (i >> 24) & 0xff;
const g = (i >> 16) & 0xff;
const b = (i >> 8) & 0xff;
Expand All @@ -81,7 +81,7 @@ const math = {
* // Set result2 to 0x112233 from 3 discrete values
* const result2 = pc.math.bytesToInt24(0x11, 0x22, 0x33);
*/
bytesToInt24: function (r, g, b) {
bytesToInt24(r, g, b) {
if (r.length) {
b = r[2];
g = r[1];
Expand All @@ -105,7 +105,7 @@ const math = {
* // Set result2 to 0x11223344 from 4 discrete values
* const result2 = pc.math.bytesToInt32(0x11, 0x22, 0x33, 0x44);
*/
bytesToInt32: function (r, g, b, a) {
bytesToInt32(r, g, b, a) {
if (r.length) {
a = r[3];
b = r[2];
Expand All @@ -130,7 +130,7 @@ const math = {
* between a and b is returned. alpha is clamped between 0 and 1.
* @returns {number} The linear interpolation of two numbers.
*/
lerp: function (a, b, alpha) {
lerp(a, b, alpha) {
return a + (b - a) * math.clamp(alpha, 0, 1);
},

Expand All @@ -145,7 +145,7 @@ const math = {
* between a and b is returned. alpha is clamped between 0 and 1.
* @returns {number} The linear interpolation of two angles.
*/
lerpAngle: function (a, b, alpha) {
lerpAngle(a, b, alpha) {
if (b - a > 180) {
b -= 360;
}
Expand All @@ -161,7 +161,7 @@ const math = {
* @param {number} x - Number to check for power-of-two property.
* @returns {boolean} true if power-of-two and false otherwise.
*/
powerOfTwo: function (x) {
powerOfTwo(x) {
return ((x !== 0) && !(x & (x - 1)));
},

Expand All @@ -171,7 +171,7 @@ const math = {
* @param {number} val - The value for which to calculate the next power of 2.
* @returns {number} The next power of 2.
*/
nextPowerOfTwo: function (val) {
nextPowerOfTwo(val) {
val--;
val |= (val >> 1);
val |= (val >> 2);
Expand All @@ -188,7 +188,7 @@ const math = {
* @param {number} val - The value for which to calculate the nearest power of 2.
* @returns {number} The nearest power of 2.
*/
nearestPowerOfTwo: function (val) {
nearestPowerOfTwo(val) {
return Math.pow(2, Math.round(Math.log(val) / Math.log(2)));
},

Expand All @@ -200,7 +200,7 @@ const math = {
* @param {number} max - Upper bound for range.
* @returns {number} Pseudo-random number between the supplied range.
*/
random: function (min, max) {
random(min, max) {
const diff = max - min;
return Math.random() * diff + min;
},
Expand All @@ -220,7 +220,7 @@ const math = {
* @param {number} x - The value to interpolate.
* @returns {number} The smoothly interpolated value clamped between zero and one.
*/
smoothstep: function (min, max, x) {
smoothstep(min, max, x) {
if (x <= min) return 0;
if (x >= max) return 1;

Expand All @@ -240,7 +240,7 @@ const math = {
* @param {number} x - The value to interpolate.
* @returns {number} The smoothly interpolated value clamped between zero and one.
*/
smootherstep: function (min, max, x) {
smootherstep(min, max, x) {
if (x <= min) return 0;
if (x >= max) return 1;

Expand All @@ -256,7 +256,7 @@ const math = {
* @param {number} multiple - The multiple to round up to.
* @returns {number} A number rounded up to nearest multiple.
*/
roundUp: function (numToRound, multiple) {
roundUp(numToRound, multiple) {
if (multiple === 0)
return numToRound;
return Math.ceil(numToRound / multiple) * multiple;
Expand All @@ -272,7 +272,7 @@ const math = {
* @returns {boolean} true if between or false otherwise.
* @ignore
*/
between: function (num, a, b, inclusive) {
between(num, a, b, inclusive) {
const min = Math.min(a, b);
const max = Math.max(a, b);
return inclusive ? num >= min && num <= max : num > min && num < max;
Expand Down
8 changes: 4 additions & 4 deletions src/core/math/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const random = {
* @param {import('./vec2.js').Vec2} point - The returned generated point.
* @ignore
*/
circlePoint: function (point) {
circlePoint(point) {
const r = Math.sqrt(Math.random());
const theta = Math.random() * 2 * Math.PI;
point.x = r * Math.cos(theta);
Expand All @@ -32,7 +32,7 @@ const random = {
* @param {number} numPoints - The total number of points of the set.
* @ignore
*/
circlePointDeterministic: function (point, index, numPoints) {
circlePointDeterministic(point, index, numPoints) {
const theta = index * _goldenAngle;
const r = Math.sqrt(index) / Math.sqrt(numPoints);

Expand All @@ -56,7 +56,7 @@ const random = {
* 0 and 1. Defaults to 1.
* @ignore
*/
spherePointDeterministic: function (point, index, numPoints, start = 0, end = 1) {
spherePointDeterministic(point, index, numPoints, start = 0, end = 1) {

// y coordinate needs to go from -1 (top) to 1 (bottom) for the full sphere
// evaluate its value for this point and specified start and end
Expand All @@ -83,7 +83,7 @@ const random = {
* @returns {number} The pseudo-random value.
* @ignore
*/
radicalInverse: function (i) {
radicalInverse(i) {
let bits = ((i << 16) | (i >>> 16)) >>> 0;
bits = (((bits & 0x55555555) << 1) | ((bits & 0xAAAAAAAA) >>> 1)) >>> 0;
bits = (((bits & 0x33333333) << 2) | ((bits & 0xCCCCCCCC) >>> 2)) >>> 0;
Expand Down
16 changes: 8 additions & 8 deletions src/core/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const path = {
* const path = pc.path.join('alpha', 'beta', 'gamma');
* console.log(path); // Prints 'alpha/beta/gamma'
*/
join: function () {
join() {
const num = arguments.length;
let result = arguments[0];

Expand Down Expand Up @@ -57,7 +57,7 @@ const path = {
* @param {string} pathname - The path to normalize.
* @returns {string} The normalized path.
*/
normalize: function (pathname) {
normalize(pathname) {
const lead = pathname.startsWith(path.delimiter);
const trail = pathname.endsWith(path.delimiter);

Expand Down Expand Up @@ -101,7 +101,7 @@ const path = {
* @returns {string[]} The split path which is an array of two strings, the path and the
* filename.
*/
split: function (pathname) {
split(pathname) {
const lastDelimiterIndex = pathname.lastIndexOf(path.delimiter);
if (lastDelimiterIndex !== -1) {
return [pathname.substring(0, lastDelimiterIndex), pathname.substring(lastDelimiterIndex + 1)];
Expand All @@ -119,7 +119,7 @@ const path = {
* pc.path.getBasename("/path/to/file.txt"); // returns "file.txt"
* pc.path.getBasename("/path/to/dir"); // returns "dir"
*/
getBasename: function (pathname) {
getBasename(pathname) {
return path.split(pathname)[1];
},

Expand All @@ -130,7 +130,7 @@ const path = {
* @param {string} pathname - The path to get the directory from.
* @returns {string} The directory part of the path.
*/
getDirectory: function (pathname) {
getDirectory(pathname) {
return path.split(pathname)[0];
},

Expand All @@ -145,7 +145,7 @@ const path = {
* pc.path.getExtension("/path/to/file.jpg"); // returns ".jpg"
* pc.path.getExtension("/path/to/file.txt?function=getExtension"); // returns ".txt"
*/
getExtension: function (pathname) {
getExtension(pathname) {
const ext = pathname.split('?')[0].split('.').pop();
if (ext !== pathname) {
return '.' + ext;
Expand All @@ -168,7 +168,7 @@ const path = {
* pc.path.isRelativePath("/path/to/file.jpg"); // returns false
* pc.path.isRelativePath("http://path/to/file.jpg"); // returns false
*/
isRelativePath: function (pathname) {
isRelativePath(pathname) {
return pathname.charAt(0) !== '/' && pathname.match(/:\/\//) === null;
},

Expand All @@ -183,7 +183,7 @@ const path = {
* pc.path.extractPath("../path/to/file.txt"); // returns "../path/to"
* pc.path.extractPath("/path/to/file.txt"); // returns "/path/to"
*/
extractPath: function (pathname) {
extractPath(pathname) {
let result = '';
const parts = pathname.split('/');
let i = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/framework/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const script = {
* });
* @ignore
*/
create: function (name, callback) {
create(name, callback) {
if (!_legacy)
return;

Expand Down Expand Up @@ -131,7 +131,7 @@ const script = {
* });
* @ignore
*/
attribute: function (name, type, defaultValue, options) {
attribute(name, type, defaultValue, options) {
// only works when parsing the script...
},

Expand All @@ -153,7 +153,7 @@ const script = {
* app.on("start", hideSplashScreen);
* });
*/
createLoadingScreen: function (callback) {
createLoadingScreen(callback) {
if (_createdLoadingScreen)
return;

Expand Down