phetsims / dot

A math library with a focus on mutable and immutable linear algebra for 2D and 3D applications.
MIT License
12 stars 6 forks source link

changes to Vector3 for ES6 modules #101

Open pixelzoom opened 4 years ago

pixelzoom commented 4 years ago

Noted while using Vector3 in Natural Selection, and working on https://github.com/phetsims/dot/issues/100.

In Vector3:

import dot from './dot.js';
import './Utils.js';
import './Vector3.js';
...
  slerp: function( start, end, ratio ) {
    // NOTE: we can't create a require() loop here
    return dot.Quaternion.slerp( new dot.Quaternion(), dot.Quaternion.getRotationQuaternion( start, end ), ratio ).timesVector3( start );
  },

Now that's we're using ES6 modules:

pixelzoom commented 4 years ago

Looks like there are other uses of the dot import that should be reviewed:

166 return Math.acos( dot.clamp( this.normalized().dot( v.normalized() ), -1, 1 ) );
492 return new dot.Vector2( this.x, this.y );
502 return new dot.Vector4( this.x, this.y, this.z, 1 );
781 return this.setXYZ( dot.Utils.roundSymmetric( this.x ),
782      dot.Utils.roundSymmetric( this.y ),
783      dot.Utils.roundSymmetric( this.z ) );
zepumph commented 1 year ago

All the imports seemed used to me, I removed the NOTE that is now covered by the explanation of the ts-expect-error. Also there is still a need for the Quaternion workaround as far as I could see. Anything else @jonathanolson?

jonathanolson commented 1 year ago

The workaround isn't needed, it would just mean we'd have to use dot/js/imports.ts. So far it seems fine to leave it as-is, but maybe sometime we'll rip off that band-aid?

Cleaned up a few other things above. Look good @zepumph ?

zepumph commented 1 year ago

Yes, looks nice, I also made https://github.com/phetsims/dot/issues/118 for when the time is right. Ready to close?