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

Refactor functions to encapsulate private cache variables #74

Closed
gkjohnson opened this issue Mar 4, 2019 · 0 comments
Closed

Refactor functions to encapsulate private cache variables #74

gkjohnson opened this issue Mar 4, 2019 · 0 comments
Milestone

Comments

@gkjohnson
Copy link
Owner

gkjohnson commented Mar 4, 2019

A lot of functions depend on cached THREE objects:

const v1 = new Vector3();
function doSomething( triangle ) {

  v1.copy( triangle.a );
  // ... do stuff ...

}

which runs a risk of functions overwriting other functions variables mid-use, etc. It might be best to refactor to use the pattern that THREE.js uses:

const doSomething = ( function() {

  const v1 = new Vector3();
  return function doSomething ( triangle ) {
    // ...
  }

} )();

Or for class members:

MeshBVHNode.prototype.doSomething = ( function() {

  const v1 = new Vector3();
  return function doSomething ( triangle ) {
    // ...
  }

} )();

Update: See MeshBVH.js for the functions that need to be updated.

@gkjohnson gkjohnson added this to the v0.1.6 milestone Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant