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

Src: cleanup MathUtils imports #29943

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/animation/AnimationClip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NumberKeyframeTrack } from './tracks/NumberKeyframeTrack.js';
import { QuaternionKeyframeTrack } from './tracks/QuaternionKeyframeTrack.js';
import { StringKeyframeTrack } from './tracks/StringKeyframeTrack.js';
import { VectorKeyframeTrack } from './tracks/VectorKeyframeTrack.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';
import { NormalAnimationBlendMode } from '../constants.js';

class AnimationClip {
Expand All @@ -18,7 +18,7 @@ class AnimationClip {
this.duration = duration;
this.blendMode = blendMode;

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

// this means it should figure out its duration by scanning the tracks
if ( this.duration < 0 ) {
Expand Down
4 changes: 2 additions & 2 deletions src/animation/AnimationObjectGroup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PropertyBinding } from './PropertyBinding.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';

/**
*
Expand Down Expand Up @@ -36,7 +36,7 @@ class AnimationObjectGroup {

this.isAnimationObjectGroup = true;

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

// cached objects followed by the active ones
this._objects = Array.prototype.slice.call( arguments );
Expand Down
12 changes: 6 additions & 6 deletions src/cameras/PerspectiveCamera.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Camera } from './Camera.js';
import * as MathUtils from '../math/MathUtils.js';
import { RAD2DEG, DEG2RAD } from '../math/MathUtils.js';
import { Vector2 } from '../math/Vector2.js';
import { Vector3 } from '../math/Vector3.js';

Expand Down Expand Up @@ -69,7 +69,7 @@ class PerspectiveCamera extends Camera {
/** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;

this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
this.updateProjectionMatrix();

}
Expand All @@ -79,16 +79,16 @@ class PerspectiveCamera extends Camera {
*/
getFocalLength() {

const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );

return 0.5 * this.getFilmHeight() / vExtentSlope;

}

getEffectiveFOV() {

return MathUtils.RAD2DEG * 2 * Math.atan(
Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
return RAD2DEG * 2 * Math.atan(
Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );

}

Expand Down Expand Up @@ -214,7 +214,7 @@ class PerspectiveCamera extends Camera {
updateProjectionMatrix() {

const near = this.near;
let top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom;
let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
let height = 2 * top;
let width = this.aspect * height;
let left = - 0.5 * width;
Expand Down
4 changes: 2 additions & 2 deletions src/cameras/StereoCamera.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Matrix4 } from '../math/Matrix4.js';
import * as MathUtils from '../math/MathUtils.js';
import { DEG2RAD } from '../math/MathUtils.js';
import { PerspectiveCamera } from './PerspectiveCamera.js';

const _eyeRight = /*@__PURE__*/ new Matrix4();
Expand Down Expand Up @@ -60,7 +60,7 @@ class StereoCamera {
_projectionMatrix.copy( camera.projectionMatrix );
const eyeSepHalf = cache.eyeSep / 2;
const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
let xmin, xmax;

// translate xOffset
Expand Down
4 changes: 2 additions & 2 deletions src/core/BufferGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Sphere } from '../math/Sphere.js';
import { Object3D } from './Object3D.js';
import { Matrix4 } from '../math/Matrix4.js';
import { Matrix3 } from '../math/Matrix3.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';
import { arrayNeedsUint32 } from '../utils.js';

let _id = 0;
Expand All @@ -29,7 +29,7 @@ class BufferGeometry extends EventDispatcher {

Object.defineProperty( this, 'id', { value: _id ++ } );

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

this.name = '';
this.type = 'BufferGeometry';
Expand Down
8 changes: 4 additions & 4 deletions src/core/InterleavedBuffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';
import { StaticDrawUsage } from '../constants.js';

class InterleavedBuffer {
Expand All @@ -16,7 +16,7 @@ class InterleavedBuffer {

this.version = 0;

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

}

Expand Down Expand Up @@ -92,7 +92,7 @@ class InterleavedBuffer {

if ( this.array.buffer._uuid === undefined ) {

this.array.buffer._uuid = MathUtils.generateUUID();
this.array.buffer._uuid = generateUUID();

}

Expand Down Expand Up @@ -131,7 +131,7 @@ class InterleavedBuffer {

if ( this.array.buffer._uuid === undefined ) {

this.array.buffer._uuid = MathUtils.generateUUID();
this.array.buffer._uuid = generateUUID();

}

Expand Down
4 changes: 2 additions & 2 deletions src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EventDispatcher } from './EventDispatcher.js';
import { Euler } from '../math/Euler.js';
import { Layers } from './Layers.js';
import { Matrix3 } from '../math/Matrix3.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';

let _object3DId = 0;

Expand Down Expand Up @@ -38,7 +38,7 @@ class Object3D extends EventDispatcher {

Object.defineProperty( this, 'id', { value: _object3DId ++ } );

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

this.name = '';
this.type = 'Object3D';
Expand Down
6 changes: 3 additions & 3 deletions src/extras/core/Curve.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as MathUtils from '../../math/MathUtils.js';
import { clamp } from '../../math/MathUtils.js';
import { Vector2 } from '../../math/Vector2.js';
import { Vector3 } from '../../math/Vector3.js';
import { Matrix4 } from '../../math/Matrix4.js';
Expand Down Expand Up @@ -330,7 +330,7 @@ class Curve {

vec.normalize();

const theta = Math.acos( MathUtils.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors

normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );

Expand All @@ -344,7 +344,7 @@ class Curve {

if ( closed === true ) {

let theta = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
theta /= segments;

if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
Expand Down
4 changes: 2 additions & 2 deletions src/extras/core/Shape.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Path } from './Path.js';
import * as MathUtils from '../../math/MathUtils.js';
import { generateUUID } from '../../math/MathUtils.js';

class Shape extends Path {

constructor( points ) {

super( points );

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

this.type = 'Shape';

Expand Down
4 changes: 2 additions & 2 deletions src/geometries/EdgesGeometry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BufferGeometry } from '../core/BufferGeometry.js';
import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import * as MathUtils from '../math/MathUtils.js';
import { DEG2RAD } from '../math/MathUtils.js';
import { Triangle } from '../math/Triangle.js';
import { Vector3 } from '../math/Vector3.js';

Expand All @@ -26,7 +26,7 @@ class EdgesGeometry extends BufferGeometry {

const precisionPoints = 4;
const precision = Math.pow( 10, precisionPoints );
const thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle );
const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );

const indexAttr = geometry.getIndex();
const positionAttr = geometry.getAttribute( 'position' );
Expand Down
4 changes: 2 additions & 2 deletions src/geometries/LatheGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Float32BufferAttribute } from '../core/BufferAttribute.js';
import { BufferGeometry } from '../core/BufferGeometry.js';
import { Vector3 } from '../math/Vector3.js';
import { Vector2 } from '../math/Vector2.js';
import * as MathUtils from '../math/MathUtils.js';
import { clamp } from '../math/MathUtils.js';

class LatheGeometry extends BufferGeometry {

Expand All @@ -23,7 +23,7 @@ class LatheGeometry extends BufferGeometry {

// clamp phiLength so it's in range of [ 0, 2PI ]

phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 );
phiLength = clamp( phiLength, 0, Math.PI * 2 );

// buffers

Expand Down
4 changes: 2 additions & 2 deletions src/lights/SpotLightShadow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightShadow } from './LightShadow.js';
import * as MathUtils from '../math/MathUtils.js';
import { RAD2DEG } from '../math/MathUtils.js';
import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';

class SpotLightShadow extends LightShadow {
Expand All @@ -18,7 +18,7 @@ class SpotLightShadow extends LightShadow {

const camera = this.camera;

const fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
const fov = RAD2DEG * 2 * light.angle * this.focus;
const aspect = this.mapSize.width / this.mapSize.height;
const far = light.distance || camera.far;

Expand Down
4 changes: 2 additions & 2 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Color } from '../math/Color.js';
import { EventDispatcher } from '../core/EventDispatcher.js';
import { FrontSide, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp } from '../constants.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';

let _materialId = 0;

Expand All @@ -15,7 +15,7 @@ class Material extends EventDispatcher {

Object.defineProperty( this, 'id', { value: _materialId ++ } );

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

this.name = '';
this.type = 'Material';
Expand Down
4 changes: 2 additions & 2 deletions src/materials/MeshPhysicalMaterial.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Vector2 } from '../math/Vector2.js';
import { MeshStandardMaterial } from './MeshStandardMaterial.js';
import { Color } from '../math/Color.js';
import * as MathUtils from '../math/MathUtils.js';
import { clamp } from '../math/MathUtils.js';

class MeshPhysicalMaterial extends MeshStandardMaterial {

Expand Down Expand Up @@ -34,7 +34,7 @@ class MeshPhysicalMaterial extends MeshStandardMaterial {
Object.defineProperty( this, 'reflectivity', {
get: function () {

return ( MathUtils.clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );

},
set: function ( reflectivity ) {
Expand Down
4 changes: 2 additions & 2 deletions src/math/Line3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Vector3 } from './Vector3.js';
import * as MathUtils from './MathUtils.js';
import { clamp } from './MathUtils.js';

const _startP = /*@__PURE__*/ new Vector3();
const _startEnd = /*@__PURE__*/ new Vector3();
Expand Down Expand Up @@ -73,7 +73,7 @@ class Line3 {

if ( clampToLine ) {

t = MathUtils.clamp( t, 0, 1 );
t = clamp( t, 0, 1 );

}

Expand Down
4 changes: 2 additions & 2 deletions src/math/Quaternion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as MathUtils from './MathUtils.js';
import { clamp } from './MathUtils.js';

class Quaternion {

Expand Down Expand Up @@ -394,7 +394,7 @@ class Quaternion {

angleTo( q ) {

return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) );
return 2 * Math.acos( Math.abs( clamp( this.dot( q ), - 1, 1 ) ) );

}

Expand Down
6 changes: 3 additions & 3 deletions src/math/Spherical.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as MathUtils from './MathUtils.js';
import { clamp } from './MathUtils.js';

/**
* Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
Expand Down Expand Up @@ -42,7 +42,7 @@ class Spherical {
makeSafe() {

const EPS = 0.000001;
this.phi = MathUtils.clamp( this.phi, EPS, Math.PI - EPS );
this.phi = clamp( this.phi, EPS, Math.PI - EPS );

return this;

Expand All @@ -66,7 +66,7 @@ class Spherical {
} else {

this.theta = Math.atan2( x, z );
this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) );

}

Expand Down
4 changes: 2 additions & 2 deletions src/objects/Skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { Bone } from './Bone.js';
import { Matrix4 } from '../math/Matrix4.js';
import { DataTexture } from '../textures/DataTexture.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';

const _offsetMatrix = /*@__PURE__*/ new Matrix4();
const _identityMatrix = /*@__PURE__*/ new Matrix4();
Expand All @@ -14,7 +14,7 @@ class Skeleton {

constructor( bones = [], boneInverses = [] ) {

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

this.bones = bones.slice( 0 );
this.boneInverses = boneInverses;
Expand Down
4 changes: 2 additions & 2 deletions src/textures/Source.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ImageUtils } from '../extras/ImageUtils.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';

let _sourceId = 0;

Expand All @@ -11,7 +11,7 @@ class Source {

Object.defineProperty( this, 'id', { value: _sourceId ++ } );

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

this.data = data;
this.dataReady = true;
Expand Down
4 changes: 2 additions & 2 deletions src/textures/Texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UVMapping,
NoColorSpace,
} from '../constants.js';
import * as MathUtils from '../math/MathUtils.js';
import { generateUUID } from '../math/MathUtils.js';
import { Vector2 } from '../math/Vector2.js';
import { Matrix3 } from '../math/Matrix3.js';
import { Source } from './Source.js';
Expand All @@ -27,7 +27,7 @@ class Texture extends EventDispatcher {

Object.defineProperty( this, 'id', { value: _textureId ++ } );

this.uuid = MathUtils.generateUUID();
this.uuid = generateUUID();

this.name = '';

Expand Down