New "const" style interfaces for Vectors

This commit is contained in:
Caspian Rychlik-Prince 2003-09-26 16:19:18 +00:00
parent 42ad1026af
commit 5497007c33
8 changed files with 341 additions and 19 deletions

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.vector;
import java.nio.FloatBuffer;
/**
* @author foo
*/
public interface ReadableVector {
/**
* @return the length of the vector
*/
public float length();
/**
* @return the length squared of the vector
*/
public float lengthSquared();
/**
* Store this vector in a FloatBuffer
* @param buf The buffer to store it in, at the current position
* @return this
*/
public Vector store(FloatBuffer buf);
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.vector;
/**
* @author foo
*/
public interface ReadableVector2f extends ReadableVector {
/**
* @return x
*/
public float getX();
/**
* @return y
*/
public float getY();
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.vector;
/**
* @author foo
*/
public interface ReadableVector3f extends ReadableVector2f {
/**
* @return z
*/
public float getZ();
}

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2003 Shaven Puppy Ltd
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'Shaven Puppy' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.vector;
/**
* @author foo
*/
public interface ReadableVector4f extends ReadableVector3f {
/**
* @return w
*/
public float getW();
}

View file

@ -42,7 +42,7 @@ import java.nio.FloatBuffer;
* @author cix_foo <cix_foo@users.sourceforge.net>
* @version $Revision$
*/
public abstract class Vector implements Serializable {
public abstract class Vector implements Serializable, ReadableVector {
/**
* Constructor for Vector.

View file

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$
*/
public class Vector2f extends Vector implements Serializable {
public class Vector2f extends Vector implements Serializable, ReadableVector2f {
public float x, y;
@ -57,7 +57,7 @@ public class Vector2f extends Vector implements Serializable {
/**
* Constructor
*/
public Vector2f(Vector2f src) {
public Vector2f(ReadableVector2f src) {
set(src);
}
@ -83,9 +83,9 @@ public class Vector2f extends Vector implements Serializable {
* @param src The source vector
* @return this
*/
public Vector2f set(Vector2f src) {
x = src.x;
y = src.y;
public Vector2f set(ReadableVector2f src) {
x = src.getX();
y = src.getY();
return this;
}
@ -254,4 +254,35 @@ public class Vector2f extends Vector implements Serializable {
sb.append(']');
return sb.toString();
}
/**
* @return x
*/
public final float getX() {
return x;
}
/**
* @return y
*/
public final float getY() {
return y;
}
/**
* Set X
* @param x
*/
public final void setX(float x) {
this.x = x;
}
/**
* Set Y
* @param y
*/
public final void setY(float y) {
this.y = y;
}
}

View file

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$
*/
public class Vector3f extends Vector implements Serializable {
public class Vector3f extends Vector implements Serializable, ReadableVector3f {
public float x, y, z;
@ -57,7 +57,7 @@ public class Vector3f extends Vector implements Serializable {
/**
* Constructor
*/
public Vector3f(Vector3f src) {
public Vector3f(ReadableVector3f src) {
set(src);
}
@ -84,10 +84,10 @@ public class Vector3f extends Vector implements Serializable {
* @param src The source vector
* @return this
*/
public Vector3f set(Vector3f src) {
x = src.x;
y = src.y;
z = src.z;
public Vector3f set(ReadableVector3f src) {
x = src.getX();
y = src.getY();
z = src.getZ();
return this;
}
@ -290,5 +290,48 @@ public class Vector3f extends Vector implements Serializable {
return sb.toString();
}
/**
* @return x
*/
public final float getX() {
return x;
}
/**
* @return y
*/
public final float getY() {
return y;
}
/**
* Set X
* @param x
*/
public final void setX(float x) {
this.x = x;
}
/**
* Set Y
* @param y
*/
public final void setY(float y) {
this.y = y;
}
/**
* Set Z
* @param z
*/
public void setZ(float z) {
this.z = z;
}
/* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ()
*/
public float getZ() {
return z;
}
}

View file

@ -43,7 +43,7 @@ import java.nio.FloatBuffer;
* @version $Revision$
*/
public class Vector4f extends Vector implements Serializable {
public class Vector4f extends Vector implements Serializable, ReadableVector4f {
public float x, y, z, w;
@ -57,7 +57,7 @@ public class Vector4f extends Vector implements Serializable {
/**
* Constructor
*/
public Vector4f(Vector4f src) {
public Vector4f(ReadableVector4f src) {
set(src);
}
@ -85,11 +85,11 @@ public class Vector4f extends Vector implements Serializable {
* @param src The source vector
* @return this
*/
public Vector4f set(Vector4f src) {
x = src.x;
y = src.y;
z = src.z;
w = src.w;
public Vector4f set(ReadableVector4f src) {
x = src.getX();
y = src.getY();
z = src.getZ();
w = src.getW();
return this;
}
@ -255,4 +255,66 @@ public class Vector4f extends Vector implements Serializable {
public String toString() {
return "Vector4f: " + x + " " + y + " " + z + " " + w;
}
/**
* @return x
*/
public final float getX() {
return x;
}
/**
* @return y
*/
public final float getY() {
return y;
}
/**
* Set X
* @param x
*/
public final void setX(float x) {
this.x = x;
}
/**
* Set Y
* @param y
*/
public final void setY(float y) {
this.y = y;
}
/**
* Set Z
* @param z
*/
public void setZ(float z) {
this.z = z;
}
/* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ()
*/
public float getZ() {
return z;
}
/**
* Set W
* @param w
*/
public void setW(float w) {
this.w = w;
}
/* (Overrides)
* @see org.lwjgl.vector.ReadableVector3f#getZ()
*/
public float getW() {
return w;
}
}