MCPcopy
hub / github.com/processing/p5.js / constructor

Method constructor

src/math/p5.Vector.js:72–111  ·  view source on GitHub ↗
(...args)

Source from the content-addressed store, hash-verified

70 // This is how it comes in with createVector()
71 // This check if the first argument is a function
72 constructor(...args) {
73
74 if (args.length === 0) {
75 this._friendlyError(
76 'Requires valid arguments.', 'p5.Vector'
77 );
78 }
79
80 if (typeof args[0] === 'function') {
81 this.isPInst = true;
82 this._fromRadians = args.shift();
83 this._toRadians = args.shift();
84 }
85
86 this.values = args;
87 if (Array.isArray(args)) {
88 for (let i = 0; i < args.length; i++) {
89 const v = args[i];
90 if (typeof v !== 'number' || !Number.isFinite(v)) {
91 if (!Vector.friendlyErrorsDisabled()) {
92 this._friendlyError(
93 'Arguments contain non-finite numbers',
94 'p5.Vector'
95 );
96 }
97 this.values = [];
98 break;
99 }
100 }
101 } else {
102 this.values = [];
103 }
104
105 // This property is here where duck typing (checking if obj.isVector) needs
106 // to be used over more standard type checking (obj instanceof Vector). This
107 // needs to happen where we are building multiple files, such as in p5.webgpu.js,
108 // where if we `import { Vector }` directly, it will be a separate copy of the
109 // Vector class from the one imported in the main p5.js bundle.
110 this.isVector = true;
111 }
112
113 // This will get overwritten when exported as part of p5.
114 _friendlyError(_e) {}

Callers

nothing calls this directly

Calls 2

_friendlyErrorMethod · 0.95

Tested by

no test coverage detected