mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
unecessary new
This commit is contained in:
@ -40,43 +40,43 @@ class Position {
|
||||
Position.fromVector(b2d.Vector2 vector) : this(vector.x, vector.y);
|
||||
|
||||
Position add(Position other) {
|
||||
this.x += other.x;
|
||||
this.y += other.y;
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
Position minus(Position other) {
|
||||
return this.add(other.clone().opposite());
|
||||
return add(other.clone().opposite());
|
||||
}
|
||||
|
||||
Position opposite() {
|
||||
return this.times(-1.0);
|
||||
return times(-1.0);
|
||||
}
|
||||
|
||||
Position times(double scalar) {
|
||||
this.x *= scalar;
|
||||
this.y *= scalar;
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
return this;
|
||||
}
|
||||
|
||||
double dotProduct(Position p) {
|
||||
return this.x * p.x + this.y * p.y;
|
||||
return x * p.x + y * p.y;
|
||||
}
|
||||
|
||||
double length() {
|
||||
return math.sqrt(math.pow(this.x, 2) + math.pow(this.y, 2));
|
||||
return math.sqrt(math.pow(x, 2) + math.pow(y, 2));
|
||||
}
|
||||
|
||||
Position rotate(double angle) {
|
||||
double nx = math.cos(angle) * this.x - math.sin(angle) * this.y;
|
||||
double ny = math.sin(angle) * this.x + math.cos(angle) * this.y;
|
||||
this.x = nx;
|
||||
this.y = ny;
|
||||
double nx = math.cos(angle) * x - math.sin(angle) * y;
|
||||
double ny = math.sin(angle) * x + math.cos(angle) * y;
|
||||
x = nx;
|
||||
y = ny;
|
||||
return this;
|
||||
}
|
||||
|
||||
double distance(Position other) {
|
||||
return this.minus(other).length();
|
||||
return minus(other).length();
|
||||
}
|
||||
|
||||
ui.Offset toOffset() {
|
||||
|
||||
Reference in New Issue
Block a user