Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 1 addition & 7 deletions src/color/p5.Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
import {
ColorSpace,
to,
toGamut,
serialize,
parse,
range,
Expand Down Expand Up @@ -128,7 +127,7 @@ class Color {
});
this._cachedMode = mode;
this._cachedColor = to(this._cachedColor, this._cachedColor.spaceId);
} catch (err) {
} catch {
// TODO: Invalid color string
throw new Error('Invalid color string');
}
Expand Down Expand Up @@ -305,11 +304,6 @@ class Color {
});
}

// Will do conversion in-Gamut as out of Gamut conversion is only really useful for futher conversions
#toColorMode(mode) {
return new Color(this._color, mode);
}

// Get raw coordinates of underlying library, can differ between libraries
get _array() {
return this._getRGBA();
Expand Down
6 changes: 3 additions & 3 deletions src/core/filterShaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function makeFilterShader(renderer, operation, p5) {
const maxSamples = 64.0;

let numSamples = p5.floor(radius * 7.0);
if (p5.mod(numSamples, 2) == 0.0) {
if (p5.mod(numSamples, 2) === 0.0) {
numSamples++;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ export function makeFilterShader(renderer, operation, p5) {

for (let x = -1; x <= 1; x++) {
for (let y = -1; y <= 1; y++) {
if (x != 0 || y != 0) {
if (x !== 0 || y !== 0) {
const offset = p5.vec2(x, y) * inputs.texelSize;
const neighborColor = p5.getTexture(
canvasContent,
Expand Down Expand Up @@ -198,7 +198,7 @@ export function makeFilterShader(renderer, operation, p5) {

for (let x = -1; x <= 1; x++) {
for (let y = -1; y <= 1; y++) {
if (x != 0 || y != 0) {
if (x !== 0 || y !== 0) {
const offset = p5.vec2(x, y) * inputs.texelSize;
const neighborColor = p5.getTexture(
canvasContent,
Expand Down
4 changes: 2 additions & 2 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,15 @@ class p5 {
for (const p in p5.prototype) {
try {
delete window[p];
} catch (x) {
} catch {
window[p] = undefined;
}
}
for (const p2 in this) {
if (this.hasOwnProperty(p2)) {
try {
delete window[p2];
} catch (x) {
} catch {
window[p2] = undefined;
}
}
Expand Down
20 changes: 0 additions & 20 deletions src/core/p5.Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,25 +447,5 @@ function renderer(p5, fn) {
p5.Renderer = Renderer;
}

/**
* Helper fxn to measure ascent and descent.
* Adapted from http://stackoverflow.com/a/25355178
* @private
*/
function calculateOffset(object) {
let currentLeft = 0,
currentTop = 0;
if (object.offsetParent) {
do {
currentLeft += object.offsetLeft;
currentTop += object.offsetTop;
} while ((object = object.offsetParent));
} else {
currentLeft += object.offsetLeft;
currentTop += object.offsetTop;
}
return [currentLeft, currentTop];
}

export default renderer;
export { Renderer };
4 changes: 1 addition & 3 deletions src/core/p5.Renderer2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { Matrix } from '../math/p5.Matrix';
import { PrimitiveToPath2DConverter } from '../shape/custom_shapes';
import { DefaultFill, textCoreConstants } from '../type/textCore';

const styleEmpty = 'rgba(0,0,0,0)';

class Renderer2D extends Renderer {
constructor(pInst, w, h, isMainCanvas, elt, attributes = {}) {
super(pInst, w, h, isMainCanvas);
Expand Down Expand Up @@ -151,7 +149,7 @@ class Renderer2D extends Renderer {
for (const savedKey in props) {
try {
this.drawingContext[savedKey] = props[savedKey];
} catch (err) {
} catch {
// ignore read-only property errors
}
}
Expand Down
15 changes: 6 additions & 9 deletions src/core/p5.Renderer3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,6 @@ export class Renderer3D extends Renderer {
}
}

remove() {
this.wrappedElt.remove();
this.wrappedElt = null;
this.canvas = null;
this.elt = null;
}

//////////////////////////////////////////////
// Geometry Building
//////////////////////////////////////////////
Expand Down Expand Up @@ -1350,7 +1343,7 @@ export class Renderer3D extends Renderer {
for (const savedKey in props) {
try {
this.drawingContext[savedKey] = props[savedKey];
} catch (err) {
} catch {
// ignore read-only property errors
}
}
Expand Down Expand Up @@ -1933,7 +1926,7 @@ export class Renderer3D extends Renderer {
throw Error('_yAlignOffset: height is required');
}

let { textLeading, textBaseline, textSize, textFont } = this.states;
let { textLeading, textBaseline, textSize } = this.states;
let yOff = 0,
numLines = dataArr.length;
let totalHeight =
Expand Down Expand Up @@ -2175,6 +2168,10 @@ export class Renderer3D extends Renderer {
if (this._textCanvas) {
this._textCanvas.parentElement.removeChild(this._textCanvas);
}
this.wrappedElt.remove();
this.wrappedElt = null;
this.canvas = null;
this.elt = null;
super.remove();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/dom/p5.MediaElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Element } from './p5.Element';
// import { friendlyAutoplayError } from '../friendly_errors/fes_core';
import { FES, TL } from '../friendly_errors/fes';
import { FES } from '../friendly_errors/fes';

/**
* @typedef {'video'} VIDEO
Expand Down Expand Up @@ -934,7 +934,7 @@ class MediaElement extends Element {
try {
audioContext = obj.context;
mainOutput = audioContext.destination;
} catch (e) {
} catch {
throw 'connect() is meant to be used with Web Audio API or p5.sound.js';
}
}
Expand Down Expand Up @@ -1639,7 +1639,7 @@ function media(p5, fn) {
} else {
domElement.src = window.URL.createObjectURL(stream);
}
} catch (err) {
} catch {
domElement.src = stream;
}
})
Expand Down
6 changes: 4 additions & 2 deletions src/friendly_errors/param_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ function validateParams(p5, fn, lifecycles) {
message = FES.log`Expected ${match[1]} at the ${position} parameter in ${func + '()'}.`;
break;
}
// Unrecognized custom errors fall through to the default logging below.
// falls through
}
default: {
console.log('Zod error object', currentError);
Expand All @@ -564,7 +566,7 @@ function validateParams(p5, fn, lifecycles) {
if (isVersionError) {
FES.log`${message}`();
} else {
const [_null, stacktrace] = processStack(
const [, stacktrace] = processStack(
null,
errorStackParser.parse(Error()).slice(3)
);
Expand Down Expand Up @@ -624,7 +626,7 @@ function validateParams(p5, fn, lifecycles) {
success: true,
data: funcSchemas.parse(args)
};
} catch (error) {
} catch {
const closestSchema = findClosestSchema(funcSchemas, args);
const zodError = closestSchema.safeParse(args).error;
const errorMessage = friendlyParamError(zodError, func, args);
Expand Down
8 changes: 2 additions & 6 deletions src/friendly_errors/stacktrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,6 @@ export const processStack = (error, stacktrace) => {
// from user's code
if (friendlyStack.length === 0) return [true, null];

// get the function just above the topmost frame in the friendlyStack.
// i.e the name of the library function called from user's code
const func = stacktrace[friendlyStack[0].frameIndex - 1].functionName
.split('.')
.slice(-1)[0];

// Try and get the location (line no.) from the top element of the stack
let locationObj;
if (
Expand All @@ -351,6 +345,8 @@ export const processStack = (error, stacktrace) => {
}

// Library error
// `func` below is the name of the library function called from user's code,
// i.e. stacktrace[friendlyStack[0].frameIndex - 1].functionName.
// const message = TL.tl`${locationObj ? TL.tl`[${locationObj.file}, line ${locationObj.line}]` : ''} An error with message "${error.message}" occurred inside the p5js library when ${func} was called. If not stated otherwise, it might be an issue with the arguments passed to ${func}.`;
// p5._friendlyError(
// message,
Expand Down
8 changes: 1 addition & 7 deletions src/image/p5.Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ class Image {
if (typeof density !== 'undefined') {
// Setter: set the density and handle resize
if (density <= 0) {
const errorObj = {
type: 'INVALID_VALUE',
format: { types: ['Number'] },
position: 1
};

// p5._friendlyParamError(errorObj, 'pixelDensity');
// TODO: report an INVALID_VALUE param error through the FES here.

// Default to 1 in case of an invalid value
density = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/io/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@ function inferType(value) {
}

function escapeRegExp(str) {
return str.replace(/[-\[\]/\{}\()\*+\?.\\^\$|]/g, '\\$&');
return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&');
}
12 changes: 1 addition & 11 deletions src/io/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,7 @@ function files(p5, fn) {
case 'xml':
// NOTE: still need to normalize type handling/mapping
// datatype = 'xml';
// falls through
case 'txt':
default:
datatype = 'text';
Expand Down Expand Up @@ -2119,17 +2120,6 @@ function files(p5, fn) {
// The following line is CC BY SA 3 by user Fregante https://stackoverflow.com/a/23522755
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
};

/**
* Helper function, a callback for download that deletes
* an invisible anchor element from the DOM once the file
* has been automatically downloaded.
*
* @private
*/
function destroyClickedElement(event) {
document.body.removeChild(event.target);
}
}

export default files;
Expand Down
3 changes: 3 additions & 0 deletions src/math/Matrices/Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,9 @@ export class Matrix extends MatrixInterface {
* @return {Number} Determinant of our 4×4 matrix
* @private
*/
// Kept private until the determinant API is made public; see the skipped
// 'Determinant' tests in test/unit/math/p5.Matrix.js.
// oxlint-disable-next-line no-unused-private-class-members
#determinant4x4() {
if (this.#sqDimention !== 4) {
throw new Error(
Expand Down
2 changes: 0 additions & 2 deletions src/math/Matrices/MatrixInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ if (typeof Float32Array !== 'undefined') {
isMatrixArray = x => Array.isArray(x) || x instanceof Float32Array;
}
export class MatrixInterface {
// Private field to store the matrix
#matrix = null;
constructor(...args) {
if (this.constructor === MatrixInterface) {
throw new Error("Class is of abstract type and can't be instantiated");
Expand Down
7 changes: 1 addition & 6 deletions src/math/Matrices/MatrixNumjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import { MatrixInterface } from './MatrixInterface';
* Reference/Global_Objects/SIMD
*/

let GLMAT_ARRAY_TYPE = Array;
let isMatrixArray = x => Array.isArray(x);
if (typeof Float32Array !== 'undefined') {
GLMAT_ARRAY_TYPE = Float32Array;
isMatrixArray = x => Array.isArray(x) || x instanceof Float32Array;
}

Expand Down Expand Up @@ -131,7 +129,6 @@ export class MatrixNumjs extends MatrixInterface {
* @return {MatrixNumjs} the copy of the MatrixNumjs object
*/
get() {
let temp = new MatrixNumjs(this.mat4);
return new MatrixNumjs(this.mat4);
}

Expand Down Expand Up @@ -522,7 +519,6 @@ export class MatrixNumjs extends MatrixInterface {
x = x[0]; // must be last
}
this._mat4 = this._mat4.flatten();
const vect = nj.array([x, y, z, 1]);
this._mat4.set(0, x * this._mat4.get(0));
this._mat4.set(1, x * this._mat4.get(1));
this._mat4.set(2, x * this._mat4.get(2));
Expand Down Expand Up @@ -805,12 +801,11 @@ export class MatrixNumjs extends MatrixInterface {
* @chainable
*/
mult3x3(multMatrix) {
let _src;
let tempMatrix = multMatrix;
if (multMatrix === this || multMatrix === this._mat3) {
// mat3; // only need to allocate in this rare case
} else if (multMatrix instanceof MatrixNumjs) {
_src = multMatrix.mat3;
// tempMatrix already holds the matrix we need
} else if (isMatrixArray(multMatrix)) {
multMatrix._mat3 = nj.array(arguments);
} else if (arguments.length === 9) {
Expand Down
6 changes: 0 additions & 6 deletions src/strands/ir_dag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
NodeTypeRequiredFields,
NodeTypeToName,
BasePriority,
StatementType,
BaseType
} from './ir_types';
import * as FES from './strands_FES';
Expand Down Expand Up @@ -149,11 +148,6 @@ function createNode(graph, node) {
return id;
}

function getNodeKey(node) {
const key = JSON.stringify(node);
return key;
}

function validateNode(node) {
const nodeType = node.nodeType;
const requiredFields = NodeTypeRequiredFields[nodeType];
Expand Down
4 changes: 2 additions & 2 deletions src/strands/ir_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ export const ConstantFolding = {
[OpCode.Binary.MULTIPLY]: (a, b) => a * b,
[OpCode.Binary.DIVIDE]: (a, b) => a / b,
[OpCode.Binary.MODULO]: (a, b) => a % b,
[OpCode.Binary.EQUAL]: (a, b) => a == b,
[OpCode.Binary.NOT_EQUAL]: (a, b) => a != b,
[OpCode.Binary.EQUAL]: (a, b) => a === b,
[OpCode.Binary.NOT_EQUAL]: (a, b) => a !== b,
[OpCode.Binary.GREATER_THAN]: (a, b) => a > b,
[OpCode.Binary.GREATER_EQUAL]: (a, b) => a >= b,
[OpCode.Binary.LESS_THAN]: (a, b) => a < b,
Expand Down
2 changes: 0 additions & 2 deletions src/strands/strands_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import {
DataType,
BaseType,
structType,
TypeInfoFromGLSLName,
isStructType,
OpCode,
StatementType,
NodeType,
HOOK_PARAM_PREFIX
Expand Down
8 changes: 1 addition & 7 deletions src/strands/strands_codegen.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { sortCFG } from './ir_cfg';
import * as DAG from './ir_dag';
import {
NodeType,
StatementType,
structType,
TypeInfoFromGLSLName
} from './ir_types';
import { structType } from './ir_types';

export function generateShaderCode(strandsContext) {
const {
Expand Down
Loading
Loading