Permalink
Browse files

Vector[2|3]: Incorrect order in mathematical operations.

  • Loading branch information...
Dgame committed Apr 15, 2015
1 parent 02445ce commit b2d7da67e52060a3513ef88f7d766ea787ae2879
Showing with 16 additions and 9 deletions.
  1. +13 −6 source/Dgame/Math/Vector2.d
  2. +2 −2 source/Dgame/Math/Vector3.d
  3. +1 −1 source/Dgame/test/.dub/dub.json
@@ -123,7 +123,7 @@ struct Vector2(T) if (isNumeric!(T)) {
case "*":
case "/":
case "%":
mixin("return Vector2!(T)(vec.x " ~ op ~ " this.x, vec.y " ~ op ~ " this.y);");
mixin("return Vector2!(T)(this.x " ~ op ~ " vec.x, this.y " ~ op ~ " vec.y);");
default:
assert(0, "Unsupported operator " ~ op);
}
@@ -140,7 +140,7 @@ struct Vector2(T) if (isNumeric!(T)) {
case "*":
case "/":
case "%":
mixin("return Vector2!(T)(cast(T)(num " ~ op ~ " this.x), cast(T)(num " ~ op ~ " this.y));");
mixin("return Vector2!(T)(cast(T)(this.x " ~ op ~ " num), cast(T)(this.y " ~ op ~ " num));");
default:
assert(0, "Unsupported operator " ~ op);
}
@@ -254,25 +254,25 @@ unittest {
assert(vec.y == 72);
assert(!vec.isEmpty());
Vector2i vec2 = vec * 3;
const Vector2i vec2 = vec * 3;
assert(vec2.x == 3 * vec.x);
assert(vec2.y == 3 * vec.y);
Vector2i vec3 = vec2 + vec;
const Vector2i vec3 = vec2 + vec;
assert(vec3.x == vec.x + vec2.x);
assert(vec3.y == vec.y + vec2.y);
assert(vec == vec);
assert(vec2 != vec3);
Vector2i vec4 = -vec;
const Vector2i vec4 = -vec;
assert(vec4.x == -62);
assert(vec4.y == -72);
Vector2f vconv = vec4;
const Vector2f vconv = vec4;
assert(vec4.x == vconv.x && vec4.y == vconv.y);
@@ -283,4 +283,11 @@ unittest {
Vector2i v2 = Vector2i(2.3, 4.2);
immutable float l2 = v2.length;
const Vector2i v2n = v2.normalize();
const Vector2f vec5 = Vector2f(80, 64);
const Vector2f vec6 = Vector2f(32, 32);
const Vector2f vec7 = Vector2f(2.5, 2);
assert(vec5 / vec6 == vec7);
assert(vec5 / vec6.x == vec7);
}
@@ -169,7 +169,7 @@ struct Vector3(T) if (isNumeric!(T)) {
case "*":
case "/":
case "%":
mixin("return Vector3!(T)(vec.x " ~ op ~ " this.x, vec.y " ~ op ~ " this.y, vec.z " ~ op ~ " this.z);");
mixin("return Vector3!(T)(this.x " ~ op ~ " vec.x, this.y " ~ op ~ " vec.y, this.z " ~ op ~ " vec.y);");
default:
assert(0, "Unsupported operator " ~ op);
}
@@ -186,7 +186,7 @@ struct Vector3(T) if (isNumeric!(T)) {
case "*":
case "/":
case "%":
mixin("return Vector3!(T)(cast(T)(num " ~ op ~ " this.x), cast(T)(num " ~ op ~ " this.y), cast(T)(num " ~ op ~ " this.z));");
mixin("return Vector3!(T)(cast(T)(this.x " ~ op ~ " num), cast(T)(this.y " ~ op ~ " num), cast(T)(this.z " ~ op ~ " num));");
default:
assert(0, "Unsupported operator " ~ op);
}
@@ -5,6 +5,6 @@
"derelict-sdl2": "1.9.5",
"derelict-gl3": "1.0.12"
},
"lastUpgrade": "2015-04-12T13:47:26.8541678"
"lastUpgrade": "2015-04-15T20:34:44.2702045"
}
}

0 comments on commit b2d7da6

Please sign in to comment.