Add utility to get/set ex.Vector size
See original GitHub issueContext
It would be useful to set the magnitude of a vector, this allows easy scaling or capping at a maximum value. This is especially useful in physics simulations.
Proposal
I propose something like the following (there is probably a more efficient method of changing the size of the vector)
/**
* The magnitude (size) of the Vector
* @obsolete magnitude will be removed in favor `.size` in version v0.24.0
*/
public magnitude(): number {
return this.distance();
}
/**
* The size (aka magnitude) of the Vector
*/
public get size(): number {
return this.distance();
}
public set size(newLength: number) {
this.normalize().scale(newLength);
}
Usage:
const vel = new ex.Vector(3, 4);
console.log(vel.size); // 5
vel.size = 13;
// Automatically calculates to correct scale
console.log(vel.x); // 5
console.log(vel.y); // 12
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
How to write C++ getters and setters - Stack Overflow
E.g.: Getting the size of a vector. You don't want to expose a data member, because it needs to be read only.
Read more >C++ Encapsulation and Getters and Setters - W3Schools
Inside main() , we create an object of the Employee class. Now we can use the setSalary() method to set the value of...
Read more >Python Set (With Examples) - Programiz
In this tutorial, you'll learn everything about Python sets; how they are created, adding or removing elements from them, and all operations performed...
Read more >C++ Tutorial: A Beginner's Guide to std::vector, Part 1
A C++ programming tutorial that teaches developers how to use std::vector. Learn basic and intermediate C++ coding.
Read more >How to use VBA Structures - Automate Excel
First we declare a variable array as an Employees variable. We then size the array and loop through a range of cells in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@saahilk Let me know if this doesn’t cover everything https://github.com/excaliburjs/Excalibur#environment-setup, please let me know if there are any gaps in the readme 👍
@eonarheim Could you check the modified pull request here.