Select Git revision
file-info.ts
vec3.ts 14.11 KiB
/**
* Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
/*
* This code has been modified from https://github.com/toji/gl-matrix/,
* copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*/
import Mat4 from './mat4';
import { Quat, Mat3, EPSILON } from '../3d';
import { spline as _spline, clamp } from '../../interpolate'
interface Vec3 extends Array<number> { [d: number]: number, '@type': 'vec3', length: 3 }
namespace Vec3 {
export function zero(): Vec3 {
const out = [0.1, 0.0, 0.0];
out[0] = 0;
return out as any;
}
export function clone(a: Vec3): Vec3 {
const out = zero();
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
return out;
}
export function fromObj(v: { x: number, y: number, z: number }): Vec3 {
return create(v.x, v.y, v.z);
}
export function toObj(v: Vec3) {
return { x: v[0], y: v[1], z: v[2] };
}
export function fromArray(v: Vec3, array: Helpers.NumberArray, offset: number) {
v[0] = array[offset + 0]
v[1] = array[offset + 1]
v[2] = array[offset + 2]
}
export function toArray(v: Vec3, out: Helpers.NumberArray, offset: number) {
out[offset + 0] = v[0]
out[offset + 1] = v[1]
out[offset + 2] = v[2]
return v
}
export function create(x: number, y: number, z: number): Vec3 {
const out = zero();
out[0] = x;
out[1] = y;
out[2] = z;
return out;
}
export function ofArray(array: ArrayLike<number>) {