mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-10-14 20:01:28 +00:00
import codes
This commit is contained in:
24
src/utils/cancelToken.ts
Normal file
24
src/utils/cancelToken.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import axios from "axios";
|
||||
const CancelToken = axios.CancelToken;
|
||||
|
||||
export const cancelToken = () =>
|
||||
new CancelToken(function executor(c) {
|
||||
const w = window as any;
|
||||
w.axiosCancel.push(c);
|
||||
});
|
101
src/utils/dateFormat.ts
Normal file
101
src/utils/dateFormat.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
export default function dateFormatStep(
|
||||
date: Date,
|
||||
step: string,
|
||||
monthDayDiff?: boolean
|
||||
): string {
|
||||
const year = date.getFullYear();
|
||||
const monthTemp = date.getMonth() + 1;
|
||||
let month = `${monthTemp}`;
|
||||
if (monthTemp < 10) {
|
||||
month = `0${monthTemp}`;
|
||||
}
|
||||
if (step === "MONTH" && monthDayDiff) {
|
||||
return `${year}-${month}`;
|
||||
}
|
||||
const dayTemp = date.getDate();
|
||||
let day = `${dayTemp}`;
|
||||
if (dayTemp < 10) {
|
||||
day = `0${dayTemp}`;
|
||||
}
|
||||
if (step === "DAY" || step === "MONTH") {
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
const hourTemp = date.getHours();
|
||||
let hour = `${hourTemp}`;
|
||||
if (hourTemp < 10) {
|
||||
hour = `0${hourTemp}`;
|
||||
}
|
||||
if (step === "HOUR") {
|
||||
return `${year}-${month}-${day} ${hour}`;
|
||||
}
|
||||
const minuteTemp = date.getMinutes();
|
||||
let minute = `${minuteTemp}`;
|
||||
if (minuteTemp < 10) {
|
||||
minute = `0${minuteTemp}`;
|
||||
}
|
||||
if (step === "MINUTE") {
|
||||
return `${year}-${month}-${day} ${hour}${minute}`;
|
||||
}
|
||||
const secondTemp = date.getSeconds();
|
||||
let second = `${secondTemp}`;
|
||||
if (secondTemp < 10) {
|
||||
second = `0${secondTemp}`;
|
||||
}
|
||||
if (step === "SECOND") {
|
||||
return `${year}-${month}-${day} ${hour}${minute}${second}`;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export const dateFormatTime = (date: Date, step: string): string => {
|
||||
const year = date.getFullYear();
|
||||
const monthTemp = date.getMonth() + 1;
|
||||
let month = `${monthTemp}`;
|
||||
if (monthTemp < 10) {
|
||||
month = `0${monthTemp}`;
|
||||
}
|
||||
if (step === "MONTH") {
|
||||
return `${year}-${month}`;
|
||||
}
|
||||
const dayTemp = date.getDate();
|
||||
let day = `${dayTemp}`;
|
||||
if (dayTemp < 10) {
|
||||
day = `0${dayTemp}`;
|
||||
}
|
||||
if (step === "DAY") {
|
||||
return `${month}-${day}`;
|
||||
}
|
||||
const hourTemp = date.getHours();
|
||||
let hour = `${hourTemp}`;
|
||||
if (hourTemp < 10) {
|
||||
hour = `0${hourTemp}`;
|
||||
}
|
||||
if (step === "HOUR") {
|
||||
return `${month}-${day} ${hour}`;
|
||||
}
|
||||
const minuteTemp = date.getMinutes();
|
||||
let minute = `${minuteTemp}`;
|
||||
if (minuteTemp < 10) {
|
||||
minute = `0${minuteTemp}`;
|
||||
}
|
||||
if (step === "MINUTE") {
|
||||
return `${hour}:${minute}\n${month}-${day}`;
|
||||
}
|
||||
return "";
|
||||
};
|
44
src/utils/dateTime.ts
Normal file
44
src/utils/dateTime.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Duration } from "@/types/app";
|
||||
import { TimeType } from "@/constants/data";
|
||||
|
||||
/**
|
||||
* init or generate durationRow Obj and save localStorage.
|
||||
*/
|
||||
const getDurationRow = (): Duration => {
|
||||
const durationRowString = localStorage.getItem("durationRow");
|
||||
let durationRow: Duration;
|
||||
if (durationRowString && durationRowString !== "") {
|
||||
durationRow = JSON.parse(durationRowString);
|
||||
durationRow = {
|
||||
start: new Date(durationRow.start),
|
||||
end: new Date(durationRow.end),
|
||||
step: durationRow.step,
|
||||
};
|
||||
} else {
|
||||
durationRow = {
|
||||
start: new Date(new Date().getTime() - 900000),
|
||||
end: new Date(),
|
||||
step: TimeType.MINUTE_TIME,
|
||||
};
|
||||
localStorage.setItem("durationRow", JSON.stringify(durationRow, null, 0));
|
||||
}
|
||||
return durationRow;
|
||||
};
|
||||
|
||||
export default getDurationRow;
|
56
src/utils/localtime.ts
Normal file
56
src/utils/localtime.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import graph from "@/graph";
|
||||
import { AxiosResponse } from "axios";
|
||||
|
||||
const getLocalTime = (utc: string, time: Date): Date => {
|
||||
const utcArr = utc.split(":");
|
||||
const utcHour = isNaN(Number(utcArr[0])) ? 0 : Number(utcArr[0]);
|
||||
const utcMin = isNaN(Number(utcArr[1])) ? 0 : Number(utcArr[1]);
|
||||
const d = new Date(time);
|
||||
const len = d.getTime();
|
||||
const offset = d.getTimezoneOffset() * 60000;
|
||||
const utcTime = len + offset;
|
||||
return new Date(utcTime + 3600000 * utcHour + utcMin * 60000);
|
||||
};
|
||||
|
||||
const setTimezoneOffset = () => {
|
||||
window.localStorage.setItem(
|
||||
"utc",
|
||||
-(new Date().getTimezoneOffset() / 60) + ":0"
|
||||
);
|
||||
};
|
||||
|
||||
export const queryOAPTimeInfo = async (): Promise<void> => {
|
||||
let utc = window.localStorage.getItem("utc");
|
||||
if (!utc) {
|
||||
const res: AxiosResponse = await graph.query("queryOAPTimeInfo").params({});
|
||||
if (
|
||||
!res.data ||
|
||||
!res.data.data ||
|
||||
!res.data.data.getTimeInfo ||
|
||||
!res.data.data.getTimeInfo.timezone
|
||||
) {
|
||||
setTimezoneOffset();
|
||||
return;
|
||||
}
|
||||
utc = res.data.data.getTimeInfo.timezone / 100 + ":0";
|
||||
window.localStorage.setItem("utc", utc);
|
||||
}
|
||||
};
|
||||
|
||||
export default getLocalTime;
|
33
src/utils/timeFormat.ts
Normal file
33
src/utils/timeFormat.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Duration } from "@/types/app";
|
||||
import { TimeType } from "@/constants/data";
|
||||
|
||||
const timeFormat = (time: Date[]): Duration => {
|
||||
let step: TimeType;
|
||||
const unix = Math.round(time[1].getTime()) - Math.round(time[0].getTime());
|
||||
if (unix <= 60 * 60 * 1000) {
|
||||
step = TimeType.MINUTE_TIME;
|
||||
} else if (unix <= 24 * 60 * 60 * 1000) {
|
||||
step = TimeType.HOUR_TIME;
|
||||
} else {
|
||||
step = TimeType.DAY_TIME;
|
||||
}
|
||||
return { start: time[0], end: time[1], step };
|
||||
};
|
||||
|
||||
export default timeFormat;
|
163
src/utils/vec2.ts
Normal file
163
src/utils/vec2.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
class Vec2 extends Float32Array {
|
||||
constructor(v?: unknown, y?: unknown) {
|
||||
super(2);
|
||||
if (
|
||||
v instanceof Vec2 ||
|
||||
v instanceof Float32Array ||
|
||||
(v instanceof Array && v.length == 2)
|
||||
) {
|
||||
this[0] = v[0];
|
||||
this[1] = v[1];
|
||||
} else if (typeof v === "number" && typeof y === "number") {
|
||||
this[0] = v;
|
||||
this[1] = y;
|
||||
} else if (typeof v === "number") {
|
||||
this[0] = v;
|
||||
this[1] = v;
|
||||
}
|
||||
}
|
||||
xy(x: number, y: number): Vec2 {
|
||||
if (y != undefined) {
|
||||
this[0] = x;
|
||||
this[1] = y;
|
||||
} else this[0] = this[1] = x;
|
||||
return this;
|
||||
}
|
||||
get x(): number {
|
||||
return this[0];
|
||||
}
|
||||
set x(v: number) {
|
||||
this[0] = v;
|
||||
}
|
||||
get y(): number {
|
||||
return this[1];
|
||||
}
|
||||
set y(v: number) {
|
||||
this[1] = v;
|
||||
}
|
||||
len(): number {
|
||||
return Math.sqrt(this[0] * this[0] + this[1] * this[1]);
|
||||
}
|
||||
fromAdd(a: number[], b: number[]): Vec2 {
|
||||
this[0] = a[0] + b[0];
|
||||
this[1] = a[1] + b[1];
|
||||
return this;
|
||||
}
|
||||
fromSub(a: number[] | Vec2, b: number[] | Vec2): Vec2 {
|
||||
this[0] = a[0] - b[0];
|
||||
this[1] = a[1] - b[1];
|
||||
return this;
|
||||
}
|
||||
fromScale(a: number[] | Vec2, s: number): Vec2 {
|
||||
this[0] = a[0] * s;
|
||||
this[1] = a[1] * s;
|
||||
return this;
|
||||
}
|
||||
fromLerp(a: number[] | Vec2, b: number[] | Vec2, t: number): Vec2 {
|
||||
const tt = 1 - t;
|
||||
this[0] = a[0] * tt + b[0] * t;
|
||||
this[1] = a[1] * tt + b[1] * t;
|
||||
return this;
|
||||
}
|
||||
/** Used to get data from a flat buffer of vectors, useful when building geometery */
|
||||
fromBuf(ary: number[], idx: number): Vec2 {
|
||||
this[0] = ary[idx];
|
||||
this[1] = ary[idx + 1];
|
||||
return this;
|
||||
}
|
||||
/** Pust vector components onto an array, useful when building geometery */
|
||||
pushTo(ary: number[]): Vec2 {
|
||||
ary.push(this[0], this[1]);
|
||||
return this;
|
||||
}
|
||||
add(v: number[]): Vec2 {
|
||||
this[0] += v[0];
|
||||
this[1] += v[1];
|
||||
return this;
|
||||
}
|
||||
addRaw(x: number, y: number): Vec2 {
|
||||
this[0] += x;
|
||||
this[1] += y;
|
||||
return this;
|
||||
}
|
||||
sub(v: number[]): Vec2 {
|
||||
this[0] -= v[0];
|
||||
this[1] -= v[1];
|
||||
return this;
|
||||
}
|
||||
scale(v: number): Vec2 {
|
||||
this[0] *= v;
|
||||
this[1] *= v;
|
||||
return this;
|
||||
}
|
||||
norm(out?: number[] | Vec2): number[] | Vec2 | undefined {
|
||||
const mag = Math.sqrt(this[0] * this[0] + this[1] * this[1]);
|
||||
if (mag == 0) return this;
|
||||
out = out || this;
|
||||
out[0] = this[0] / mag;
|
||||
out[1] = this[1] / mag;
|
||||
return out;
|
||||
}
|
||||
perpCCW(): Vec2 {
|
||||
const x = this[0];
|
||||
this[0] = -this[1];
|
||||
this[1] = x;
|
||||
return this;
|
||||
}
|
||||
static add(a: number[], b: number[]): Vec2 {
|
||||
return new Vec2().fromAdd(a, b);
|
||||
}
|
||||
static sub(a: number[], b: number[]): Vec2 {
|
||||
return new Vec2().fromSub(a, b);
|
||||
}
|
||||
static scale(v: number[], s: number): Vec2 {
|
||||
return new Vec2().fromScale(v, s);
|
||||
}
|
||||
static lerp(v0: number[], v1: number[], t: number): Vec2 {
|
||||
return new Vec2().fromLerp(v0, v1, t);
|
||||
}
|
||||
static len(v0: Vec2, v1: Vec2): number {
|
||||
return Math.sqrt((v0[0] - v1[0]) ** 2 + (v0[1] - v1[1]) ** 2);
|
||||
}
|
||||
/** Create an Iterator Object that allows an easy way to loop a Float32Buffer
|
||||
* @example
|
||||
* let buf = new Float32Array( 2 * 10 );
|
||||
* for( let v of Vec3.bufIter( buf ) ){console.log( v )};
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
static bufIter(buf: number[]) {
|
||||
let i = 0;
|
||||
const result = { value: new Vec2(), done: false },
|
||||
len = buf.length,
|
||||
next = () => {
|
||||
if (i >= len) result.done = true;
|
||||
else {
|
||||
result.value.fromBuf(buf, i);
|
||||
i += 2;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return {
|
||||
[Symbol.iterator]() {
|
||||
return { next };
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
export default Vec2;
|
177
src/utils/vec3.ts
Normal file
177
src/utils/vec3.ts
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
class Vec3 extends Float32Array {
|
||||
constructor(v?: unknown, y?: unknown, z?: unknown) {
|
||||
super(3);
|
||||
if (
|
||||
v instanceof Vec3 ||
|
||||
v instanceof Float32Array ||
|
||||
(v instanceof Array && v.length == 3)
|
||||
) {
|
||||
this[0] = v[0];
|
||||
this[1] = v[1];
|
||||
this[2] = v[2];
|
||||
} else if (
|
||||
typeof v === "number" &&
|
||||
typeof y === "number" &&
|
||||
typeof z === "number"
|
||||
) {
|
||||
this[0] = v;
|
||||
this[1] = y;
|
||||
this[2] = z;
|
||||
} else if (typeof v === "number") {
|
||||
this[0] = v;
|
||||
this[1] = v;
|
||||
this[2] = v;
|
||||
}
|
||||
}
|
||||
xyz(x: number, y: number, z: number): Vec3 {
|
||||
if (y != undefined && z != undefined) {
|
||||
this[0] = x;
|
||||
this[1] = y;
|
||||
this[2] = z;
|
||||
} else this[0] = this[1] = this[2] = x;
|
||||
return this;
|
||||
}
|
||||
get x(): number {
|
||||
return this[0];
|
||||
}
|
||||
set x(v: number) {
|
||||
this[0] = v;
|
||||
}
|
||||
get y(): number {
|
||||
return this[1];
|
||||
}
|
||||
set y(v: number) {
|
||||
this[1] = v;
|
||||
}
|
||||
get z(): number {
|
||||
return this[2];
|
||||
}
|
||||
set z(v: number) {
|
||||
this[2] = v;
|
||||
}
|
||||
|
||||
fromVec2(v: Vec3, useZ = false): Vec3 {
|
||||
this[0] = v[0];
|
||||
if (useZ) {
|
||||
this[1] = 0;
|
||||
this[2] = v[1];
|
||||
} else {
|
||||
this[1] = v[1];
|
||||
this[2] = 0;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
norm(): Vec3 {
|
||||
let mag = Math.sqrt(this[0] ** 2 + this[1] ** 2 + this[2] ** 2);
|
||||
if (mag != 0) {
|
||||
mag = 1 / mag;
|
||||
this[0] *= mag;
|
||||
this[1] *= mag;
|
||||
this[2] *= mag;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/** Pust vector components onto an array, useful when building geometery */
|
||||
pushTo(ary: number[]): Vec3 {
|
||||
ary.push(this[0], this[1], this[2]);
|
||||
return this;
|
||||
}
|
||||
// INTERPOLATION SETTERS
|
||||
fromLerp(a: Vec3, b: Vec3, t: number): Vec3 {
|
||||
const ti = 1 - t; // Linear Interpolation : (1 - t) * v0 + t * v1;
|
||||
this[0] = a[0] * ti + b[0] * t;
|
||||
this[1] = a[1] * ti + b[1] * t;
|
||||
this[2] = a[2] * ti + b[2] * t;
|
||||
return this;
|
||||
}
|
||||
/** Add vector to current vector */
|
||||
add(a: Vec3 | number[]): Vec3 {
|
||||
this[0] += a[0];
|
||||
this[1] += a[1];
|
||||
this[2] += a[2];
|
||||
return this;
|
||||
}
|
||||
sub(v: Vec3 | number[]): Vec3 {
|
||||
this[0] -= v[0];
|
||||
this[1] -= v[1];
|
||||
this[2] -= v[2];
|
||||
return this;
|
||||
}
|
||||
scale(v: number): Vec3 {
|
||||
this[0] *= v;
|
||||
this[1] *= v;
|
||||
this[2] *= v;
|
||||
return this;
|
||||
}
|
||||
/** Scale a vector */
|
||||
fromScale(a: Vec3, s: number): Vec3 {
|
||||
this[0] = a[0] * s;
|
||||
this[1] = a[1] * s;
|
||||
this[2] = a[2] * s;
|
||||
return this;
|
||||
}
|
||||
/** Add two vectors together */
|
||||
fromAdd(a: Vec3, b: number[]): Vec3 {
|
||||
this[0] = a[0] + b[0];
|
||||
this[1] = a[1] + b[1];
|
||||
this[2] = a[2] + b[2];
|
||||
return this;
|
||||
}
|
||||
/** Subtract two vectors together */
|
||||
fromSub(a: number[], b: number[]): Vec3 {
|
||||
this[0] = a[0] - b[0];
|
||||
this[1] = a[1] - b[1];
|
||||
this[2] = a[2] - b[2];
|
||||
return this;
|
||||
}
|
||||
/** Copy in vector data */
|
||||
copy(v: any[] | Float32Array): Vec3 {
|
||||
this[0] = v[0];
|
||||
this[1] = v[1];
|
||||
this[2] = v[2];
|
||||
return this;
|
||||
}
|
||||
static add(a: Vec3, b: number[]): Vec3 {
|
||||
return new Vec3().fromAdd(a, b);
|
||||
}
|
||||
static sub(a: number[], b: number[]): Vec3 {
|
||||
return new Vec3().fromSub(a, b);
|
||||
}
|
||||
static scale(a: Vec3, s: number): Vec3 {
|
||||
return new Vec3().fromScale(a, s);
|
||||
}
|
||||
static norm(x: unknown, y: unknown, z: unknown): Vec3 {
|
||||
const rtn = new Vec3();
|
||||
if (
|
||||
x instanceof Vec3 ||
|
||||
x instanceof Float32Array ||
|
||||
(x instanceof Array && x.length == 3)
|
||||
) {
|
||||
rtn.copy(x);
|
||||
} else if (
|
||||
typeof x === "number" &&
|
||||
typeof y === "number" &&
|
||||
typeof z === "number"
|
||||
) {
|
||||
rtn.xyz(x, y, z);
|
||||
}
|
||||
return rtn.norm();
|
||||
}
|
||||
}
|
||||
export default Vec3;
|
Reference in New Issue
Block a user