Now throws an assertion error if you try to normalise a zero length vector

This commit is contained in:
Caspian Rychlik-Prince 2002-12-22 19:53:41 +00:00
parent 18f8302668
commit 75faf07a54
1 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002 Lightweight Java Game Library Project
* Copyright (c) 2002 Light Weight Java Game Library Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -84,8 +84,14 @@ public abstract class Vector {
* @return this
*/
public final Vector normalize() {
float l = 1.0f / length();
return scale(l);
float len = length();
if (len != 0.0f) {
float l = 1.0f / len;
return scale(l);
} else {
assert false;
return this;
}
}