After reviewing the information provided on the linked page:
.addScaledVector ( v, s )
This function adds a scaled version of vector v to this vector.
A more optimized approach would be:
camera.position.clone().addScaledVector(forward, THRESHOLD)
It's unnecessary to clone forward since it will not be altered in this scenario.
If I understand @T.J.'s suggestion correctly and you're looking for a more widely applicable solution, my response would be that if by 'idomatic' you mean utilizing the + and - operators in JavaScript strictly, then no. You could potentially create your own framework to adhere to idiomatic standards, like implementing a general addition operator:
var add = function(x,y):
try {
var sum = x + y;
if ( s != undefined ) { return sum; }
#otherwise
sum = x.clone().add(y);
} catch {
#Otherwise threw something
sum = x.add(y) #maybe another exception? nest try/catch.
}
}
However, this approach entails a considerable amount of effort due to the need for extensive type checking, as JavaScript allows for loose concatenation of values without strict rules. Simply attempting to return x+y
may result in an undefined output. In my illustration, prioritizing add functions over basic arithmetic operations might yield better results.
This method enables you to establish the desired programming style, should you find it worthwhile, and use your customized add
function across different tasks instead of relying on the standard +
operator. It's advisable to expand upon this concept during your coding process.