├── .gitignore ├── src └── javax │ └── vecmath │ ├── package-info.java │ ├── VecMathI18N.java │ ├── SingularMatrixException.java │ ├── MismatchedSizeException.java │ ├── VecMathUtil.java │ ├── Point2i.java │ ├── Point3i.java │ ├── Point4i.java │ ├── TexCoord2f.java │ ├── TexCoord3f.java │ ├── TexCoord4f.java │ ├── Point2d.java │ ├── Point2f.java │ ├── Color3b.java │ ├── ExceptionStrings.properties │ ├── Color3f.java │ ├── Color4b.java │ ├── Color4f.java │ ├── Vector2f.java │ ├── Vector2d.java │ ├── Point3d.java │ ├── Point3f.java │ ├── Vector3d.java │ ├── Vector3f.java │ ├── Vector4f.java │ ├── Vector4d.java │ ├── Point4f.java │ ├── Point4d.java │ ├── Tuple3b.java │ ├── Tuple4b.java │ ├── Tuple2i.java │ ├── Tuple3i.java │ ├── Tuple2d.java │ └── Tuple2f.java ├── README-FIRST.txt ├── LICENSE-SPEC.html ├── docs ├── api-changes-1_6.txt ├── api-changes-1_4.txt └── api-changes-1_5.txt ├── README-build.html └── COPYRIGHT.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /src/javax/vecmath/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Provides 3D vector mathematics classes. 3 | */ 4 | package javax.vecmath; 5 | -------------------------------------------------------------------------------- /README-FIRST.txt: -------------------------------------------------------------------------------- 1 | The source code for the vecmath project is copyrighted code 2 | that is licensed to individuals or companies who download or otherwise 3 | access the code. 4 | 5 | The copyright notice for this project is in COPYRIGHT.txt 6 | 7 | The source code license information for this project is in LICENSE.txt 8 | 9 | Instructions for building this project are in README-build.html 10 | 11 | Note that the source code in this directory is untested and presumed 12 | incompatible with the Java 3D(TM) API specification. You must only use 13 | this code in accordance with the terms under which the code is 14 | licensed. No additional rights are granted to you. 15 | 16 | If you prefer to use a tested and certified compatible version of the 17 | code, then you can download a binary release for the Solaris, Linux, 18 | Windows, and Mac OS X operating environments at: 19 | https://java3d.dev.java.net/binary-builds.html 20 | or at: 21 | http://java.sun.com/products/java-media/3D/ 22 | -------------------------------------------------------------------------------- /LICENSE-SPEC.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 3D Graphics API for the Java Platform 7 | 8 | 9 |

Copyright 1996-2008 Sun Microsystems, Inc. All rights reserved. 10 | Use is subject to license terms. 11 |

12 |

This javadoc-generated API documentation is not an 13 | official API specification. This documentation may contain references to 14 | Java and Java 3D, both of which are trademarks of Sun Microsystems, Inc. 15 | Any reference to these and other trademarks of Sun Microsystems are 16 | for explanatory purposes only. Their use does impart any rights beyond 17 | those listed in the source code license. In particular, Sun Microsystems 18 | retains all intellectual property and trademark rights as described in 19 | the proprietary rights notice in the COPYRIGHT.txt file. 20 |

21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/api-changes-1_6.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | $RCSfile$ 3 | $Revision$ 4 | $Date$ 5 | ------------------------------------------------------------------------ 6 | This document conatains proposed API changes to the vecmath 1.6 API 7 | that deviate from the 1.5 API. 8 | 9 | This file must be updated to record the addition or deprecation of any 10 | public or protected class, interface, field, constructor, or method to 11 | the vecmath API. 12 | 13 | The one exception to this rule is that you don't need to update this 14 | file when adding a non-final (i.e., virtual) method to a class if that 15 | method--with exactly the same signature--already exists in a 16 | superclass. For example, adding a "toString" method to a vecmath object 17 | doesn't require an entry in this file. 18 | 19 | No incompatible changes to the vecmath 1.5 API are allowed. 20 | 21 | 22 | I. New/deprecated fields, constructors, methods 23 | 24 | 25 | --------------- 26 | New methods: 27 | public 28 | 29 | II. Reparented classes 30 | 31 | 32 | --------------- 33 | now extends (used to extend ) 34 | 35 | 36 | III. New classes and interfaces (in javax.vecmath) 37 | 38 | -------------------------------------------------------------------------------- /docs/api-changes-1_4.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | $RCSfile$ 3 | $Revision$ 4 | $Date$ 5 | ------------------------------------------------------------------------ 6 | This document conatains proposed API changes to the vecmath 1.4 API 7 | that deviate from the 1.3 API. 8 | 9 | This file must be updated to record the addition or deprecation of any 10 | public or protected class, interface, field, constructor, or method to 11 | the vecmath API. 12 | 13 | The one exception to this rule is that you don't need to update this 14 | file when adding a non-final (i.e., virtual) method to a class if that 15 | method--with exactly the same signature--already exists in a 16 | superclass. For example, adding a "toString" method to a vecmath object 17 | doesn't require an entry in this file. 18 | 19 | No incompatible changes to the vecmath 1.3 API are allowed. 20 | 21 | 22 | I. New/deprecated fields, constructors, methods 23 | 24 | 25 | --------------- 26 | New methods: 27 | 28 | 29 | 30 | II. Reparented classes 31 | 32 | 33 | --------------- 34 | now extends (used to extend ) 35 | 36 | 37 | III. New classes and interfaces (in javax.vecmath) 38 | 39 | Tuple2i 40 | ------- 41 | public abstract class Tuple2i implements Serializable, Cloneable 42 | 43 | Point2i 44 | ------- 45 | public class Point2i extends Tuple2i 46 | 47 | -------------------------------------------------------------------------------- /src/javax/vecmath/VecMathI18N.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.util.MissingResourceException; 30 | import java.util.ResourceBundle; 31 | 32 | 33 | class VecMathI18N { 34 | static String getString(String key) { 35 | String s; 36 | try { 37 | s = (String) ResourceBundle.getBundle("javax.vecmath.ExceptionStrings").getString(key); 38 | } 39 | catch (MissingResourceException e) { 40 | System.err.println("VecMathI18N: Error looking up: " + key); 41 | s = key; 42 | } 43 | return s; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/javax/vecmath/SingularMatrixException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | /** 30 | * Indicates that inverse of a matrix can not be computed. 31 | */ 32 | public class SingularMatrixException extends RuntimeException{ 33 | 34 | /** 35 | * Create the exception object with default values. 36 | */ 37 | public SingularMatrixException(){ 38 | } 39 | 40 | /** 41 | * Create the exception object that outputs message. 42 | * @param str the message string to be output. 43 | */ 44 | public SingularMatrixException(String str){ 45 | 46 | super(str); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/javax/vecmath/MismatchedSizeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | /** 30 | * Indicates that an operation cannot be completed properly because 31 | * of a mismatch in the sizes of object attributes. 32 | */ 33 | public class MismatchedSizeException extends RuntimeException{ 34 | 35 | 36 | /** 37 | * Create the exception object with default values. 38 | */ 39 | public MismatchedSizeException(){ 40 | } 41 | 42 | /** 43 | * Create the exception object that outputs a message. 44 | * @param str the message string to be output. 45 | */ 46 | public MismatchedSizeException(String str){ 47 | 48 | super(str); 49 | } 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/javax/vecmath/VecMathUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | /** 30 | * Utility vecmath class used when computing the hash code for vecmath 31 | * objects containing float or double values. This fixes Issue 36. 32 | */ 33 | class VecMathUtil { 34 | /** 35 | * Do not construct an instance of this class. 36 | */ 37 | private VecMathUtil() {} 38 | 39 | static final long hashLongBits(long hash, long l) { 40 | hash *= 31L; 41 | return hash + l; 42 | } 43 | 44 | static final long hashFloatBits(long hash, float f) { 45 | hash *= 31L; 46 | // Treat 0.0d and -0.0d the same (all zero bits) 47 | if (f == 0.0f) 48 | return hash; 49 | 50 | return hash + Float.floatToIntBits(f); 51 | } 52 | 53 | static final long hashDoubleBits(long hash, double d) { 54 | hash *= 31L; 55 | // Treat 0.0d and -0.0d the same (all zero bits) 56 | if (d == 0.0d) 57 | return hash; 58 | 59 | return hash + Double.doubleToLongBits(d); 60 | } 61 | 62 | /** 63 | * Return an integer hash from a long by mixing it with itself. 64 | */ 65 | static final int hashFinish(long hash) { 66 | return (int)(hash ^ (hash >> 32)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point2i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2-element point represented by signed integer x,y 32 | * coordinates. 33 | * 34 | * @since vecmath 1.4 35 | */ 36 | public class Point2i extends Tuple2i implements java.io.Serializable { 37 | 38 | static final long serialVersionUID = 9208072376494084954L; 39 | 40 | /** 41 | * Constructs and initializes a Point2i from the specified 42 | * x and y coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | */ 46 | public Point2i(int x, int y) { 47 | super(x, y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Point2i from the array of length 2. 53 | * @param t the array of length 2 containing x and y in order. 54 | */ 55 | public Point2i(int[] t) { 56 | super(t); 57 | } 58 | 59 | 60 | /** 61 | * Constructs and initializes a Point2i from the specified Tuple2i. 62 | * @param t1 the Tuple2i containing the initialization x and y 63 | * data. 64 | */ 65 | public Point2i(Tuple2i t1) { 66 | super(t1); 67 | } 68 | 69 | 70 | /** 71 | * Constructs and initializes a Point2i to (0,0). 72 | */ 73 | public Point2i() { 74 | super(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point3i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3 element point represented by signed integer x,y,z 32 | * coordinates. 33 | * 34 | * @since vecmath 1.2 35 | */ 36 | public class Point3i extends Tuple3i implements java.io.Serializable { 37 | 38 | // Compatible with 1.2 39 | static final long serialVersionUID = 6149289077348153921L; 40 | 41 | /** 42 | * Constructs and initializes a Point3i from the specified 43 | * x, y, and z coordinates. 44 | * @param x the x coordinate 45 | * @param y the y coordinate 46 | * @param z the z coordinate 47 | */ 48 | public Point3i(int x, int y, int z) { 49 | super(x, y, z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Point3i from the array of length 3. 55 | * @param t the array of length 3 containing x, y, and z in order. 56 | */ 57 | public Point3i(int[] t) { 58 | super(t); 59 | } 60 | 61 | 62 | /** 63 | * Constructs and initializes a Point3i from the specified Tuple3i. 64 | * @param t1 the Tuple3i containing the initialization x, y, and z 65 | * data. 66 | */ 67 | public Point3i(Tuple3i t1) { 68 | super(t1); 69 | } 70 | 71 | 72 | /** 73 | * Constructs and initializes a Point3i to (0,0,0). 74 | */ 75 | public Point3i() { 76 | super(); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point4i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4 element point represented by signed integer x,y,z,w 32 | * coordinates. 33 | * 34 | * @since vecmath 1.2 35 | */ 36 | public class Point4i extends Tuple4i implements java.io.Serializable { 37 | 38 | // Combatible with 1.2 39 | static final long serialVersionUID = 620124780244617983L; 40 | 41 | /** 42 | * Constructs and initializes a Point4i from the specified 43 | * x, y, z, and w coordinates. 44 | * @param x the x coordinate 45 | * @param y the y coordinate 46 | * @param z the z coordinate 47 | * @param w the w coordinate 48 | */ 49 | public Point4i(int x, int y, int z, int w) { 50 | super(x, y, z, w); 51 | } 52 | 53 | 54 | /** 55 | * Constructs and initializes a Point4i from the array of length 4. 56 | * @param t the array of length 4 containing x, y, z, and w in order. 57 | */ 58 | public Point4i(int[] t) { 59 | super(t); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Point4i from the specified Tuple4i. 65 | * @param t1 the Tuple4i containing the initialization x, y, z, 66 | * and w data. 67 | */ 68 | public Point4i(Tuple4i t1) { 69 | super(t1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Point4i to (0,0,0,0). 75 | */ 76 | public Point4i() { 77 | super(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/javax/vecmath/TexCoord2f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2-element vector that is represented by single-precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class TexCoord2f extends Tuple2f implements java.io.Serializable { 36 | 37 | // Combatible with 1.1 38 | static final long serialVersionUID = 7998248474800032487L; 39 | 40 | /** 41 | * Constructs and initializes a TexCoord2f from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public TexCoord2f(float x, float y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a TexCoord2f from the specified array. 53 | * @param v the array of length 2 containing xy in order 54 | */ 55 | public TexCoord2f(float[] v) 56 | { 57 | super(v); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a TexCoord2f from the specified TexCoord2f. 63 | * @param v1 the TexCoord2f containing the initialization x y data 64 | */ 65 | public TexCoord2f(TexCoord2f v1) 66 | { 67 | super(v1); 68 | } 69 | 70 | 71 | /** 72 | * Constructs and initializes a TexCoord2f from the specified Tuple2f. 73 | * @param t1 the Tuple2f containing the initialization x y data 74 | */ 75 | public TexCoord2f(Tuple2f t1) 76 | { 77 | super(t1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a TexCoord2f to (0,0). 83 | */ 84 | public TexCoord2f() 85 | { 86 | super(); 87 | } 88 | 89 | 90 | } 91 | -------------------------------------------------------------------------------- /README-build.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 19 | README-build: build instructions for the vecmath project 20 | 21 | 22 |

Building 23 | the Vecmath Package

24 |

To 25 | build the vecmath package, you must first checkout the vecmath 27 | svn 28 | repository on java.net. For example, run 29 | the svn checkout command as follows:
30 |

31 |
    32 | cd <j3d-root-dir>
    33 | svn checkout https://vecmath.dev.java.net/svn/vecmath/branches/dev-1_6 vecmath 34 |
35 |

36 |

This top-level directory must be named "vecmath". 37 |

38 |

System Requirements 39 |

40 |

Vecmath is 100% Java, so any operating environment that supports 41 | J2SE should work. We have built vecmath on the following 42 | operating environments:
43 |

44 |
    45 |
  • Solaris: Sparc (Ultra60 or better) running Solaris 9
  • 46 |
  • Linux: i386/i586 running SuSE 9 or RedHat 9.0
  • 47 |
  • Windows: Windows/XP (Windows 48 | 2000 should work, but is untested)
    49 |
  • 50 |
51 |

The following software must be installed:

52 | 58 |

Building 59 | Vecmath

61 |

62 | 63 |

Before you start building, 65 | please check that your PATH must 66 | include the 67 | following directories:

68 |
    69 |
  • <ant-root-dir>/bin
  • 70 |
  • <jdk-root_dir>/bin
  • 71 |
72 |

The default target, jar-opt, creates an optimized jar files.
73 |

74 |

Steps: 75 |

76 |
    77 | cd <j3d-root-dir>/vecmath
    78 | ant
    79 |
80 |

This will build the javax.vecmath package, which will 81 | be put 82 | in the vecmath/build/opt sub-directory.
83 |

84 |

To see other targets that are available, type "ant 85 | -projecthelp". Note that ant must be run from the top-level 86 | directory.

87 | 88 | 89 | -------------------------------------------------------------------------------- /src/javax/vecmath/TexCoord3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3 element texture coordinate that is represented by single precision 32 | * floating point x,y,z coordinates. 33 | * 34 | */ 35 | public class TexCoord3f extends Tuple3f implements java.io.Serializable { 36 | 37 | // Combatible with 1.1 38 | static final long serialVersionUID = -3517736544731446513L; 39 | 40 | /** 41 | * Constructs and initializes a TexCoord3f from the specified xyz 42 | * coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public TexCoord3f(float x, float y, float z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a TexCoord3f from the array of length 3. 55 | * @param v the array of length 3 containing xyz in order 56 | */ 57 | public TexCoord3f(float[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a TexCoord3f from the specified TexCoord3f. 65 | * @param v1 the TexCoord3f containing the initialization x y z data 66 | */ 67 | public TexCoord3f(TexCoord3f v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a TexCoord3f from the specified Tuple3f. 75 | * @param t1 the Tuple3f containing the initialization x y z data 76 | */ 77 | public TexCoord3f(Tuple3f t1) 78 | { 79 | super(t1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a TexCoord3f from the specified Tuple3d. 85 | * @param t1 the Tuple3d containing the initialization x y z data 86 | */ 87 | public TexCoord3f(Tuple3d t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a TexCoord3f to (0,0,0). 95 | */ 96 | public TexCoord3f() 97 | { 98 | super(); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/javax/vecmath/TexCoord4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4 element texture coordinate that is represented by single precision 32 | * floating point x,y,z,w coordinates. 33 | * 34 | * @since vecmath 1.3 35 | */ 36 | public class TexCoord4f extends Tuple4f implements java.io.Serializable { 37 | 38 | // Combatible with 1.1 39 | static final long serialVersionUID = -3517736544731446513L; 40 | 41 | /** 42 | * Constructs and initializes a TexCoord4f from the specified xyzw 43 | * coordinates. 44 | * @param x the x coordinate 45 | * @param y the y coordinate 46 | * @param z the z coordinate 47 | * @param w the w coordinate 48 | */ 49 | public TexCoord4f(float x, float y, float z, float w) 50 | { 51 | super(x,y,z,w); 52 | } 53 | 54 | 55 | /** 56 | * Constructs and initializes a TexCoord4f from the array of length 4. 57 | * @param v the array of length w containing xyzw in order 58 | */ 59 | public TexCoord4f(float[] v) 60 | { 61 | super(v); 62 | } 63 | 64 | 65 | /** 66 | * Constructs and initializes a TexCoord4f from the specified TexCoord4f. 67 | * @param v1 the TexCoord4f containing the initialization x y z w data 68 | */ 69 | public TexCoord4f(TexCoord4f v1) 70 | { 71 | super(v1); 72 | } 73 | 74 | 75 | /** 76 | * Constructs and initializes a TexCoord4f from the specified Tuple4f. 77 | * @param t1 the Tuple4f containing the initialization x y z w data 78 | */ 79 | public TexCoord4f(Tuple4f t1) 80 | { 81 | super(t1); 82 | } 83 | 84 | 85 | /** 86 | * Constructs and initializes a TexCoord4f from the specified Tuple4d. 87 | * @param t1 the Tuple4d containing the initialization x y z w data 88 | */ 89 | public TexCoord4f(Tuple4d t1) 90 | { 91 | super(t1); 92 | } 93 | 94 | 95 | /** 96 | * Constructs and initializes a TexCoord4f to (0,0,0,0). 97 | */ 98 | public TexCoord4f() 99 | { 100 | super(); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /COPYRIGHT.txt: -------------------------------------------------------------------------------- 1 | Copyright 1996-2008 Sun Microsystems, Inc., 4150 Network Circle, Santa 2 | Clara, California 95054, U.S.A. All rights reserved. 3 | 4 | Sun Microsystems, Inc. has intellectual property rights relating to 5 | technology embodied in the product that is described in this 6 | document. In particular, and without limitation, these intellectual 7 | property rights may include one or more of the U.S. patents listed at 8 | http://www.sun.com/patents and one or more additional patents or 9 | pending patent applications in the U.S. and in other countries. 10 | 11 | U.S. Government Rights - Commercial software. Government users are 12 | subject to the Sun Microsystems, Inc. standard license agreement and 13 | applicable provisions of the FAR and its supplements. 14 | 15 | Use is subject to license terms. 16 | 17 | This distribution may include materials developed by third parties. 18 | 19 | Parts of the product may be derived from Berkeley BSD systems, 20 | licensed from the University of California. UNIX is a registered 21 | trademark in the U.S. and in other countries, exclusively licensed 22 | through X/Open Company, Ltd. 23 | 24 | Sun, Sun Microsystems, the Sun logo, Java, Solaris, Java 3D, the 100% 25 | Pure Java logo, the Duke logo and the Java Coffee Cup logo are 26 | trademarks or registered trademarks of Sun Microsystems, Inc. in the 27 | U.S. and other countries. 28 | 29 | This product is covered and controlled by U.S. Export Control laws and 30 | may be subject to the export or import laws in other countries. 31 | Nuclear, missile, chemical biological weapons or nuclear maritime end 32 | uses or end users, whether direct or indirect, are strictly 33 | prohibited. Export or reexport to countries subject to U.S. embargo or 34 | to entities identified on U.S. export exclusion lists, including, but 35 | not limited to, the denied persons and specially designated nationals 36 | lists is strictly prohibited. 37 | 38 | Copyright 1996-2008 Sun Microsystems, Inc., 4150 Network Circle, Santa 39 | Clara, California 95054, Etats-Unis. Tous droits réservés. 40 | 41 | Sun Microsystems, Inc. détient les droits de propriété intellectuels 42 | relatifs à la technologie incorporée dans le produit qui est décrit 43 | dans ce document. En particulier, et ce sans limitation, ces droits de 44 | propriété intellectuelle peuvent inclure un ou plus des brevets 45 | américains listés à l'adresse http://www.sun.com/patents et un ou les 46 | brevets supplémentaires ou les applications de brevet en attente aux 47 | Etats - Unis et dans les autres pays. 48 | 49 | L'utilisation est soumise aux termes de la Licence. 50 | 51 | Cette distribution peut comprendre des composants développés par des 52 | tierces parties. 53 | 54 | Des parties de ce produit pourront être dérivées des systèmes Berkeley 55 | BSD licenciés par l'Université de Californie. UNIX est une marque 56 | déposée aux Etats-Unis et dans d'autres pays et licenciée 57 | exclusivement par X/Open Company, Ltd. 58 | 59 | Sun, Sun Microsystems, le logo Sun, Java, Solaris, Java 3D, le logo 60 | 100% Pure Java, le logo Duke et le logo Java Coffee Cup sont des 61 | marques de fabrique ou des marques déposées de Sun Microsystems, 62 | Inc. aux Etats-Unis et dans d'autres pays. 63 | 64 | Ce produit est soumis à la législation américaine en matière de 65 | contrôle des exportations et peut être soumis à la règlementation en 66 | vigueur dans d'autres pays dans le domaine des exportations et 67 | importations. Les utilisations, ou utilisateurs finaux, pour des armes 68 | nucléaires,des missiles, des armes biologiques et chimiques ou du 69 | nucléaire maritime, directement ou indirectement, sont strictement 70 | interdites. Les exportations ou réexportations vers les pays sous 71 | embargo américain, ou vers des entités figurant sur les listes 72 | d'exclusion d'exportation américaines, y compris, mais de manière non 73 | exhaustive, la liste de personnes qui font objet d'un ordre de ne pas 74 | participer, d'une façon directe ou indirecte, aux exportations des 75 | produits ou des services qui sont régis par la législation américaine 76 | en matière de contrôle des exportations et la liste de ressortissants 77 | spécifiquement désignés, sont rigoureusement interdites. 78 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point2d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2 element point that is represented by double precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Point2d extends Tuple2d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 1133748791492571954L; 39 | 40 | /** 41 | * Constructs and initializes a Point2d from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Point2d(double x, double y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Point2d from the specified array. 53 | * @param p the array of length 2 containing xy in order 54 | */ 55 | public Point2d(double[] p) 56 | { 57 | super(p); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Point2d from the specified Point2d. 63 | * @param p1 the Point2d containing the initialization x y data 64 | */ 65 | public Point2d(Point2d p1) 66 | { 67 | super(p1); 68 | } 69 | 70 | 71 | /** 72 | * Constructs and initializes a Point2d from the specified Point2f. 73 | * @param p1 the Point2f containing the initialization x y data 74 | */ 75 | public Point2d(Point2f p1) 76 | { 77 | super(p1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Point2d from the specified Tuple2d. 83 | * @param t1 the Tuple2d containing the initialization x y data 84 | */ 85 | public Point2d(Tuple2d t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | /** 92 | * Constructs and initializes a Point2d from the specified Tuple2f. 93 | * @param t1 the Tuple2f containing the initialization x y data 94 | */ 95 | public Point2d(Tuple2f t1) 96 | { 97 | super(t1); 98 | } 99 | 100 | 101 | /** 102 | * Constructs and initializes a Point2d to (0,0). 103 | */ 104 | public Point2d() 105 | { 106 | super(); 107 | } 108 | 109 | /** 110 | * Computes the square of the distance between this point and point p1. 111 | * @param p1 the other point 112 | */ 113 | public final double distanceSquared(Point2d p1) 114 | { 115 | double dx, dy; 116 | 117 | dx = this.x-p1.x; 118 | dy = this.y-p1.y; 119 | return dx*dx+dy*dy; 120 | } 121 | 122 | /** 123 | * Computes the distance between this point and point p1. 124 | * @param p1 the other point 125 | */ 126 | public final double distance(Point2d p1) 127 | { 128 | double dx, dy; 129 | 130 | dx = this.x-p1.x; 131 | dy = this.y-p1.y; 132 | return Math.sqrt(dx*dx+dy*dy); 133 | } 134 | 135 | 136 | /** 137 | * Computes the L-1 (Manhattan) distance between this point and 138 | * point p1. The L-1 distance is equal to abs(x1-x2) + abs(y1-y2). 139 | * @param p1 the other point 140 | */ 141 | public final double distanceL1(Point2d p1) 142 | { 143 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y)); 144 | } 145 | 146 | /** 147 | * Computes the L-infinite distance between this point and 148 | * point p1. The L-infinite distance is equal to 149 | * MAX[abs(x1-x2), abs(y1-y2)]. 150 | * @param p1 the other point 151 | */ 152 | public final double distanceLinf(Point2d p1) 153 | { 154 | return(Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y))); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point2f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2 element point that is represented by single precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Point2f extends Tuple2f implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = -4801347926528714435L; 39 | 40 | /** 41 | * Constructs and initializes a Point2f from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Point2f(float x, float y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Point2f from the specified array. 53 | * @param p the array of length 2 containing xy in order 54 | */ 55 | public Point2f(float[] p) 56 | { 57 | super(p); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Point2f from the specified Point2f. 63 | * @param p1 the Point2f containing the initialization x y data 64 | */ 65 | public Point2f(Point2f p1) 66 | { 67 | super(p1); 68 | } 69 | 70 | /** 71 | * Constructs and initializes a Point2f from the specified Point2d. 72 | * @param p1 the Point2d containing the initialization x y z data 73 | */ 74 | public Point2f(Point2d p1) 75 | { 76 | super(p1); 77 | } 78 | 79 | 80 | 81 | /** 82 | * Constructs and initializes a Point2f from the specified Tuple2d. 83 | * @param t1 the Tuple2d containing the initialization x y z data 84 | */ 85 | public Point2f(Tuple2d t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | 92 | /** 93 | * Constructs and initializes a Point2f from the specified Tuple2f. 94 | * @param t1 the Tuple2f containing the initialization x y data 95 | */ 96 | public Point2f(Tuple2f t1) 97 | { 98 | super(t1); 99 | } 100 | 101 | 102 | /** 103 | * Constructs and initializes a Point2f to (0,0). 104 | */ 105 | public Point2f() 106 | { 107 | super(); 108 | } 109 | 110 | /** 111 | * Computes the square of the distance between this point and point p1. 112 | * @param p1 the other point 113 | */ 114 | public final float distanceSquared(Point2f p1) 115 | { 116 | float dx, dy; 117 | 118 | dx = this.x-p1.x; 119 | dy = this.y-p1.y; 120 | return dx*dx+dy*dy; 121 | } 122 | 123 | /** 124 | * Computes the distance between this point and point p1. 125 | * @param p1 the other point 126 | */ 127 | public final float distance(Point2f p1) 128 | { 129 | float dx, dy; 130 | 131 | dx = this.x-p1.x; 132 | dy = this.y-p1.y; 133 | return (float) Math.sqrt(dx*dx+dy*dy); 134 | } 135 | 136 | 137 | /** 138 | * Computes the L-1 (Manhattan) distance between this point and 139 | * point p1. The L-1 distance is equal to abs(x1-x2) + abs(y1-y2). 140 | * @param p1 the other point 141 | */ 142 | public final float distanceL1(Point2f p1) 143 | { 144 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y)); 145 | } 146 | 147 | /** 148 | * Computes the L-infinite distance between this point and 149 | * point p1. The L-infinite distance is equal to 150 | * MAX[abs(x1-x2), abs(y1-y2)]. 151 | * @param p1 the other point 152 | */ 153 | public final float distanceLinf(Point2f p1) 154 | { 155 | return(Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y))); 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color3b.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A three-byte color value represented by byte x, y, and z values. The 34 | * x, y, and z values represent the red, green, and blue values, 35 | * respectively. 36 | *

37 | * Note that Java defines a byte as a signed integer in the range 38 | * [-128, 127]. However, colors are more typically represented by values 39 | * in the range [0, 255]. Java 3D recognizes this and for color 40 | * treats the bytes as if the range were [0, 255]---in other words, as 41 | * if the bytes were unsigned. 42 | *

43 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 44 | * all colors. 45 | * 46 | */ 47 | public class Color3b extends Tuple3b implements java.io.Serializable { 48 | 49 | // Compatible with 1.1 50 | static final long serialVersionUID = 6632576088353444794L; 51 | 52 | /** 53 | * Constructs and initializes a Color3b from the specified three values. 54 | * @param c1 the red color value 55 | * @param c2 the green color value 56 | * @param c3 the blue color value 57 | */ 58 | public Color3b(byte c1, byte c2, byte c3) { 59 | super(c1,c2,c3); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Color3b from input array of length 3. 65 | * @param c the array of length 3 containing the r,g,b data in order 66 | */ 67 | public Color3b(byte[] c) { 68 | super(c); 69 | } 70 | 71 | 72 | /** 73 | * Constructs and initializes a Color3b from the specified Color3b. 74 | * @param c1 the Color3b containing the initialization r,g,b data 75 | */ 76 | public Color3b(Color3b c1) { 77 | super(c1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Color3b from the specified Tuple3b. 83 | * @param t1 the Tuple3b containing the initialization r,g,b data 84 | */ 85 | public Color3b(Tuple3b t1) { 86 | super(t1); 87 | } 88 | 89 | 90 | /** 91 | * Constructs and initializes a Color3b from the specified AWT 92 | * Color object. The alpha value of the AWT color is ignored. 93 | * No conversion is done on the color to compensate for 94 | * gamma correction. 95 | * 96 | * @param color the AWT color with which to initialize this 97 | * Color3b object 98 | * 99 | * @since vecmath 1.2 100 | */ 101 | public Color3b(Color color) { 102 | super((byte)color.getRed(), 103 | (byte)color.getGreen(), 104 | (byte)color.getBlue()); 105 | } 106 | 107 | 108 | /** 109 | * Constructs and initializes a Color3b to (0,0,0). 110 | */ 111 | public Color3b() { 112 | super(); 113 | } 114 | 115 | 116 | /** 117 | * Sets the r,g,b values of this Color3b object to those of the 118 | * specified AWT Color object. 119 | * No conversion is done on the color to compensate for 120 | * gamma correction. 121 | * 122 | * @param color the AWT color to copy into this Color3b object 123 | * 124 | * @since vecmath 1.2 125 | */ 126 | public final void set(Color color) { 127 | x = (byte)color.getRed(); 128 | y = (byte)color.getGreen(); 129 | z = (byte)color.getBlue(); 130 | } 131 | 132 | 133 | /** 134 | * Returns a new AWT color object initialized with the r,g,b 135 | * values of this Color3b object. 136 | * 137 | * @return a new AWT Color object 138 | * 139 | * @since vecmath 1.2 140 | */ 141 | public final Color get() { 142 | int r = (int)x & 0xff; 143 | int g = (int)y & 0xff; 144 | int b = (int)z & 0xff; 145 | 146 | return new Color(r, g, b); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/javax/vecmath/ExceptionStrings.properties: -------------------------------------------------------------------------------- 1 | Matrix3d0=Matrix3d setElement 2 | Matrix3d1=Matrix3d getElement 3 | Matrix3d2=Matrix3d getRow 4 | Matrix3d4=Matrix3d getColumn 5 | Matrix3d6=Matrix3d setRow 6 | Matrix3d9=Matrix3d setColumn 7 | Matrix3d12=cannot invert matrix 8 | Matrix3d13=Logic error: imax < 0 9 | Matrix3f0=Matrix3f setElement 10 | Matrix3f1=Matrix3d getRow 11 | Matrix3f3=Matrix3d getColumn 12 | Matrix3f5=Matrix3f getElement 13 | Matrix3f6=Matrix3f setRow 14 | Matrix3f9=Matrix3f setColumn 15 | Matrix3f12=cannot invert matrix 16 | Matrix3f13=Logic error: imax < 0 17 | Matrix4d0=Matrix4d setElement 18 | Matrix4d1=Matrix4d getElement 19 | Matrix4d2=Matrix4d getRow 20 | Matrix4d3=Matrix4d getColumn 21 | Matrix4d4=Matrix4d setRow 22 | Matrix4d7=Matrix4d setColumn 23 | Matrix4d10=cannot invert matrix 24 | Matrix4d11=Logic error: imax < 0 25 | Matrix4f0=Matrix4f setElement 26 | Matrix4f1=Matrix4f getElement 27 | Matrix4f2=Matrix4f getRow 28 | Matrix4f4=Matrix4f getColumn 29 | Matrix4f6=Matrix4f setRow 30 | Matrix4f9=Matrix4f setColumn 31 | Matrix4f12=cannot invert matrix 32 | Matrix4f13=Logic error: imax < 0 33 | GMatrix0=GMatrix.mul:array dimension mismatch 34 | GMatrix1=GMatrix.mul(GMatrix, GMatrix) dimension mismatch 35 | GMatrix2=GMatrix.mul(GVector, GVector): matrix does not have enough rows 36 | GMatrix3=GMatrix.mul(GVector, GVector): matrix does not have enough columns 37 | GMatrix4=GMatrix.add(GMatrix): row dimension mismatch 38 | GMatrix5=GMatrix.add(GMatrix): column dimension mismatch 39 | GMatrix6=GMatrix.add(GMatrix, GMatrix): row dimension mismatch 40 | GMatrix7=GMatrix.add(GMatrix, GMatrix): column dimension mismatch 41 | GMatrix8=GMatrix.add(GMatrix): input matrices dimensions do not match this matrix dimensions 42 | GMatrix9=GMatrix.sub(GMatrix): row dimension mismatch 43 | GMatrix10=GMatrix.sub(GMatrix, GMatrix): row dimension mismatch 44 | GMatrix11=GMatrix.sub(GMatrix, GMatrix): column dimension mismatch 45 | GMatrix12=GMatrix.sub(GMatrix, GMatrix): input matrix dimensions do not match dimensions for this matrix 46 | GMatrix13=GMatrix.negate(GMatrix, GMatrix): input matrix dimensions do not match dimensions for this matrix 47 | GMatrix14=GMatrix.mulTransposeBoth matrix dimension mismatch 48 | GMatrix15=GMatrix.mulTransposeRight matrix dimension mismatch 49 | GMatrix16=GMatrix.mulTransposeLeft matrix dimension mismatch 50 | GMatrix17=GMatrix.transpose(GMatrix) mismatch in matrix dimensions 51 | GMatrix18=GMatrix.SVD: dimension mismatch with V matrix 52 | GMatrix19=cannot perform LU decomposition on a non square matrix 53 | GMatrix20=row permutation must be same dimension as matrix 54 | GMatrix21=cannot invert matrix 55 | GMatrix22=cannot invert non square matrix 56 | GMatrix24=Logic error: imax < 0 57 | GMatrix25=GMatrix.SVD: dimension mismatch with U matrix 58 | GMatrix26=GMatrix.SVD: dimension mismatch with W matrix 59 | GMatrix27=LU must have same dimensions as this matrix 60 | GMatrix28=GMatrix.sub(GMatrix): column dimension mismatch 61 | GVector0=GVector.normalize( GVector) input vector and this vector lengths not matched 62 | GVector1=GVector.scale(double, GVector) input vector and this vector lengths not matched 63 | GVector2=GVector.scaleAdd(GVector, GVector) input vector dimensions not matched 64 | GVector3=GVector.scaleAdd(GVector, GVector) input vectors and this vector dimensions not matched 65 | GVector4=GVector.add(GVector) input vectors and this vector dimensions not matched 66 | GVector5=GVector.add(GVector, GVector) input vector dimensions not matched 67 | GVector6=GVector.add(GVector, GVector) input vectors and this vector dimensions not matched 68 | GVector7=GVector.sub(GVector) input vector and this vector dimensions not matched 69 | GVector8=GVector.sub(GVector, GVector) input vector dimensions not matched 70 | GVector9=GVector.sub(GMatrix, GVector) input vectors and this vector dimensions not matched 71 | GVector10=GVector.mul(GMatrix, GVector) matrix and vector dimensions not matched 72 | GVector11=GVector.mul(GMatrix, GVector) matrix this vector dimensions not matched 73 | GVector12=GVector.mul(GVector, GMatrix) matrix and vector dimensions not matched 74 | GVector13=GVector.mul(GVector, GMatrix) matrix this vector dimensions not matched 75 | GVector14=GVector.dot(GVector) input vector and this vector have different sizes 76 | GVector15=matrix dimensions are not compatible 77 | GVector16=b vector does not match matrix dimension 78 | GVector17=GVector.interpolate(GVector, GVector, float) input vectors have different lengths 79 | GVector18=GVector.interpolate(GVector, GVector, float) input vectors and this vector have different lengths 80 | GVector19=GVector.interpolate(GVector, float) input vector and this vector have different lengths 81 | GVector20=GVector.interpolate(GVector, GVector, double) input vectors have different lengths 82 | GVector21=GVector.interpolate(GVector, GVector, double) input vectors and this vector have different lengths 83 | GVector22=GVector.interpolate(GVector, double) input vectors and this vector have different lengths 84 | GVector23=matrix dimensions are not compatible 85 | GVector24=permutation vector does not match matrix dimension 86 | GVector25=LUDBackSolve non square matrix 87 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A three-element color value represented by single precision floating 34 | * point x,y,z values. The x,y,z values represent the red, green, and 35 | * blue color values, respectively. Color components should be in the 36 | * range of [0.0, 1.0]. 37 | *

38 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 39 | * all colors. 40 | * 41 | */ 42 | public class Color3f extends Tuple3f implements java.io.Serializable { 43 | 44 | // Compatible with 1.1 45 | static final long serialVersionUID = -1861792981817493659L; 46 | 47 | /** 48 | * Constructs and initializes a Color3f from the three xyz values. 49 | * @param x the red color value 50 | * @param y the green color value 51 | * @param z the blue color value 52 | */ 53 | public Color3f(float x, float y, float z) { 54 | super(x,y,z); 55 | } 56 | 57 | 58 | /** 59 | * Constructs and initializes a Color3f from the array of length 3. 60 | * @param v the array of length 3 containing xyz in order 61 | */ 62 | public Color3f(float[] v) { 63 | super(v); 64 | } 65 | 66 | 67 | /** 68 | * Constructs and initializes a Color3f from the specified Color3f. 69 | * @param v1 the Color3f containing the initialization x y z data 70 | */ 71 | public Color3f(Color3f v1) { 72 | super(v1); 73 | } 74 | 75 | 76 | /** 77 | * Constructs and initializes a Color3f from the specified Tuple3f. 78 | * @param t1 the Tuple3f containing the initialization x y z data 79 | */ 80 | public Color3f(Tuple3f t1) { 81 | super(t1); 82 | } 83 | 84 | 85 | /** 86 | * Constructs and initializes a Color3f from the specified Tuple3d. 87 | * @param t1 the Tuple3d containing the initialization x y z data 88 | */ 89 | public Color3f(Tuple3d t1) { 90 | super(t1); 91 | } 92 | 93 | 94 | /** 95 | * Constructs and initializes a Color3f from the specified AWT 96 | * Color object. The alpha value of the AWT color is ignored. 97 | * No conversion is done on the color to compensate for 98 | * gamma correction. 99 | * 100 | * @param color the AWT color with which to initialize this 101 | * Color3f object 102 | * 103 | * @since vecmath 1.2 104 | */ 105 | public Color3f(Color color) { 106 | super((float)color.getRed() / 255.0f, 107 | (float)color.getGreen() / 255.0f, 108 | (float)color.getBlue() / 255.0f); 109 | } 110 | 111 | 112 | /** 113 | * Constructs and initializes a Color3f to (0.0, 0.0, 0.0). 114 | */ 115 | public Color3f() { 116 | super(); 117 | } 118 | 119 | 120 | /** 121 | * Sets the r,g,b values of this Color3f object to those of the 122 | * specified AWT Color object. 123 | * No conversion is done on the color to compensate for 124 | * gamma correction. 125 | * 126 | * @param color the AWT color to copy into this Color3f object 127 | * 128 | * @since vecmath 1.2 129 | */ 130 | public final void set(Color color) { 131 | x = (float)color.getRed() / 255.0f; 132 | y = (float)color.getGreen() / 255.0f; 133 | z = (float)color.getBlue() / 255.0f; 134 | } 135 | 136 | 137 | /** 138 | * Returns a new AWT color object initialized with the r,g,b 139 | * values of this Color3f object. 140 | * 141 | * @return a new AWT Color object 142 | * 143 | * @since vecmath 1.2 144 | */ 145 | public final Color get() { 146 | int r = Math.round(x * 255.0f); 147 | int g = Math.round(y * 255.0f); 148 | int b = Math.round(z * 255.0f); 149 | 150 | return new Color(r, g, b); 151 | } 152 | 153 | } 154 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color4b.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A four-byte color value represented by byte x, y, z, and w values. 34 | * The x, y, z, and w values represent the red, green, blue, and alpha 35 | * values, respectively. 36 | *

37 | * Note that Java defines a byte as a signed integer in the range 38 | * [-128, 127]. However, colors are more typically represented by values 39 | * in the range [0, 255]. Java 3D recognizes this and for color 40 | * treats the bytes as if the range were [0, 255]---in other words, as 41 | * if the bytes were unsigned. 42 | *

43 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 44 | * all colors. 45 | * 46 | */ 47 | public class Color4b extends Tuple4b implements java.io.Serializable { 48 | 49 | // Compatible with 1.1 50 | static final long serialVersionUID = -105080578052502155L; 51 | 52 | /** 53 | * Constructs and initializes a Color4b from the four specified values. 54 | * @param b1 the red color value 55 | * @param b2 the green color value 56 | * @param b3 the blue color value 57 | * @param b4 the alpha value 58 | */ 59 | public Color4b(byte b1, byte b2, byte b3, byte b4) { 60 | super(b1,b2,b3,b4); 61 | } 62 | 63 | 64 | /** 65 | * Constructs and initializes a Color4b from the array of length 4. 66 | * @param c the array of length 4 containing r, g, b, and alpha in order 67 | */ 68 | public Color4b(byte[] c) { 69 | super(c); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Color4b from the specified Color4b. 75 | * @param c1 the Color4b containing the initialization r,g,b,a 76 | * data 77 | */ 78 | public Color4b(Color4b c1) { 79 | super(c1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Color4b from the specified Tuple4b. 85 | * @param t1 the Tuple4b containing the initialization r,g,b,a 86 | * data 87 | */ 88 | public Color4b(Tuple4b t1) { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Color4b from the specified AWT 95 | * Color object. 96 | * No conversion is done on the color to compensate for 97 | * gamma correction. 98 | * 99 | * @param color the AWT color with which to initialize this 100 | * Color4b object 101 | * 102 | * @since vecmath 1.2 103 | */ 104 | public Color4b(Color color) { 105 | super((byte)color.getRed(), 106 | (byte)color.getGreen(), 107 | (byte)color.getBlue(), 108 | (byte)color.getAlpha()); 109 | } 110 | 111 | 112 | /** 113 | * Constructs and initializes a Color4b to (0,0,0,0). 114 | */ 115 | public Color4b() { 116 | super(); 117 | } 118 | 119 | 120 | /** 121 | * Sets the r,g,b,a values of this Color4b object to those of the 122 | * specified AWT Color object. 123 | * No conversion is done on the color to compensate for 124 | * gamma correction. 125 | * 126 | * @param color the AWT color to copy into this Color4b object 127 | * 128 | * @since vecmath 1.2 129 | */ 130 | public final void set(Color color) { 131 | x = (byte)color.getRed(); 132 | y = (byte)color.getGreen(); 133 | z = (byte)color.getBlue(); 134 | w = (byte)color.getAlpha(); 135 | } 136 | 137 | 138 | /** 139 | * Returns a new AWT color object initialized with the r,g,b,a 140 | * values of this Color4b object. 141 | * 142 | * @return a new AWT Color object 143 | * 144 | * @since vecmath 1.2 145 | */ 146 | public final Color get() { 147 | int r = (int)x & 0xff; 148 | int g = (int)y & 0xff; 149 | int b = (int)z & 0xff; 150 | int a = (int)w & 0xff; 151 | 152 | return new Color(r, g, b, a); 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/javax/vecmath/Color4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | import java.awt.Color; 30 | 31 | 32 | /** 33 | * A four-element color represented by single precision floating point 34 | * x, y, z, and w values. The x, y, z, and w values represent the red, 35 | * blue, green, and alpha color values, respectively. Color and alpha 36 | * components should be in the range [0.0, 1.0]. 37 | *

38 | * Java 3D assumes that a linear (gamma-corrected) visual is used for 39 | * all colors. 40 | * 41 | */ 42 | public class Color4f extends Tuple4f implements java.io.Serializable { 43 | 44 | // Compatible with 1.1 45 | static final long serialVersionUID = 8577680141580006740L; 46 | 47 | /** 48 | * Constructs and initializes a Color4f from the specified xyzw 49 | * coordinates. 50 | * @param x the red color value 51 | * @param y the green color value 52 | * @param z the blue color value 53 | * @param w the alpha value 54 | */ 55 | public Color4f(float x, float y, float z, float w) { 56 | super(x,y,z,w); 57 | } 58 | 59 | 60 | /** 61 | * Constructs and initializes a Color4f from the array of length 4. 62 | * @param c the array of length 4 containing r,g,b,a in order 63 | */ 64 | public Color4f(float[] c) { 65 | super(c); 66 | } 67 | 68 | 69 | /** 70 | * Constructs and initializes a Color4f from the specified Color4f. 71 | * @param c1 the Color4f containing the initialization r,g,b,a data 72 | */ 73 | public Color4f(Color4f c1) { 74 | super(c1); 75 | } 76 | 77 | 78 | /** 79 | * Constructs and initializes a Color4f from the specified Tuple4f. 80 | * @param t1 the Tuple4f containing the initialization r,g,b,a data 81 | */ 82 | public Color4f(Tuple4f t1) { 83 | super(t1); 84 | } 85 | 86 | 87 | /** 88 | * Constructs and initializes a Color4f from the specified Tuple4d. 89 | * @param t1 the Tuple4d containing the initialization r,g,b,a data 90 | */ 91 | public Color4f(Tuple4d t1) { 92 | super(t1); 93 | } 94 | 95 | 96 | /** 97 | * Constructs and initializes a Color4f from the specified AWT 98 | * Color object. 99 | * No conversion is done on the color to compensate for 100 | * gamma correction. 101 | * 102 | * @param color the AWT color with which to initialize this 103 | * Color4f object 104 | * 105 | * @since vecmath 1.2 106 | */ 107 | public Color4f(Color color) { 108 | super((float)color.getRed() / 255.0f, 109 | (float)color.getGreen() / 255.0f, 110 | (float)color.getBlue() / 255.0f, 111 | (float)color.getAlpha() / 255.0f); 112 | } 113 | 114 | 115 | /** 116 | * Constructs and initializes a Color4f to (0.0, 0.0, 0.0, 0.0). 117 | */ 118 | public Color4f() { 119 | super(); 120 | } 121 | 122 | 123 | /** 124 | * Sets the r,g,b,a values of this Color4f object to those of the 125 | * specified AWT Color object. 126 | * No conversion is done on the color to compensate for 127 | * gamma correction. 128 | * 129 | * @param color the AWT color to copy into this Color4f object 130 | * 131 | * @since vecmath 1.2 132 | */ 133 | public final void set(Color color) { 134 | x = (float)color.getRed() / 255.0f; 135 | y = (float)color.getGreen() / 255.0f; 136 | z = (float)color.getBlue() / 255.0f; 137 | w = (float)color.getAlpha() / 255.0f; 138 | } 139 | 140 | 141 | /** 142 | * Returns a new AWT color object initialized with the r,g,b,a 143 | * values of this Color4f object. 144 | * 145 | * @return a new AWT Color object 146 | * 147 | * @since vecmath 1.2 148 | */ 149 | public final Color get() { 150 | int r = Math.round(x * 255.0f); 151 | int g = Math.round(y * 255.0f); 152 | int b = Math.round(z * 255.0f); 153 | int a = Math.round(w * 255.0f); 154 | 155 | return new Color(r, g, b, a); 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector2f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2-element vector that is represented by single-precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Vector2f extends Tuple2f implements java.io.Serializable { 36 | 37 | // Combatible with 1.1 38 | static final long serialVersionUID = -2168194326883512320L; 39 | 40 | /** 41 | * Constructs and initializes a Vector2f from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Vector2f(float x, float y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Vector2f from the specified array. 53 | * @param v the array of length 2 containing xy in order 54 | */ 55 | public Vector2f(float[] v) 56 | { 57 | super(v); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Vector2f from the specified Vector2f. 63 | * @param v1 the Vector2f containing the initialization x y data 64 | */ 65 | public Vector2f(Vector2f v1) 66 | { 67 | super(v1); 68 | } 69 | 70 | 71 | /** 72 | * Constructs and initializes a Vector2f from the specified Vector2d. 73 | * @param v1 the Vector2d containing the initialization x y data 74 | */ 75 | public Vector2f(Vector2d v1) 76 | { 77 | super(v1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Vector2f from the specified Tuple2f. 83 | * @param t1 the Tuple2f containing the initialization x y data 84 | */ 85 | public Vector2f(Tuple2f t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | /** 92 | * Constructs and initializes a Vector2f from the specified Tuple2d. 93 | * @param t1 the Tuple2d containing the initialization x y data 94 | */ 95 | public Vector2f(Tuple2d t1) 96 | { 97 | super(t1); 98 | } 99 | 100 | 101 | 102 | /** 103 | * Constructs and initializes a Vector2f to (0,0). 104 | */ 105 | public Vector2f() 106 | { 107 | super(); 108 | } 109 | 110 | 111 | /** 112 | * Computes the dot product of the this vector and vector v1. 113 | * @param v1 the other vector 114 | */ 115 | public final float dot(Vector2f v1) 116 | { 117 | return (this.x*v1.x + this.y*v1.y); 118 | } 119 | 120 | 121 | /** 122 | * Returns the length of this vector. 123 | * @return the length of this vector 124 | */ 125 | public final float length() 126 | { 127 | return (float) Math.sqrt(this.x*this.x + this.y*this.y); 128 | } 129 | 130 | /** 131 | * Returns the squared length of this vector. 132 | * @return the squared length of this vector 133 | */ 134 | public final float lengthSquared() 135 | { 136 | return (this.x*this.x + this.y*this.y); 137 | } 138 | 139 | /** 140 | * Sets the value of this vector to the normalization of vector v1. 141 | * @param v1 the un-normalized vector 142 | */ 143 | public final void normalize(Vector2f v1) 144 | { 145 | float norm; 146 | 147 | norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y)); 148 | this.x = v1.x*norm; 149 | this.y = v1.y*norm; 150 | } 151 | 152 | /** 153 | * Normalizes this vector in place. 154 | */ 155 | public final void normalize() 156 | { 157 | float norm; 158 | 159 | norm = (float) 160 | (1.0/Math.sqrt(this.x*this.x + this.y*this.y)); 161 | this.x *= norm; 162 | this.y *= norm; 163 | } 164 | 165 | 166 | /** 167 | * Returns the angle in radians between this vector and the vector 168 | * parameter; the return value is constrained to the range [0,PI]. 169 | * @param v1 the other vector 170 | * @return the angle in radians in the range [0,PI] 171 | */ 172 | public final float angle(Vector2f v1) 173 | { 174 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 175 | if( vDot < -1.0) vDot = -1.0; 176 | if( vDot > 1.0) vDot = 1.0; 177 | return((float) (Math.acos( vDot ))); 178 | } 179 | 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector2d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2-element vector that is represented by double-precision floating 32 | * point x,y coordinates. 33 | * 34 | */ 35 | public class Vector2d extends Tuple2d implements java.io.Serializable { 36 | 37 | // Combatible with 1.1 38 | static final long serialVersionUID = 8572646365302599857L; 39 | 40 | /** 41 | * Constructs and initializes a Vector2d from the specified xy coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | */ 45 | public Vector2d(double x, double y) 46 | { 47 | super(x,y); 48 | } 49 | 50 | 51 | /** 52 | * Constructs and initializes a Vector2d from the specified array. 53 | * @param v the array of length 2 containing xy in order 54 | */ 55 | public Vector2d(double[] v) 56 | { 57 | super(v); 58 | } 59 | 60 | 61 | /** 62 | * Constructs and initializes a Vector2d from the specified Vector2d. 63 | * @param v1 the Vector2d containing the initialization x y data 64 | */ 65 | public Vector2d(Vector2d v1) 66 | { 67 | super(v1); 68 | } 69 | 70 | 71 | /** 72 | * Constructs and initializes a Vector2d from the specified Vector2f. 73 | * @param v1 the Vector2f containing the initialization x y data 74 | */ 75 | public Vector2d(Vector2f v1) 76 | { 77 | super(v1); 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Vector2d from the specified Tuple2d. 83 | * @param t1 the Tuple2d containing the initialization x y data 84 | */ 85 | public Vector2d(Tuple2d t1) 86 | { 87 | super(t1); 88 | } 89 | 90 | 91 | /** 92 | * Constructs and initializes a Vector2d from the specified Tuple2f. 93 | * @param t1 the Tuple2f containing the initialization x y data 94 | */ 95 | public Vector2d(Tuple2f t1) 96 | { 97 | super(t1); 98 | } 99 | 100 | 101 | /** 102 | * Constructs and initializes a Vector2d to (0,0). 103 | */ 104 | public Vector2d() 105 | { 106 | super(); 107 | } 108 | 109 | 110 | /** 111 | * Computes the dot product of the this vector and vector v1. 112 | * @param v1 the other vector 113 | */ 114 | public final double dot(Vector2d v1) 115 | { 116 | return (this.x*v1.x + this.y*v1.y); 117 | } 118 | 119 | 120 | /** 121 | * Returns the length of this vector. 122 | * @return the length of this vector 123 | */ 124 | public final double length() 125 | { 126 | return (double) Math.sqrt(this.x*this.x + this.y*this.y); 127 | } 128 | 129 | /** 130 | * Returns the squared length of this vector. 131 | * @return the squared length of this vector 132 | */ 133 | public final double lengthSquared() 134 | { 135 | return (this.x*this.x + this.y*this.y); 136 | } 137 | 138 | /** 139 | * Sets the value of this vector to the normalization of vector v1. 140 | * @param v1 the un-normalized vector 141 | */ 142 | public final void normalize(Vector2d v1) 143 | { 144 | double norm; 145 | 146 | norm = (double) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y)); 147 | this.x = v1.x*norm; 148 | this.y = v1.y*norm; 149 | } 150 | 151 | /** 152 | * Normalizes this vector in place. 153 | */ 154 | public final void normalize() 155 | { 156 | double norm; 157 | 158 | norm = (double) 159 | (1.0/Math.sqrt(this.x*this.x + this.y*this.y)); 160 | this.x *= norm; 161 | this.y *= norm; 162 | } 163 | 164 | 165 | /** 166 | * Returns the angle in radians between this vector and the vector 167 | * parameter; the return value is constrained to the range [0,PI]. 168 | * @param v1 the other vector 169 | * @return the angle in radians in the range [0,PI] 170 | */ 171 | public final double angle(Vector2d v1) 172 | { 173 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 174 | if( vDot < -1.0) vDot = -1.0; 175 | if( vDot > 1.0) vDot = 1.0; 176 | return((double) (Math.acos( vDot ))); 177 | 178 | } 179 | 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point3d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3 element point that is represented by double precision floating point 32 | * x,y,z coordinates. 33 | * 34 | */ 35 | public class Point3d extends Tuple3d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 5718062286069042927L; 39 | 40 | /** 41 | * Constructs and initializes a Point3d from the specified xyz coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | * @param z the z coordinate 45 | */ 46 | public Point3d(double x, double y, double z) 47 | { 48 | super(x,y,z); 49 | } 50 | 51 | 52 | /** 53 | * Constructs and initializes a Point3d from the array of length 3. 54 | * @param p the array of length 3 containing xyz in order 55 | */ 56 | public Point3d(double[] p) 57 | { 58 | super(p); 59 | } 60 | 61 | 62 | /** 63 | * Constructs and initializes a Point3d from the specified Point3d. 64 | * @param p1 the Point3d containing the initialization x y z data 65 | */ 66 | public Point3d(Point3d p1) 67 | { 68 | super(p1); 69 | } 70 | 71 | 72 | /** 73 | * Constructs and initializes a Point3d from the specified Point3f. 74 | * @param p1 the Point3f containing the initialization x y z data 75 | */ 76 | public Point3d(Point3f p1) 77 | { 78 | super(p1); 79 | } 80 | 81 | 82 | /** 83 | * Constructs and initializes a Point3d from the specified Tuple3f. 84 | * @param t1 the Tuple3f containing the initialization x y z data 85 | */ 86 | public Point3d(Tuple3f t1) 87 | { 88 | super(t1); 89 | } 90 | 91 | 92 | /** 93 | * Constructs and initializes a Point3d from the specified Tuple3d. 94 | * @param t1 the Tuple3d containing the initialization x y z data 95 | */ 96 | public Point3d(Tuple3d t1) 97 | { 98 | super(t1); 99 | } 100 | 101 | 102 | /** 103 | * Constructs and initializes a Point3d to (0,0,0). 104 | */ 105 | public Point3d() 106 | { 107 | super(); 108 | } 109 | 110 | 111 | /** 112 | * Returns the square of the distance between this point and point p1. 113 | * @param p1 the other point 114 | * @return the square of the distance 115 | */ 116 | public final double distanceSquared(Point3d p1) 117 | { 118 | double dx, dy, dz; 119 | 120 | dx = this.x-p1.x; 121 | dy = this.y-p1.y; 122 | dz = this.z-p1.z; 123 | return (dx*dx+dy*dy+dz*dz); 124 | } 125 | 126 | 127 | /** 128 | * Returns the distance between this point and point p1. 129 | * @param p1 the other point 130 | * @return the distance 131 | */ 132 | public final double distance(Point3d p1) 133 | { 134 | double dx, dy, dz; 135 | 136 | dx = this.x-p1.x; 137 | dy = this.y-p1.y; 138 | dz = this.z-p1.z; 139 | return Math.sqrt(dx*dx+dy*dy+dz*dz); 140 | } 141 | 142 | 143 | /** 144 | * Computes the L-1 (Manhattan) distance between this point and 145 | * point p1. The L-1 distance is equal to: 146 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2). 147 | * @param p1 the other point 148 | * @return the L-1 distance 149 | */ 150 | public final double distanceL1(Point3d p1) { 151 | return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + 152 | Math.abs(this.z-p1.z); 153 | } 154 | 155 | 156 | /** 157 | * Computes the L-infinite distance between this point and 158 | * point p1. The L-infinite distance is equal to 159 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)]. 160 | * @param p1 the other point 161 | * @return the L-infinite distance 162 | */ 163 | public final double distanceLinf(Point3d p1) { 164 | double tmp; 165 | tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 166 | 167 | return Math.max(tmp,Math.abs(this.z-p1.z)); 168 | } 169 | 170 | 171 | /** 172 | * Multiplies each of the x,y,z components of the Point4d parameter 173 | * by 1/w and places the projected values into this point. 174 | * @param p1 the source Point4d, which is not modified 175 | */ 176 | public final void project(Point4d p1) 177 | { 178 | double oneOw; 179 | 180 | oneOw = 1/p1.w; 181 | x = p1.x*oneOw; 182 | y = p1.y*oneOw; 183 | z = p1.z*oneOw; 184 | 185 | } 186 | 187 | 188 | } 189 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3 element point that is represented by single precision floating point 32 | * x,y,z coordinates. 33 | * 34 | */ 35 | public class Point3f extends Tuple3f implements java.io.Serializable { 36 | 37 | 38 | // Compatible with 1.1 39 | static final long serialVersionUID = -8689337816398030143L; 40 | 41 | /** 42 | * Constructs and initializes a Point3f from the specified xyz coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public Point3f(float x, float y, float z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Point3f from the array of length 3. 55 | * @param p the array of length 3 containing xyz in order 56 | */ 57 | public Point3f(float[] p) 58 | { 59 | super(p); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Point3f from the specified Point3f. 65 | * @param p1 the Point3f containing the initialization x y z data 66 | */ 67 | public Point3f(Point3f p1) 68 | { 69 | super(p1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Point3f from the specified Point3d. 75 | * @param p1 the Point3d containing the initialization x y z data 76 | */ 77 | public Point3f(Point3d p1) 78 | { 79 | super(p1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Point3f from the specified Tuple3f. 85 | * @param t1 the Tuple3f containing the initialization x y z data 86 | */ 87 | public Point3f(Tuple3f t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Point3f from the specified Tuple3d. 95 | * @param t1 the Tuple3d containing the initialization x y z data 96 | */ 97 | public Point3f(Tuple3d t1) 98 | { 99 | super(t1); 100 | } 101 | 102 | 103 | /** 104 | * Constructs and initializes a Point3f to (0,0,0). 105 | */ 106 | public Point3f() 107 | { 108 | super(); 109 | } 110 | 111 | 112 | /** 113 | * Computes the square of the distance between this point and 114 | * point p1. 115 | * @param p1 the other point 116 | * @return the square of the distance 117 | */ 118 | public final float distanceSquared(Point3f p1) 119 | { 120 | float dx, dy, dz; 121 | 122 | dx = this.x-p1.x; 123 | dy = this.y-p1.y; 124 | dz = this.z-p1.z; 125 | return dx*dx+dy*dy+dz*dz; 126 | } 127 | 128 | 129 | /** 130 | * Computes the distance between this point and point p1. 131 | * @param p1 the other point 132 | * @return the distance 133 | */ 134 | public final float distance(Point3f p1) 135 | { 136 | float dx, dy, dz; 137 | 138 | dx = this.x-p1.x; 139 | dy = this.y-p1.y; 140 | dz = this.z-p1.z; 141 | return (float) Math.sqrt(dx*dx+dy*dy+dz*dz); 142 | } 143 | 144 | 145 | /** 146 | * Computes the L-1 (Manhattan) distance between this point and 147 | * point p1. The L-1 distance is equal to: 148 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2). 149 | * @param p1 the other point 150 | * @return the L-1 distance 151 | */ 152 | public final float distanceL1(Point3f p1) 153 | { 154 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z)); 155 | } 156 | 157 | 158 | /** 159 | * Computes the L-infinite distance between this point and 160 | * point p1. The L-infinite distance is equal to 161 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)]. 162 | * @param p1 the other point 163 | * @return the L-infinite distance 164 | */ 165 | public final float distanceLinf(Point3f p1) 166 | { 167 | float tmp; 168 | tmp = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 169 | return(Math.max(tmp,Math.abs(this.z-p1.z))); 170 | 171 | } 172 | 173 | 174 | /** 175 | * Multiplies each of the x,y,z components of the Point4f parameter 176 | * by 1/w and places the projected values into this point. 177 | * @param p1 the source Point4f, which is not modified 178 | */ 179 | public final void project(Point4f p1) 180 | { 181 | float oneOw; 182 | 183 | oneOw = 1/p1.w; 184 | x = p1.x*oneOw; 185 | y = p1.y*oneOw; 186 | z = p1.z*oneOw; 187 | 188 | } 189 | 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector3d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3-element vector that is represented by double-precision floating point 32 | * x,y,z coordinates. If this value represents a normal, then it should 33 | * be normalized. 34 | * 35 | */ 36 | public class Vector3d extends Tuple3d implements java.io.Serializable { 37 | 38 | // Combatible with 1.1 39 | static final long serialVersionUID = 3761969948420550442L; 40 | 41 | /** 42 | * Constructs and initializes a Vector3d from the specified xyz coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public Vector3d(double x, double y, double z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Vector3d from the array of length 3. 55 | * @param v the array of length 3 containing xyz in order 56 | */ 57 | public Vector3d(double[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Vector3d from the specified Vector3d. 65 | * @param v1 the Vector3d containing the initialization x y z data 66 | */ 67 | public Vector3d(Vector3d v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Vector3d from the specified Vector3f. 75 | * @param v1 the Vector3f containing the initialization x y z data 76 | */ 77 | public Vector3d(Vector3f v1) 78 | { 79 | super(v1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Vector3d from the specified Tuple3f. 85 | * @param t1 the Tuple3f containing the initialization x y z data 86 | */ 87 | public Vector3d(Tuple3f t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Vector3d from the specified Tuple3d. 95 | * @param t1 the Tuple3d containing the initialization x y z data 96 | */ 97 | public Vector3d(Tuple3d t1) 98 | { 99 | super(t1); 100 | } 101 | 102 | 103 | /** 104 | * Constructs and initializes a Vector3d to (0,0,0). 105 | */ 106 | public Vector3d() 107 | { 108 | super(); 109 | } 110 | 111 | 112 | /** 113 | * Sets this vector to the vector cross product of vectors v1 and v2. 114 | * @param v1 the first vector 115 | * @param v2 the second vector 116 | */ 117 | public final void cross(Vector3d v1, Vector3d v2) 118 | { 119 | double x,y; 120 | 121 | x = v1.y*v2.z - v1.z*v2.y; 122 | y = v2.x*v1.z - v2.z*v1.x; 123 | this.z = v1.x*v2.y - v1.y*v2.x; 124 | this.x = x; 125 | this.y = y; 126 | } 127 | 128 | 129 | /** 130 | * Sets the value of this vector to the normalization of vector v1. 131 | * @param v1 the un-normalized vector 132 | */ 133 | public final void normalize(Vector3d v1) 134 | { 135 | double norm; 136 | 137 | norm = 1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z); 138 | this.x = v1.x*norm; 139 | this.y = v1.y*norm; 140 | this.z = v1.z*norm; 141 | } 142 | 143 | 144 | /** 145 | * Normalizes this vector in place. 146 | */ 147 | public final void normalize() 148 | { 149 | double norm; 150 | 151 | norm = 1.0/Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); 152 | this.x *= norm; 153 | this.y *= norm; 154 | this.z *= norm; 155 | } 156 | 157 | 158 | /** 159 | * Returns the dot product of this vector and vector v1. 160 | * @param v1 the other vector 161 | * @return the dot product of this and v1 162 | */ 163 | public final double dot(Vector3d v1) 164 | { 165 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z); 166 | } 167 | 168 | 169 | /** 170 | * Returns the squared length of this vector. 171 | * @return the squared length of this vector 172 | */ 173 | public final double lengthSquared() 174 | { 175 | return (this.x*this.x + this.y*this.y + this.z*this.z); 176 | } 177 | 178 | 179 | /** 180 | * Returns the length of this vector. 181 | * @return the length of this vector 182 | */ 183 | public final double length() 184 | { 185 | return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); 186 | } 187 | 188 | 189 | /** 190 | * Returns the angle in radians between this vector and the vector 191 | * parameter; the return value is constrained to the range [0,PI]. 192 | * @param v1 the other vector 193 | * @return the angle in radians in the range [0,PI] 194 | */ 195 | public final double angle(Vector3d v1) 196 | { 197 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 198 | if( vDot < -1.0) vDot = -1.0; 199 | if( vDot > 1.0) vDot = 1.0; 200 | return((double) (Math.acos( vDot ))); 201 | } 202 | 203 | 204 | } 205 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector3f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3-element vector that is represented by single-precision floating point 32 | * x,y,z coordinates. If this value represents a normal, then it should 33 | * be normalized. 34 | * 35 | */ 36 | public class Vector3f extends Tuple3f implements java.io.Serializable { 37 | 38 | // Combatible with 1.1 39 | static final long serialVersionUID = -7031930069184524614L; 40 | 41 | /** 42 | * Constructs and initializes a Vector3f from the specified xyz coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | */ 47 | public Vector3f(float x, float y, float z) 48 | { 49 | super(x,y,z); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Vector3f from the array of length 3. 55 | * @param v the array of length 3 containing xyz in order 56 | */ 57 | public Vector3f(float[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Vector3f from the specified Vector3f. 65 | * @param v1 the Vector3f containing the initialization x y z data 66 | */ 67 | public Vector3f(Vector3f v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Vector3f from the specified Vector3d. 75 | * @param v1 the Vector3d containing the initialization x y z data 76 | */ 77 | public Vector3f(Vector3d v1) 78 | { 79 | super(v1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Vector3f from the specified Tuple3f. 85 | * @param t1 the Tuple3f containing the initialization x y z data 86 | */ 87 | public Vector3f(Tuple3f t1) { 88 | super(t1); 89 | } 90 | 91 | 92 | /** 93 | * Constructs and initializes a Vector3f from the specified Tuple3d. 94 | * @param t1 the Tuple3d containing the initialization x y z data 95 | */ 96 | public Vector3f(Tuple3d t1) { 97 | super(t1); 98 | } 99 | 100 | 101 | /** 102 | * Constructs and initializes a Vector3f to (0,0,0). 103 | */ 104 | public Vector3f() 105 | { 106 | super(); 107 | } 108 | 109 | 110 | /** 111 | * Returns the squared length of this vector. 112 | * @return the squared length of this vector 113 | */ 114 | public final float lengthSquared() 115 | { 116 | return (this.x*this.x + this.y*this.y + this.z*this.z); 117 | } 118 | 119 | /** 120 | * Returns the length of this vector. 121 | * @return the length of this vector 122 | */ 123 | public final float length() 124 | { 125 | return (float) 126 | Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z); 127 | } 128 | 129 | 130 | /** 131 | * Sets this vector to be the vector cross product of vectors v1 and v2. 132 | * @param v1 the first vector 133 | * @param v2 the second vector 134 | */ 135 | public final void cross(Vector3f v1, Vector3f v2) 136 | { 137 | float x,y; 138 | 139 | x = v1.y*v2.z - v1.z*v2.y; 140 | y = v2.x*v1.z - v2.z*v1.x; 141 | this.z = v1.x*v2.y - v1.y*v2.x; 142 | this.x = x; 143 | this.y = y; 144 | } 145 | 146 | /** 147 | * Computes the dot product of this vector and vector v1. 148 | * @param v1 the other vector 149 | * @return the dot product of this vector and v1 150 | */ 151 | public final float dot(Vector3f v1) 152 | { 153 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z); 154 | } 155 | 156 | /** 157 | * Sets the value of this vector to the normalization of vector v1. 158 | * @param v1 the un-normalized vector 159 | */ 160 | public final void normalize(Vector3f v1) 161 | { 162 | float norm; 163 | 164 | norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z)); 165 | this.x = v1.x*norm; 166 | this.y = v1.y*norm; 167 | this.z = v1.z*norm; 168 | } 169 | 170 | /** 171 | * Normalizes this vector in place. 172 | */ 173 | public final void normalize() 174 | { 175 | float norm; 176 | 177 | norm = (float) 178 | (1.0/Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z)); 179 | this.x *= norm; 180 | this.y *= norm; 181 | this.z *= norm; 182 | } 183 | 184 | 185 | /** 186 | * Returns the angle in radians between this vector and the vector 187 | * parameter; the return value is constrained to the range [0,PI]. 188 | * @param v1 the other vector 189 | * @return the angle in radians in the range [0,PI] 190 | */ 191 | public final float angle(Vector3f v1) 192 | { 193 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 194 | if( vDot < -1.0) vDot = -1.0; 195 | if( vDot > 1.0) vDot = 1.0; 196 | return((float) (Math.acos( vDot ))); 197 | } 198 | 199 | } 200 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4-element vector represented by single-precision floating point x,y,z,w 32 | * coordinates. 33 | * 34 | */ 35 | public class Vector4f extends Tuple4f implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 8749319902347760659L; 39 | 40 | /** 41 | * Constructs and initializes a Vector4f from the specified xyzw coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | * @param z the z coordinate 45 | * @param w the w coordinate 46 | */ 47 | public Vector4f(float x, float y, float z, float w) 48 | { 49 | super(x,y,z,w); 50 | } 51 | 52 | 53 | /** 54 | * Constructs and initializes a Vector4f from the array of length 4. 55 | * @param v the array of length 4 containing xyzw in order 56 | */ 57 | public Vector4f(float[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Vector4f from the specified Vector4f. 65 | * @param v1 the Vector4f containing the initialization x y z w data 66 | */ 67 | public Vector4f(Vector4f v1) 68 | { 69 | super(v1); 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Vector4f from the specified Vector4d. 75 | * @param v1 the Vector4d containing the initialization x y z w data 76 | */ 77 | public Vector4f(Vector4d v1) 78 | { 79 | super(v1); 80 | } 81 | 82 | 83 | /** 84 | * Constructs and initializes a Vector4f from the specified Tuple4f. 85 | * @param t1 the Tuple4f containing the initialization x y z w data 86 | */ 87 | public Vector4f(Tuple4f t1) 88 | { 89 | super(t1); 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Vector4f from the specified Tuple4d. 95 | * @param t1 the Tuple4d containing the initialization x y z w data 96 | */ 97 | public Vector4f(Tuple4d t1) 98 | { 99 | super(t1); 100 | } 101 | 102 | 103 | /** 104 | * Constructs and initializes a Vector4f from the specified Tuple3f. 105 | * The x,y,z components of this vector are set to the corresponding 106 | * components of tuple t1. The w component of this vector 107 | * is set to 0. 108 | * @param t1 the tuple to be copied 109 | * 110 | * @since vecmath 1.2 111 | */ 112 | public Vector4f(Tuple3f t1) { 113 | super(t1.x, t1.y, t1.z, 0.0f); 114 | } 115 | 116 | 117 | /** 118 | * Constructs and initializes a Vector4f to (0,0,0,0). 119 | */ 120 | public Vector4f() 121 | { 122 | super(); 123 | } 124 | 125 | 126 | /** 127 | * Sets the x,y,z components of this vector to the corresponding 128 | * components of tuple t1. The w component of this vector 129 | * is set to 0. 130 | * @param t1 the tuple to be copied 131 | * 132 | * @since vecmath 1.2 133 | */ 134 | public final void set(Tuple3f t1) { 135 | this.x = t1.x; 136 | this.y = t1.y; 137 | this.z = t1.z; 138 | this.w = 0.0f; 139 | } 140 | 141 | 142 | /** 143 | * Returns the length of this vector. 144 | * @return the length of this vector as a float 145 | */ 146 | public final float length() 147 | { 148 | return 149 | (float) Math.sqrt(this.x*this.x + this.y*this.y + 150 | this.z*this.z + this.w*this.w); 151 | } 152 | 153 | /** 154 | * Returns the squared length of this vector 155 | * @return the squared length of this vector as a float 156 | */ 157 | public final float lengthSquared() 158 | { 159 | return (this.x*this.x + this.y*this.y + 160 | this.z*this.z + this.w*this.w); 161 | } 162 | 163 | /** 164 | * returns the dot product of this vector and v1 165 | * @param v1 the other vector 166 | * @return the dot product of this vector and v1 167 | */ 168 | public final float dot(Vector4f v1) 169 | { 170 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z + this.w*v1.w); 171 | } 172 | 173 | 174 | /** 175 | * Sets the value of this vector to the normalization of vector v1. 176 | * @param v1 the un-normalized vector 177 | */ 178 | public final void normalize(Vector4f v1) 179 | { 180 | float norm; 181 | 182 | norm = (float) (1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + 183 | v1.z*v1.z + v1.w*v1.w)); 184 | this.x = v1.x*norm; 185 | this.y = v1.y*norm; 186 | this.z = v1.z*norm; 187 | this.w = v1.w*norm; 188 | } 189 | 190 | 191 | /** 192 | * Normalizes this vector in place. 193 | */ 194 | public final void normalize() 195 | { 196 | float norm; 197 | 198 | norm = (float) (1.0/Math.sqrt(this.x*this.x + this.y*this.y + 199 | this.z*this.z + this.w*this.w)); 200 | this.x *= norm; 201 | this.y *= norm; 202 | this.z *= norm; 203 | this.w *= norm; 204 | } 205 | 206 | 207 | /** 208 | * Returns the (4-space) angle in radians between this vector and 209 | * the vector parameter; the return value is constrained to the 210 | * range [0,PI]. 211 | * @param v1 the other vector 212 | * @return the angle in radians in the range [0,PI] 213 | */ 214 | public final float angle(Vector4f v1) 215 | { 216 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 217 | if( vDot < -1.0) vDot = -1.0; 218 | if( vDot > 1.0) vDot = 1.0; 219 | return((float) (Math.acos( vDot ))); 220 | } 221 | 222 | } 223 | -------------------------------------------------------------------------------- /src/javax/vecmath/Vector4d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4-element vector represented by double-precision floating point 32 | * x,y,z,w coordinates. 33 | * 34 | */ 35 | public class Vector4d extends Tuple4d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 3938123424117448700L; 39 | 40 | /** 41 | * Constructs and initializes a Vector4d from the specified xyzw coordinates. 42 | * @param x the x coordinate 43 | * @param y the y coordinate 44 | * @param z the z coordinate 45 | * @param w the w coordinate 46 | */ 47 | public Vector4d(double x, double y, double z, double w) 48 | { 49 | super(x,y,z,w); 50 | } 51 | 52 | /** 53 | * Constructs and initializes a Vector4d from the coordinates contained 54 | * in the array. 55 | * @param v the array of length 4 containing xyzw in order 56 | */ 57 | public Vector4d(double[] v) 58 | { 59 | super(v); 60 | } 61 | 62 | /** 63 | * Constructs and initializes a Vector4d from the specified Vector4d. 64 | * @param v1 the Vector4d containing the initialization x y z w data 65 | */ 66 | public Vector4d(Vector4d v1) 67 | { 68 | super(v1); 69 | } 70 | 71 | /** 72 | * Constructs and initializes a Vector4d from the specified Vector4f. 73 | * @param v1 the Vector4f containing the initialization x y z w data 74 | */ 75 | public Vector4d(Vector4f v1) 76 | { 77 | super(v1); 78 | } 79 | 80 | /** 81 | * Constructs and initializes a Vector4d from the specified Tuple4f. 82 | * @param t1 the Tuple4f containing the initialization x y z w data 83 | */ 84 | public Vector4d(Tuple4f t1) 85 | { 86 | super(t1); 87 | } 88 | 89 | /** 90 | * Constructs and initializes a Vector4d from the specified Tuple4d. 91 | * @param t1 the Tuple4d containing the initialization x y z w data 92 | */ 93 | public Vector4d(Tuple4d t1) 94 | { 95 | super(t1); 96 | } 97 | 98 | 99 | /** 100 | * Constructs and initializes a Vector4d from the specified Tuple3d. 101 | * The x,y,z components of this vector are set to the corresponding 102 | * components of tuple t1. The w component of this vector 103 | * is set to 0. 104 | * @param t1 the tuple to be copied 105 | * 106 | * @since vecmath 1.2 107 | */ 108 | public Vector4d(Tuple3d t1) { 109 | super(t1.x, t1.y, t1.z, 0.0); 110 | } 111 | 112 | 113 | /** 114 | * Constructs and initializes a Vector4d to (0,0,0,0). 115 | */ 116 | public Vector4d() 117 | { 118 | super(); 119 | } 120 | 121 | 122 | /** 123 | * Sets the x,y,z components of this vector to the corresponding 124 | * components of tuple t1. The w component of this vector 125 | * is set to 0. 126 | * @param t1 the tuple to be copied 127 | * 128 | * @since vecmath 1.2 129 | */ 130 | public final void set(Tuple3d t1) { 131 | this.x = t1.x; 132 | this.y = t1.y; 133 | this.z = t1.z; 134 | this.w = 0.0; 135 | } 136 | 137 | 138 | /** 139 | * Returns the length of this vector. 140 | * @return the length of this vector 141 | */ 142 | public final double length() 143 | { 144 | return Math.sqrt(this.x*this.x + this.y*this.y + 145 | this.z*this.z + this.w*this.w); 146 | } 147 | 148 | 149 | /** 150 | * Returns the squared length of this vector. 151 | * @return the squared length of this vector 152 | */ 153 | public final double lengthSquared() 154 | { 155 | return (this.x*this.x + this.y*this.y + 156 | this.z*this.z + this.w*this.w); 157 | } 158 | 159 | 160 | /** 161 | * Returns the dot product of this vector and vector v1. 162 | * @param v1 the other vector 163 | * @return the dot product of this vector and vector v1 164 | */ 165 | public final double dot(Vector4d v1) 166 | { 167 | return (this.x*v1.x + this.y*v1.y + this.z*v1.z + this.w*v1.w); 168 | } 169 | 170 | 171 | /** 172 | * Sets the value of this vector to the normalization of vector v1. 173 | * @param v1 the un-normalized vector 174 | */ 175 | public final void normalize(Vector4d v1) 176 | { 177 | double norm; 178 | 179 | norm = 1.0/Math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z + v1.w*v1.w); 180 | this.x = v1.x*norm; 181 | this.y = v1.y*norm; 182 | this.z = v1.z*norm; 183 | this.w = v1.w*norm; 184 | } 185 | 186 | 187 | /** 188 | * Normalizes this vector in place. 189 | */ 190 | public final void normalize() 191 | { 192 | double norm; 193 | 194 | norm = 1.0/Math.sqrt(this.x*this.x + this.y*this.y + 195 | this.z*this.z + this.w*this.w); 196 | this.x *= norm; 197 | this.y *= norm; 198 | this.z *= norm; 199 | this.w *= norm; 200 | } 201 | 202 | 203 | /** 204 | * Returns the (4-space) angle in radians between this vector and 205 | * the vector parameter; the return value is constrained to the 206 | * range [0,PI]. 207 | * @param v1 the other vector 208 | * @return the angle in radians in the range [0,PI] 209 | */ 210 | public final double angle(Vector4d v1) 211 | { 212 | double vDot = this.dot(v1) / ( this.length()*v1.length() ); 213 | if( vDot < -1.0) vDot = -1.0; 214 | if( vDot > 1.0) vDot = 1.0; 215 | return((double) (Math.acos( vDot ))); 216 | } 217 | 218 | } 219 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point4f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4 element point represented by single precision floating point x,y,z,w 32 | * coordinates. 33 | * 34 | */ 35 | public class Point4f extends Tuple4f implements java.io.Serializable { 36 | 37 | 38 | // Compatible with 1.1 39 | static final long serialVersionUID = 4643134103185764459L; 40 | 41 | /** 42 | * Constructs and initializes a Point4f from the specified xyzw coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | * @param w the w coordinate 47 | */ 48 | public Point4f(float x, float y, float z, float w) 49 | { 50 | super(x,y,z,w); 51 | } 52 | 53 | 54 | /** 55 | * Constructs and initializes a Point4f from the array of length 4. 56 | * @param p the array of length 4 containing xyzw in order 57 | */ 58 | public Point4f(float[] p) 59 | { 60 | super(p); 61 | } 62 | 63 | 64 | /** 65 | * Constructs and initializes a Point4f from the specified Point4f. 66 | * @param p1 the Point4f containing the initialization x y z w data 67 | */ 68 | public Point4f(Point4f p1) 69 | { 70 | super(p1); 71 | } 72 | 73 | 74 | /** 75 | * Constructs and initializes a Point4f from the specified Point4d. 76 | * @param p1 the Point4d containing the initialization x y z w data 77 | */ 78 | public Point4f(Point4d p1) 79 | { 80 | super(p1); 81 | } 82 | 83 | 84 | /** 85 | * Constructs and initializes a Point4f from the specified Tuple4f. 86 | * @param t1 the Tuple4f containing the initialization x y z w data 87 | */ 88 | public Point4f(Tuple4f t1) 89 | { 90 | super(t1); 91 | } 92 | 93 | 94 | /** 95 | * Constructs and initializes a Point4f from the specified Tuple4d. 96 | * @param t1 the Tuple4d containing the initialization x y z w data 97 | */ 98 | public Point4f(Tuple4d t1) 99 | { 100 | super(t1); 101 | } 102 | 103 | 104 | /** 105 | * Constructs and initializes a Point4f from the specified Tuple3f. 106 | * The x,y,z components of this point are set to the corresponding 107 | * components of tuple t1. The w component of this point 108 | * is set to 1. 109 | * @param t1 the tuple to be copied 110 | * 111 | * @since vecmath 1.2 112 | */ 113 | public Point4f(Tuple3f t1) { 114 | super(t1.x, t1.y, t1.z, 1.0f); 115 | } 116 | 117 | 118 | /** 119 | * Constructs and initializes a Point4f to (0,0,0,0). 120 | */ 121 | public Point4f() 122 | { 123 | super(); 124 | } 125 | 126 | 127 | /** 128 | * Sets the x,y,z components of this point to the corresponding 129 | * components of tuple t1. The w component of this point 130 | * is set to 1. 131 | * @param t1 the tuple to be copied 132 | * 133 | * @since vecmath 1.2 134 | */ 135 | public final void set(Tuple3f t1) { 136 | this.x = t1.x; 137 | this.y = t1.y; 138 | this.z = t1.z; 139 | this.w = 1.0f; 140 | } 141 | 142 | 143 | /** 144 | * Computes the square of the distance between this point and point p1. 145 | * @param p1 the other point 146 | * @return the square of distance between these two points as a float 147 | */ 148 | public final float distanceSquared(Point4f p1) 149 | { 150 | float dx, dy, dz, dw; 151 | 152 | dx = this.x-p1.x; 153 | dy = this.y-p1.y; 154 | dz = this.z-p1.z; 155 | dw = this.w-p1.w; 156 | return (dx*dx+dy*dy+dz*dz+dw*dw); 157 | } 158 | 159 | 160 | /** 161 | * Computes the distance between this point and point p1. 162 | * @param p1 the other point 163 | * @return the distance between the two points 164 | */ 165 | public final float distance(Point4f p1) 166 | { 167 | float dx, dy, dz, dw; 168 | 169 | dx = this.x-p1.x; 170 | dy = this.y-p1.y; 171 | dz = this.z-p1.z; 172 | dw = this.w-p1.w; 173 | return (float) Math.sqrt(dx*dx+dy*dy+dz*dz+dw*dw); 174 | } 175 | 176 | 177 | /** 178 | * Computes the L-1 (Manhattan) distance between this point and 179 | * point p1. The L-1 distance is equal to: 180 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2) + abs(w1-w2). 181 | * @param p1 the other point 182 | * @return the L-1 distance 183 | */ 184 | public final float distanceL1(Point4f p1) 185 | { 186 | return( Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w)); 187 | } 188 | 189 | 190 | /** 191 | * Computes the L-infinite distance between this point and 192 | * point p1. The L-infinite distance is equal to 193 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)]. 194 | * @param p1 the other point 195 | * @return the L-infinite distance 196 | */ 197 | public final float distanceLinf(Point4f p1) 198 | { 199 | float t1, t2; 200 | t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 201 | t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w)); 202 | 203 | return(Math.max(t1,t2)); 204 | 205 | } 206 | 207 | /** 208 | * Multiplies each of the x,y,z components of the Point4f parameter 209 | * by 1/w, places the projected values into this point, and places 210 | * a 1 as the w parameter of this point. 211 | * @param p1 the source Point4f, which is not modified 212 | */ 213 | public final void project(Point4f p1) 214 | { 215 | float oneOw; 216 | 217 | oneOw = 1/p1.w; 218 | x = p1.x*oneOw; 219 | y = p1.y*oneOw; 220 | z = p1.z*oneOw; 221 | w = 1.0f; 222 | 223 | } 224 | 225 | } 226 | -------------------------------------------------------------------------------- /src/javax/vecmath/Point4d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 4 element vector represented by double precision floating point 32 | * x,y,z,w coordinates. 33 | * 34 | */ 35 | public class Point4d extends Tuple4d implements java.io.Serializable { 36 | 37 | // Compatible with 1.1 38 | static final long serialVersionUID = 1733471895962736949L; 39 | 40 | 41 | /** 42 | * Constructs and initializes a Point4d from the specified xyzw coordinates. 43 | * @param x the x coordinate 44 | * @param y the y coordinate 45 | * @param z the z coordinate 46 | * @param w the w coordinate 47 | */ 48 | public Point4d(double x, double y, double z, double w) 49 | { 50 | super(x,y,z,w); 51 | } 52 | 53 | /** 54 | * Constructs and initializes a Point4d from the coordinates contained 55 | * in the array. 56 | * @param p the array of length 4 containing xyzw in order 57 | */ 58 | public Point4d(double[] p) 59 | { 60 | super(p); 61 | } 62 | 63 | 64 | /** 65 | * Constructs and initializes a Point4d from the specified Point4d. 66 | * @param p1 the Point4d containing the initialization x y z w data 67 | */ 68 | public Point4d(Point4d p1) 69 | { 70 | super(p1); 71 | } 72 | 73 | 74 | /** 75 | * Constructs and initializes a Point4d from the specified Point4f. 76 | * @param p1 the Point4f containing the initialization x y z w data 77 | */ 78 | public Point4d(Point4f p1) 79 | { 80 | super(p1); 81 | } 82 | 83 | 84 | /** 85 | * Constructs and initializes a Point4d from the specified Tuple4f. 86 | * @param t1 the Tuple4f containing the initialization x y z w data 87 | */ 88 | public Point4d(Tuple4f t1) 89 | { 90 | super(t1); 91 | } 92 | 93 | 94 | /** 95 | * Constructs and initializes a Point4d from the specified Tuple4d. 96 | * @param t1 the Tuple4d containing the initialization x y z w data 97 | */ 98 | public Point4d(Tuple4d t1) 99 | { 100 | super(t1); 101 | } 102 | 103 | 104 | /** 105 | * Constructs and initializes a Point4d from the specified Tuple3d. 106 | * The x,y,z components of this point are set to the corresponding 107 | * components of tuple t1. The w component of this point 108 | * is set to 1. 109 | * @param t1 the tuple to be copied 110 | * 111 | * @since vecmath 1.2 112 | */ 113 | public Point4d(Tuple3d t1) { 114 | super(t1.x, t1.y, t1.z, 1.0); 115 | } 116 | 117 | 118 | /** 119 | * Constructs and initializes a Point4d to (0,0,0,0). 120 | */ 121 | public Point4d() 122 | { 123 | super(); 124 | } 125 | 126 | 127 | /** 128 | * Sets the x,y,z components of this point to the corresponding 129 | * components of tuple t1. The w component of this point 130 | * is set to 1. 131 | * @param t1 the tuple to be copied 132 | * 133 | * @since vecmath 1.2 134 | */ 135 | public final void set(Tuple3d t1) { 136 | this.x = t1.x; 137 | this.y = t1.y; 138 | this.z = t1.z; 139 | this.w = 1.0; 140 | } 141 | 142 | 143 | /** 144 | * Returns the square of the distance between this point and point p1. 145 | * @param p1 the first point 146 | * @return the square of distance between this point and point p1 147 | */ 148 | public final double distanceSquared(Point4d p1) 149 | { 150 | double dx, dy, dz, dw; 151 | 152 | dx = this.x-p1.x; 153 | dy = this.y-p1.y; 154 | dz = this.z-p1.z; 155 | dw = this.w-p1.w; 156 | return (dx*dx+dy*dy+dz*dz+dw*dw); 157 | } 158 | 159 | 160 | /** 161 | * Returns the distance between this point and point p1. 162 | * @param p1 the first point 163 | * @return the distance between these this point and point p1. 164 | */ 165 | public final double distance(Point4d p1) 166 | { 167 | double dx, dy, dz, dw; 168 | 169 | dx = this.x-p1.x; 170 | dy = this.y-p1.y; 171 | dz = this.z-p1.z; 172 | dw = this.w-p1.w; 173 | return Math.sqrt(dx*dx+dy*dy+dz*dz+dw*dw); 174 | } 175 | 176 | 177 | /** 178 | * Computes the L-1 (Manhattan) distance between this point and 179 | * point p1. The L-1 distance is equal to: 180 | * abs(x1-x2) + abs(y1-y2) + abs(z1-z2) + abs(w1-w2). 181 | * @param p1 the other point 182 | * @return the L-1 distance 183 | */ 184 | public final double distanceL1(Point4d p1) { 185 | return Math.abs(this.x-p1.x) + Math.abs(this.y-p1.y) + 186 | Math.abs(this.z-p1.z) + Math.abs(this.w-p1.w); 187 | } 188 | 189 | /** 190 | * Computes the L-infinite distance between this point and 191 | * point p1. The L-infinite distance is equal to 192 | * MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2), abs(w1-w2)]. 193 | * @param p1 the other point 194 | * @return the L-infinite distance 195 | */ 196 | public final double distanceLinf(Point4d p1) { 197 | double t1, t2; 198 | t1 = Math.max( Math.abs(this.x-p1.x), Math.abs(this.y-p1.y)); 199 | t2 = Math.max( Math.abs(this.z-p1.z), Math.abs(this.w-p1.w)); 200 | 201 | return Math.max(t1,t2); 202 | } 203 | 204 | /** 205 | * Multiplies each of the x,y,z components of the Point4d parameter 206 | * by 1/w, places the projected values into this point, and places 207 | * a 1 as the w parameter of this point. 208 | * @param p1 the source Point4d, which is not modified 209 | */ 210 | public final void project(Point4d p1) 211 | { 212 | double oneOw; 213 | 214 | oneOw = 1/p1.w; 215 | x = p1.x*oneOw; 216 | y = p1.y*oneOw; 217 | z = p1.z*oneOw; 218 | w = 1.0; 219 | 220 | } 221 | 222 | 223 | } 224 | -------------------------------------------------------------------------------- /src/javax/vecmath/Tuple3b.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A three byte tuple. Note that Java defines a byte as a signed integer 32 | * in the range [-128, 127]. However, colors are more typically 33 | * represented by values in the range [0, 255]. Java 3D recognizes this 34 | * and, in those cases where Tuple3b is used to represent color, treats 35 | * the bytes as if the range were [0, 255]---in other words, as if the 36 | * bytes were unsigned. 37 | * Values greater than 127 can be assigned to a byte variable using a 38 | * type cast. For example: 39 | *

  • byteVariable = (byte) intValue; // intValue can be > 127
40 | * If intValue is greater than 127, then byteVariable will be negative. The 41 | * correct value will be extracted when it is used (by masking off the upper 42 | * bits). 43 | */ 44 | public abstract class Tuple3b implements java.io.Serializable, Cloneable { 45 | 46 | static final long serialVersionUID = -483782685323607044L; 47 | 48 | /** 49 | * The first value. 50 | */ 51 | public byte x; 52 | 53 | /** 54 | * The second value. 55 | */ 56 | public byte y; 57 | 58 | /** 59 | * The third value. 60 | */ 61 | public byte z; 62 | 63 | 64 | /** 65 | * Constructs and initializes a Tuple3b from the specified three values. 66 | * @param b1 the first value 67 | * @param b2 the second value 68 | * @param b3 the third value 69 | */ 70 | public Tuple3b(byte b1, byte b2, byte b3) 71 | { 72 | this.x = b1; 73 | this.y = b2; 74 | this.z = b3; 75 | } 76 | 77 | 78 | /** 79 | * Constructs and initializes a Tuple3b from input array of length 3. 80 | * @param t the array of length 3 containing b1 b2 b3 in order 81 | */ 82 | public Tuple3b(byte[] t) 83 | { 84 | this.x = t[0]; 85 | this.y = t[1]; 86 | this.z = t[2]; 87 | } 88 | 89 | 90 | /** 91 | * Constructs and initializes a Tuple3b from the specified Tuple3b. 92 | * @param t1 the Tuple3b containing the initialization x y z data 93 | */ 94 | public Tuple3b(Tuple3b t1) 95 | { 96 | this.x = t1.x; 97 | this.y = t1.y; 98 | this.z = t1.z; 99 | } 100 | 101 | 102 | /** 103 | * Constructs and initializes a Tuple3b to (0,0,0). 104 | */ 105 | public Tuple3b() 106 | { 107 | this.x = (byte) 0; 108 | this.y = (byte) 0; 109 | this.z = (byte) 0; 110 | } 111 | 112 | 113 | /** 114 | * Returns a string that contains the values of this Tuple3b. 115 | * @return a String with the values 116 | */ 117 | @Override 118 | public String toString() 119 | { 120 | return("(" + ((int)this.x & 0xff) + 121 | ", " + ((int)this.y & 0xff) + 122 | ", " + ((int)this.z & 0xff) + ")"); 123 | } 124 | 125 | 126 | /** 127 | * Places the value of the x,y,z components of this Tuple3b 128 | * into the array of length 3. 129 | * @param t array of length 3 into which the component values are copied 130 | */ 131 | public final void get(byte[] t) 132 | { 133 | 134 | t[0] = this.x; 135 | t[1] = this.y; 136 | t[2] = this.z; 137 | } 138 | 139 | 140 | /** 141 | * Places the value of the x,y,z components of this tuple into 142 | * the tuple t1. 143 | * @param t1 the tuple into which the values are placed 144 | */ 145 | public final void get(Tuple3b t1) 146 | { 147 | t1.x = this.x; 148 | t1.y = this.y; 149 | t1.z = this.z; 150 | } 151 | 152 | 153 | /** 154 | * Sets the value of the data members of this tuple to the value 155 | * of the argument tuple t1. 156 | * @param t1 the source tuple for the memberwise copy 157 | */ 158 | public final void set(Tuple3b t1) 159 | { 160 | this.x = t1.x; 161 | this.y = t1.y; 162 | this.z = t1.z; 163 | } 164 | 165 | 166 | /** 167 | * Sets the value of the x,y,z, data members of this tuple to the 168 | * values in the array t of length 3. 169 | * @param t array of length 3 which is the source for the memberwise copy 170 | */ 171 | public final void set(byte[] t) 172 | { 173 | this.x = t[0]; 174 | this.y = t[1]; 175 | this.z = t[2]; 176 | } 177 | 178 | 179 | /** 180 | * Returns true if all of the data members of tuple t1 are equal to 181 | * the corresponding data members in this tuple. 182 | * @param t1 the tuple with which the comparison is made 183 | * @return true or false 184 | */ 185 | public boolean equals(Tuple3b t1) 186 | { 187 | try { 188 | return(this.x == t1.x && this.y == t1.y && this.z == t1.z); 189 | } 190 | catch (NullPointerException e2) {return false;} 191 | 192 | } 193 | 194 | /** 195 | * Returns true if the Object t1 is of type Tuple3b and all of the 196 | * data members of t1 are equal to the corresponding data members in 197 | * this Tuple3b. 198 | * @param t1 the object with which the comparison is made 199 | */ 200 | @Override 201 | public boolean equals(Object t1) 202 | { 203 | try { 204 | Tuple3b t2 = (Tuple3b) t1; 205 | return(this.x == t2.x && this.y == t2.y && this.z == t2.z); 206 | } 207 | catch (NullPointerException e2) {return false;} 208 | catch (ClassCastException e1) {return false;} 209 | 210 | } 211 | 212 | /** 213 | * Returns a hash code value based on the data values in this 214 | * object. Two different Tuple3b objects with identical data values 215 | * (i.e., Tuple3b.equals returns true) will return the same hash 216 | * code value. Two objects with different data members may return the 217 | * same hash value, although this is not likely. 218 | * @return the integer hash code value 219 | */ 220 | @Override 221 | public int hashCode() { 222 | return ((((int)x & 0xff) << 0) | 223 | (((int)y & 0xff) << 8) | 224 | (((int)z & 0xff) << 16)); 225 | } 226 | 227 | /** 228 | * Creates a new object of the same class as this object. 229 | * 230 | * @return a clone of this instance. 231 | * @exception OutOfMemoryError if there is not enough memory. 232 | * @see java.lang.Cloneable 233 | * @since vecmath 1.3 234 | */ 235 | @Override 236 | public Object clone() { 237 | // Since there are no arrays we can just use Object.clone() 238 | try { 239 | return super.clone(); 240 | } catch (CloneNotSupportedException e) { 241 | // this shouldn't happen, since we are Cloneable 242 | throw new InternalError(); 243 | } 244 | } 245 | 246 | 247 | /** 248 | * Get x, the first value. 249 | * 250 | * @return the first value. 251 | * 252 | * @since vecmath 1.5 253 | */ 254 | public final byte getX() { 255 | return x; 256 | } 257 | 258 | 259 | /** 260 | * Set x, the first value. 261 | * 262 | * @param x the first value to set. 263 | * 264 | * @since vecmath 1.5 265 | */ 266 | public final void setX(byte x) { 267 | this.x = x; 268 | } 269 | 270 | 271 | /** 272 | * Get y, the second value. 273 | * 274 | * @return the second value. 275 | * 276 | * @since vecmath 1.5 277 | */ 278 | public final byte getY() { 279 | return y; 280 | } 281 | 282 | 283 | /** 284 | * Set y, the second value. 285 | * 286 | * @param y the second value to set. 287 | * 288 | * @since vecmath 1.5 289 | */ 290 | public final void setY(byte y) { 291 | this.y = y; 292 | } 293 | 294 | /** 295 | * Get z, the third value. 296 | * 297 | * @return the third value. 298 | * 299 | * @since vecmath 1.5 300 | */ 301 | public final byte getZ() { 302 | return z; 303 | } 304 | 305 | 306 | /** 307 | * Set z, the third value. 308 | * 309 | * @param z the third value to set. 310 | * 311 | * @since vecmath 1.5 312 | */ 313 | public final void setZ(byte z) { 314 | this.z = z; 315 | } 316 | 317 | } 318 | -------------------------------------------------------------------------------- /src/javax/vecmath/Tuple4b.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A four byte tuple. Note that Java defines a byte as a signed integer 32 | * in the range [-128, 127]. However, colors are more typically 33 | * represented by values in the range [0, 255]. Java 3D recognizes this 34 | * and, in those cases where Tuple4b is used to represent color, treats 35 | * the bytes as if the range were [0, 255]---in other words, as if the 36 | * bytes were unsigned. 37 | * Values greater than 127 can be assigned to a byte variable using a 38 | * type cast. For example: 39 | *
  • byteVariable = (byte) intValue; // intValue can be > 127
40 | * If intValue is greater than 127, then byteVariable will be negative. The 41 | * correct value will be extracted when it is used (by masking off the upper 42 | * bits). 43 | */ 44 | public abstract class Tuple4b implements java.io.Serializable, Cloneable { 45 | 46 | static final long serialVersionUID = -8226727741811898211L; 47 | 48 | /** 49 | * The first value. 50 | */ 51 | public byte x; 52 | 53 | /** 54 | * The second value. 55 | */ 56 | public byte y; 57 | 58 | /** 59 | * The third value. 60 | */ 61 | public byte z; 62 | 63 | /** 64 | * The fourth value. 65 | */ 66 | public byte w; 67 | 68 | 69 | /** 70 | * Constructs and initializes a Tuple4b from the specified four values. 71 | * @param b1 the first value 72 | * @param b2 the second value 73 | * @param b3 the third value 74 | * @param b4 the fourth value 75 | */ 76 | public Tuple4b(byte b1, byte b2, byte b3, byte b4) 77 | { 78 | this.x = b1; 79 | this.y = b2; 80 | this.z = b3; 81 | this.w = b4; 82 | } 83 | 84 | 85 | /** 86 | * Constructs and initializes a Tuple4b from the array of length 4. 87 | * @param t the array of length 4 containing b1 b2 b3 b4 in order 88 | */ 89 | public Tuple4b(byte[] t) 90 | { 91 | this.x = t[0]; 92 | this.y = t[1]; 93 | this.z = t[2]; 94 | this.w = t[3]; 95 | } 96 | 97 | 98 | /** 99 | * Constructs and initializes a Tuple4b from the specified Tuple4b. 100 | * @param t1 the Tuple4b containing the initialization x y z w data 101 | */ 102 | public Tuple4b(Tuple4b t1) 103 | { 104 | this.x = t1.x; 105 | this.y = t1.y; 106 | this.z = t1.z; 107 | this.w = t1.w; 108 | } 109 | 110 | 111 | /** 112 | * Constructs and initializes a Tuple4b to (0,0,0,0). 113 | */ 114 | public Tuple4b() 115 | { 116 | this.x = (byte) 0; 117 | this.y = (byte) 0; 118 | this.z = (byte) 0; 119 | this.w = (byte) 0; 120 | } 121 | 122 | 123 | /** 124 | * Returns a string that contains the values of this Tuple4b. 125 | * @return the String representation 126 | */ 127 | @Override 128 | public String toString() 129 | { 130 | return("(" + ((int)this.x & 0xff) + 131 | ", " + ((int)this.y & 0xff) + 132 | ", " + ((int)this.z & 0xff) + 133 | ", " + ((int)this.w & 0xff) + ")"); 134 | } 135 | 136 | 137 | /** 138 | * Places the value of the x,y,z,w components of this Tuple4b 139 | * into the array of length 4. 140 | * @param b array of length 4 into which the values are placed 141 | */ 142 | public final void get(byte[] b) 143 | { 144 | b[0] = this.x; 145 | b[1] = this.y; 146 | b[2] = this.z; 147 | b[3] = this.w; 148 | } 149 | 150 | 151 | /** 152 | * Places the value of the x,y,z,w components of this 153 | * Tuple4b into the tuple t1. 154 | * @param t1 tuple into which the values are placed 155 | */ 156 | public final void get(Tuple4b t1) 157 | { 158 | t1.x = this.x; 159 | t1.y = this.y; 160 | t1.z = this.z; 161 | t1.w = this.w; 162 | } 163 | 164 | 165 | /** 166 | * Sets the value of the data members of this tuple to the value 167 | * of the argument tuple t1. 168 | * @param t1 the source tuple 169 | */ 170 | public final void set(Tuple4b t1) 171 | { 172 | this.x = t1.x; 173 | this.y = t1.y; 174 | this.z = t1.z; 175 | this.w = t1.w; 176 | } 177 | 178 | 179 | /** 180 | * Sets the value of the data members of this tuple to the value 181 | * of the array b of length 4. 182 | * @param b the source array of length 4 183 | */ 184 | public final void set(byte[] b) 185 | { 186 | this.x = b[0]; 187 | this.y = b[1]; 188 | this.z = b[2]; 189 | this.w = b[3]; 190 | } 191 | 192 | 193 | /** 194 | * Returns true if all of the data members of tuple t1 are equal to 195 | * the corresponding data members in this tuple. 196 | * @param t1 the tuple with which the comparison is made 197 | */ 198 | public boolean equals(Tuple4b t1) 199 | { 200 | try { 201 | return(this.x == t1.x && this.y == t1.y && 202 | this.z == t1.z && this.w == t1.w); 203 | } 204 | catch (NullPointerException e2) {return false;} 205 | 206 | } 207 | 208 | /** 209 | * Returns true if the Object t1 is of type Tuple4b and all of the 210 | * data members of t1 are equal to the corresponding data members in 211 | * this Tuple4b. 212 | * @param t1 the object with which the comparison is made 213 | */ 214 | @Override 215 | public boolean equals(Object t1) 216 | { 217 | try { 218 | Tuple4b t2 = (Tuple4b) t1; 219 | return(this.x == t2.x && this.y == t2.y && 220 | this.z == t2.z && this.w == t2.w); 221 | } 222 | catch (NullPointerException e2) {return false;} 223 | catch (ClassCastException e1) {return false;} 224 | 225 | } 226 | 227 | 228 | /** 229 | * Returns a hash code value based on the data values in this 230 | * object. Two different Tuple4b objects with identical data values 231 | * (i.e., Tuple4b.equals returns true) will return the same hash 232 | * code value. Two objects with different data members may return the 233 | * same hash value, although this is not likely. 234 | * @return the integer hash code value 235 | */ 236 | @Override 237 | public int hashCode() { 238 | return ((((int)x & 0xff) << 0) | 239 | (((int)y & 0xff) << 8) | 240 | (((int)z & 0xff) << 16) | 241 | (((int)w & 0xff) << 24)); 242 | } 243 | 244 | /** 245 | * Creates a new object of the same class as this object. 246 | * 247 | * @return a clone of this instance. 248 | * @exception OutOfMemoryError if there is not enough memory. 249 | * @see java.lang.Cloneable 250 | * @since vecmath 1.3 251 | */ 252 | @Override 253 | public Object clone() { 254 | // Since there are no arrays we can just use Object.clone() 255 | try { 256 | return super.clone(); 257 | } catch (CloneNotSupportedException e) { 258 | // this shouldn't happen, since we are Cloneable 259 | throw new InternalError(); 260 | } 261 | } 262 | 263 | 264 | /** 265 | * Get x, the first value. 266 | * 267 | * @return Returns x, the first value. 268 | * 269 | * @since vecmath 1.5 270 | */ 271 | public final byte getX() { 272 | return x; 273 | } 274 | 275 | 276 | /** 277 | * Set x, the first value. 278 | * 279 | * @param x the first value. 280 | * 281 | * @since vecmath 1.5 282 | */ 283 | public final void setX(byte x) { 284 | this.x = x; 285 | } 286 | 287 | 288 | /** 289 | * Get y, the second value. 290 | * 291 | * @return Returns y, the second value. 292 | * 293 | * @since vecmath 1.5 294 | */ 295 | public final byte getY() { 296 | return y; 297 | } 298 | 299 | 300 | /** 301 | * Set y, the second value. 302 | * 303 | * @param y the second value. 304 | * 305 | * @since vecmath 1.5 306 | */ 307 | public final void setY(byte y) { 308 | this.y = y; 309 | } 310 | 311 | /** 312 | * Get z, the third value. 313 | * 314 | * @return Returns z, the third value. 315 | * 316 | * @since vecmath 1.5 317 | */ 318 | public final byte getZ() { 319 | return z; 320 | } 321 | 322 | 323 | /** 324 | * Set z, the third value. 325 | * 326 | * @param z the third value. 327 | * 328 | * @since vecmath 1.5 329 | */ 330 | public final void setZ(byte z) { 331 | this.z = z; 332 | } 333 | 334 | 335 | /** 336 | * Get w, the fourth value. 337 | * 338 | * @return Returns w - the fourth value. 339 | * 340 | * @since vecmath 1.5 341 | */ 342 | public final byte getW() { 343 | return w; 344 | } 345 | 346 | 347 | /** 348 | * Set w, the fourth value. 349 | * 350 | * @param w the fourth value. 351 | * 352 | * @since vecmath 1.5 353 | */ 354 | public final void setW(byte w) { 355 | this.w = w; 356 | } 357 | } 358 | -------------------------------------------------------------------------------- /docs/api-changes-1_5.txt: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------ 2 | $RCSfile$ 3 | $Revision$ 4 | $Date$ 5 | ------------------------------------------------------------------------ 6 | This document conatains proposed API changes to the vecmath 1.5 API 7 | that deviate from the 1.4 API. 8 | 9 | This file must be updated to record the addition or deprecation of any 10 | public or protected class, interface, field, constructor, or method to 11 | the vecmath API. 12 | 13 | The one exception to this rule is that you don't need to update this 14 | file when adding a non-final (i.e., virtual) method to a class if that 15 | method--with exactly the same signature--already exists in a 16 | superclass. For example, adding a "toString" method to a vecmath object 17 | doesn't require an entry in this file. 18 | 19 | No incompatible changes to the vecmath 1.4 API are allowed. 20 | 21 | 22 | I. New/deprecated fields, constructors, methods 23 | 24 | AxisAngle4f 25 | --------------- 26 | New methods: 27 | public final void setAngle(float angle) 28 | public final float getAngle() 29 | public final float getX() 30 | public final float getY() 31 | public final float getZ() 32 | public final void setX(float x) 33 | public final void setY(float y) 34 | public final void setZ(float z) 35 | 36 | AxisAngle4d 37 | -------------- 38 | New methods: 39 | public final void setAngle(double angle) 40 | public final float getAngle() 41 | public final double getX() 42 | public final double getY() 43 | public final double getZ() 44 | public final void setX(double x) 45 | public final void setY(double y) 46 | public final void setZ(double z) 47 | 48 | 49 | 50 | Matrix3d 51 | --------------- 52 | New methods: 53 | 54 | public final void setM00(double m00) 55 | public final void setM01(double m01) 56 | public final void setM02(double m02) 57 | public final void setM10(double m10) 58 | public final void setM11(double m11) 59 | public final void setM12(double m12) 60 | public final void setM20(double m20) 61 | public final void setM21(double m21) 62 | public final void setM22(double m22) 63 | public final double getM00() 64 | public final double getM01() 65 | public final double getM02() 66 | public final double getM10() 67 | public final double getM11() 68 | public final double getM12() 69 | public final double getM20() 70 | public final double getM21() 71 | public final double getM22() 72 | 73 | Matrix3f 74 | --------------- 75 | New methods: 76 | public final void setM00(float m00) 77 | public final void setM01(float m01) 78 | public final void setM02(float m02) 79 | public final void setM10(float m10) 80 | public final void setM11(float m11) 81 | public final void setM12(float m12) 82 | public final void setM20(float m20) 83 | public final void setM21(float m21) 84 | public final void setM22(float m22) 85 | public final float getM00() 86 | public final float getM01() 87 | public final float getM02() 88 | public final float getM10() 89 | public final float getM11() 90 | public final float getM12() 91 | public final float getM20() 92 | public final float getM21() 93 | public final float getM22() 94 | 95 | Matrix4d 96 | ------------- 97 | New methods: 98 | public final void setM00(double m00) 99 | public final void setM01(double m01) 100 | public final void setM02(double m02) 101 | public final void setM03(double m03) 102 | public final void setM10(double m10) 103 | public final void setM11(double m11) 104 | public final void setM12(double m12) 105 | public final void setM13(double m13) 106 | public final void setM20(double m20) 107 | public final void setM21(double m21) 108 | public final void setM22(double m22) 109 | public final void setM23(double m23) 110 | public final void setM30(double m30) 111 | public final void setM31(double m31) 112 | public final void setM32(double m32) 113 | public final void setM33(double m33) 114 | public final double getM00() 115 | public final double getM01() 116 | public final double getM02() 117 | public final double getM03() 118 | public final double getM10() 119 | public final double getM11() 120 | public final double getM12() 121 | public final double getM13() 122 | public final double getM20() 123 | public final double getM21() 124 | public final double getM22() 125 | public final double getM23() 126 | public final double getM30() 127 | public final double getM31() 128 | public final double getM32() 129 | public final double getM33() 130 | 131 | 132 | Matrix4f 133 | ------------- 134 | New methods: 135 | public final void setM00(float m00) 136 | public final void setM01(float m01) 137 | public final void setM02(float m02) 138 | public final void setM03(float m03) 139 | public final void setM10(float m10) 140 | public final void setM11(float m11) 141 | public final void setM12(float m12) 142 | public final void setM13(float m13) 143 | public final void setM20(float m20) 144 | public final void setM21(float m21) 145 | public final void setM22(float m22) 146 | public final void setM23(float m23) 147 | public final void setM30(float m30) 148 | public final void setM31(float m31) 149 | public final void setM32(float m32) 150 | public final void setM33(float m33) 151 | public final float getM00() 152 | public final float getM01() 153 | public final float getM02() 154 | public final float getM03() 155 | public final float getM10() 156 | public final float getM11() 157 | public final float getM12() 158 | public final float getM13() 159 | public final float getM20() 160 | public final float getM21() 161 | public final float getM22() 162 | public final float getM23() 163 | public final float getM30() 164 | public final float getM31() 165 | public final float getM32() 166 | public final float getM33() 167 | 168 | Tuple2d 169 | ------------ 170 | New methods: 171 | public final void setX(double x) 172 | public final void setY(double y) 173 | public final double getX() 174 | public final double getY() 175 | 176 | 177 | Tuple2f 178 | ------------ 179 | New methods: 180 | public final void setX(float x) 181 | public final void setY(float y) 182 | public final float getX() 183 | public final float getY() 184 | 185 | Tuple2i 186 | ------------ 187 | New methods: 188 | public final void setX(int x) 189 | public final void setY(int y) 190 | public final int getX() 191 | public final int getY() 192 | 193 | Tuple3d 194 | ------------ 195 | New methods: 196 | public final void setX(double x) 197 | public final void setY(double y) 198 | public final void setZ(double z) 199 | public final double getX() 200 | public final double getY() 201 | public final double getZ() 202 | 203 | Tuple3f 204 | ------------ 205 | New methods: 206 | public final void setX(float x) 207 | public final void setY(float y) 208 | public final void setZ(float z) 209 | public final float getX() 210 | public final float getY() 211 | public final float getZ() 212 | 213 | Tuple3i 214 | ------------ 215 | New methods: 216 | public final void setX(int x) 217 | public final void setY(int y) 218 | public final void setZ(int z) 219 | public final int getX() 220 | public final int getY() 221 | public final int getZ() 222 | 223 | Tuple3b 224 | ------------ 225 | New methods: 226 | public final void setX(byte x) 227 | public final void setY(byte y) 228 | public final void setZ(byte z) 229 | public final byte getX() 230 | public final byte getY() 231 | public final byte getZ() 232 | 233 | Tuple4d 234 | ------------ 235 | New methods: 236 | public final void setX(double x) 237 | public final void setY(double y) 238 | public final void setZ(double z) 239 | public final void setW(double w) 240 | public final double getX() 241 | public final double getY() 242 | public final double getZ() 243 | public final double getW() 244 | 245 | Tuple4f 246 | ------------ 247 | New methods: 248 | public final void setX(float x) 249 | public final void setY(float y) 250 | public final void setZ(float z) 251 | public final void setW(double w) 252 | public final float getX() 253 | public final float getY() 254 | public final float getZ() 255 | public final float getW() 256 | 257 | Tuple4i 258 | ------------ 259 | New methods: 260 | public final void setX(int x) 261 | public final void setY(int y) 262 | public final void setZ(int z) 263 | public final void setW(int w) 264 | public final int getX() 265 | public final int getY() 266 | public final int getZ() 267 | public final int getW() 268 | 269 | Tuple4b 270 | ------------ 271 | New methods: 272 | public final void setX(byte x) 273 | public final void setY(byte y) 274 | public final void setZ(byte z) 275 | public final void setW(byte w) 276 | public final byte getX() 277 | public final byte getY() 278 | public final byte getZ() 279 | public final byte getW() 280 | 281 | II. Reparented classes 282 | 283 | 284 | --------------- 285 | now extends (used to extend ) 286 | 287 | 288 | III. New classes and interfaces (in javax.vecmath) 289 | 290 | -------------------------------------------------------------------------------- /src/javax/vecmath/Tuple2i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2005-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 2-element tuple represented by signed integer x,y 32 | * coordinates. 33 | * 34 | * @since vecmath 1.4 35 | */ 36 | public abstract class Tuple2i implements java.io.Serializable, Cloneable { 37 | 38 | static final long serialVersionUID = -3555701650170169638L; 39 | 40 | /** 41 | * The x coordinate. 42 | */ 43 | public int x; 44 | 45 | /** 46 | * The y coordinate. 47 | */ 48 | public int y; 49 | 50 | 51 | /** 52 | * Constructs and initializes a Tuple2i from the specified 53 | * x and y coordinates. 54 | * @param x the x coordinate 55 | * @param y the y coordinate 56 | */ 57 | public Tuple2i(int x, int y) { 58 | this.x = x; 59 | this.y = y; 60 | } 61 | 62 | 63 | /** 64 | * Constructs and initializes a Tuple2i from the array of length 2. 65 | * @param t the array of length 2 containing x and y in order. 66 | */ 67 | public Tuple2i(int[] t) { 68 | this.x = t[0]; 69 | this.y = t[1]; 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Tuple2i from the specified Tuple2i. 75 | * @param t1 the Tuple2i containing the initialization x and y 76 | * data. 77 | */ 78 | public Tuple2i(Tuple2i t1) { 79 | this.x = t1.x; 80 | this.y = t1.y; 81 | } 82 | 83 | 84 | /** 85 | * Constructs and initializes a Tuple2i to (0,0). 86 | */ 87 | public Tuple2i() { 88 | this.x = 0; 89 | this.y = 0; 90 | } 91 | 92 | 93 | /** 94 | * Sets the value of this tuple to the specified x and y 95 | * coordinates. 96 | * @param x the x coordinate 97 | * @param y the y coordinate 98 | */ 99 | public final void set(int x, int y) { 100 | this.x = x; 101 | this.y = y; 102 | } 103 | 104 | 105 | /** 106 | * Sets the value of this tuple to the specified coordinates in the 107 | * array of length 2. 108 | * @param t the array of length 2 containing x and y in order. 109 | */ 110 | public final void set(int[] t) { 111 | this.x = t[0]; 112 | this.y = t[1]; 113 | } 114 | 115 | 116 | /** 117 | * Sets the value of this tuple to the value of tuple t1. 118 | * @param t1 the tuple to be copied 119 | */ 120 | public final void set(Tuple2i t1) { 121 | this.x = t1.x; 122 | this.y = t1.y; 123 | } 124 | 125 | 126 | /** 127 | * Copies the values of this tuple into the array t. 128 | * @param t is the array 129 | */ 130 | public final void get(int[] t) { 131 | t[0] = this.x; 132 | t[1] = this.y; 133 | } 134 | 135 | 136 | /** 137 | * Copies the values of this tuple into the tuple t. 138 | * @param t is the target tuple 139 | */ 140 | public final void get(Tuple2i t) { 141 | t.x = this.x; 142 | t.y = this.y; 143 | } 144 | 145 | 146 | /** 147 | * Sets the value of this tuple to the sum of tuples t1 and t2. 148 | * @param t1 the first tuple 149 | * @param t2 the second tuple 150 | */ 151 | public final void add(Tuple2i t1, Tuple2i t2) { 152 | this.x = t1.x + t2.x; 153 | this.y = t1.y + t2.y; 154 | } 155 | 156 | 157 | /** 158 | * Sets the value of this tuple to the sum of itself and t1. 159 | * @param t1 the other tuple 160 | */ 161 | public final void add(Tuple2i t1) { 162 | this.x += t1.x; 163 | this.y += t1.y; 164 | } 165 | 166 | 167 | /** 168 | * Sets the value of this tuple to the difference 169 | * of tuples t1 and t2 (this = t1 - t2). 170 | * @param t1 the first tuple 171 | * @param t2 the second tuple 172 | */ 173 | public final void sub(Tuple2i t1, Tuple2i t2) { 174 | this.x = t1.x - t2.x; 175 | this.y = t1.y - t2.y; 176 | } 177 | 178 | 179 | /** 180 | * Sets the value of this tuple to the difference 181 | * of itself and t1 (this = this - t1). 182 | * @param t1 the other tuple 183 | */ 184 | public final void sub(Tuple2i t1) { 185 | this.x -= t1.x; 186 | this.y -= t1.y; 187 | } 188 | 189 | 190 | /** 191 | * Sets the value of this tuple to the negation of tuple t1. 192 | * @param t1 the source tuple 193 | */ 194 | public final void negate(Tuple2i t1) { 195 | this.x = -t1.x; 196 | this.y = -t1.y; 197 | } 198 | 199 | 200 | /** 201 | * Negates the value of this tuple in place. 202 | */ 203 | public final void negate() { 204 | this.x = -this.x; 205 | this.y = -this.y; 206 | } 207 | 208 | 209 | /** 210 | * Sets the value of this tuple to the scalar multiplication 211 | * of tuple t1. 212 | * @param s the scalar value 213 | * @param t1 the source tuple 214 | */ 215 | public final void scale(int s, Tuple2i t1) { 216 | this.x = s*t1.x; 217 | this.y = s*t1.y; 218 | } 219 | 220 | 221 | /** 222 | * Sets the value of this tuple to the scalar multiplication 223 | * of the scale factor with this. 224 | * @param s the scalar value 225 | */ 226 | public final void scale(int s) { 227 | this.x *= s; 228 | this.y *= s; 229 | } 230 | 231 | 232 | /** 233 | * Sets the value of this tuple to the scalar multiplication 234 | * of tuple t1 plus tuple t2 (this = s*t1 + t2). 235 | * @param s the scalar value 236 | * @param t1 the tuple to be multipled 237 | * @param t2 the tuple to be added 238 | */ 239 | public final void scaleAdd(int s, Tuple2i t1, Tuple2i t2) { 240 | this.x = s*t1.x + t2.x; 241 | this.y = s*t1.y + t2.y; 242 | } 243 | 244 | 245 | /** 246 | * Sets the value of this tuple to the scalar multiplication 247 | * of itself and then adds tuple t1 (this = s*this + t1). 248 | * @param s the scalar value 249 | * @param t1 the tuple to be added 250 | */ 251 | public final void scaleAdd(int s, Tuple2i t1) { 252 | this.x = s*this.x + t1.x; 253 | this.y = s*this.y + t1.y; 254 | } 255 | 256 | 257 | /** 258 | * Returns a string that contains the values of this Tuple2i. 259 | * The form is (x,y). 260 | * @return the String representation 261 | */ 262 | @Override 263 | public String toString() { 264 | return "(" + this.x + ", " + this.y + ")"; 265 | } 266 | 267 | 268 | /** 269 | * Returns true if the Object t1 is of type Tuple2i and all of the 270 | * data members of t1 are equal to the corresponding data members in 271 | * this Tuple2i. 272 | * @param t1 the object with which the comparison is made 273 | */ 274 | @Override 275 | public boolean equals(Object t1) { 276 | try { 277 | Tuple2i t2 = (Tuple2i) t1; 278 | return(this.x == t2.x && this.y == t2.y); 279 | } 280 | catch (NullPointerException e2) { 281 | return false; 282 | } 283 | catch (ClassCastException e1) { 284 | return false; 285 | } 286 | } 287 | 288 | 289 | /** 290 | * Returns a hash code value based on the data values in this 291 | * object. Two different Tuple2i objects with identical data values 292 | * (i.e., Tuple2i.equals returns true) will return the same hash 293 | * code value. Two objects with different data members may return the 294 | * same hash value, although this is not likely. 295 | * @return the integer hash code value 296 | */ 297 | @Override 298 | public int hashCode() { 299 | long bits = 1L; 300 | bits = 31L * bits + (long)x; 301 | bits = 31L * bits + (long)y; 302 | return (int) (bits ^ (bits >> 32)); 303 | } 304 | 305 | 306 | /** 307 | * Clamps the tuple parameter to the range [low, high] and 308 | * places the values into this tuple. 309 | * @param min the lowest value in the tuple after clamping 310 | * @param max the highest value in the tuple after clamping 311 | * @param t the source tuple, which will not be modified 312 | */ 313 | public final void clamp(int min, int max, Tuple2i t) { 314 | if( t.x > max ) { 315 | x = max; 316 | } else if( t.x < min ) { 317 | x = min; 318 | } else { 319 | x = t.x; 320 | } 321 | 322 | if( t.y > max ) { 323 | y = max; 324 | } else if( t.y < min ) { 325 | y = min; 326 | } else { 327 | y = t.y; 328 | } 329 | } 330 | 331 | 332 | /** 333 | * Clamps the minimum value of the tuple parameter to the min 334 | * parameter and places the values into this tuple. 335 | * @param min the lowest value in the tuple after clamping 336 | * @param t the source tuple, which will not be modified 337 | */ 338 | public final void clampMin(int min, Tuple2i t) { 339 | if( t.x < min ) { 340 | x = min; 341 | } else { 342 | x = t.x; 343 | } 344 | 345 | if( t.y < min ) { 346 | y = min; 347 | } else { 348 | y = t.y; 349 | } 350 | } 351 | 352 | 353 | /** 354 | * Clamps the maximum value of the tuple parameter to the max 355 | * parameter and places the values into this tuple. 356 | * @param max the highest value in the tuple after clamping 357 | * @param t the source tuple, which will not be modified 358 | */ 359 | public final void clampMax(int max, Tuple2i t) { 360 | if( t.x > max ) { 361 | x = max; 362 | } else { 363 | x = t.x; 364 | } 365 | 366 | if( t.y > max ) { 367 | y = max; 368 | } else { 369 | y = t.y; 370 | } 371 | } 372 | 373 | 374 | /** 375 | * Sets each component of the tuple parameter to its absolute 376 | * value and places the modified values into this tuple. 377 | * @param t the source tuple, which will not be modified 378 | */ 379 | public final void absolute(Tuple2i t) { 380 | x = Math.abs(t.x); 381 | y = Math.abs(t.y); 382 | } 383 | 384 | 385 | /** 386 | * Clamps this tuple to the range [low, high]. 387 | * @param min the lowest value in this tuple after clamping 388 | * @param max the highest value in this tuple after clamping 389 | */ 390 | public final void clamp(int min, int max) { 391 | if( x > max ) { 392 | x = max; 393 | } else if( x < min ) { 394 | x = min; 395 | } 396 | 397 | if( y > max ) { 398 | y = max; 399 | } else if( y < min ) { 400 | y = min; 401 | } 402 | } 403 | 404 | 405 | /** 406 | * Clamps the minimum value of this tuple to the min parameter. 407 | * @param min the lowest value in this tuple after clamping 408 | */ 409 | public final void clampMin(int min) { 410 | if (x < min) 411 | x=min; 412 | 413 | if (y < min) 414 | y = min; 415 | } 416 | 417 | 418 | /** 419 | * Clamps the maximum value of this tuple to the max parameter. 420 | * @param max the highest value in the tuple after clamping 421 | */ 422 | public final void clampMax(int max) { 423 | if (x > max) 424 | x = max; 425 | 426 | if (y > max) 427 | y = max; 428 | } 429 | 430 | 431 | /** 432 | * Sets each component of this tuple to its absolute value. 433 | */ 434 | public final void absolute() { 435 | x = Math.abs(x); 436 | y = Math.abs(y); 437 | } 438 | 439 | /** 440 | * Creates a new object of the same class as this object. 441 | * 442 | * @return a clone of this instance. 443 | * @exception OutOfMemoryError if there is not enough memory. 444 | * @see java.lang.Cloneable 445 | */ 446 | @Override 447 | public Object clone() { 448 | // Since there are no arrays we can just use Object.clone() 449 | try { 450 | return super.clone(); 451 | } catch (CloneNotSupportedException e) { 452 | // this shouldn't happen, since we are Cloneable 453 | throw new InternalError(); 454 | } 455 | } 456 | 457 | 458 | /** 459 | * Get the x coordinate. 460 | * 461 | * @return the x coordinate. 462 | * 463 | * @since vecmath 1.5 464 | */ 465 | public final int getX() { 466 | return x; 467 | } 468 | 469 | 470 | /** 471 | * Set the x coordinate. 472 | * 473 | * @param x value to x coordinate. 474 | * 475 | * @since vecmath 1.5 476 | */ 477 | public final void setX(int x) { 478 | this.x = x; 479 | } 480 | 481 | 482 | /** 483 | * Get the y coordinate. 484 | * 485 | * @return the y coordinate. 486 | * 487 | * @since vecmath 1.5 488 | */ 489 | public final int getY() { 490 | return y; 491 | } 492 | 493 | 494 | /** 495 | * Set the y coordinate. 496 | * 497 | * @param y value to y coordinate. 498 | * 499 | * @since vecmath 1.5 500 | */ 501 | public final void setY(int y) { 502 | this.y = y; 503 | } 504 | } 505 | -------------------------------------------------------------------------------- /src/javax/vecmath/Tuple3i.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A 3-element tuple represented by signed integer x,y,z 32 | * coordinates. 33 | * 34 | * @since vecmath 1.2 35 | */ 36 | public abstract class Tuple3i implements java.io.Serializable, Cloneable { 37 | 38 | static final long serialVersionUID = -732740491767276200L; 39 | 40 | /** 41 | * The x coordinate. 42 | */ 43 | public int x; 44 | 45 | /** 46 | * The y coordinate. 47 | */ 48 | public int y; 49 | 50 | /** 51 | * The z coordinate. 52 | */ 53 | public int z; 54 | 55 | 56 | /** 57 | * Constructs and initializes a Tuple3i from the specified 58 | * x, y, and z coordinates. 59 | * @param x the x coordinate 60 | * @param y the y coordinate 61 | * @param z the z coordinate 62 | */ 63 | public Tuple3i(int x, int y, int z) { 64 | this.x = x; 65 | this.y = y; 66 | this.z = z; 67 | } 68 | 69 | 70 | /** 71 | * Constructs and initializes a Tuple3i from the array of length 3. 72 | * @param t the array of length 3 containing x, y, and z in order. 73 | */ 74 | public Tuple3i(int[] t) { 75 | this.x = t[0]; 76 | this.y = t[1]; 77 | this.z = t[2]; 78 | } 79 | 80 | 81 | /** 82 | * Constructs and initializes a Tuple3i from the specified Tuple3i. 83 | * @param t1 the Tuple3i containing the initialization x, y, and z 84 | * data. 85 | */ 86 | public Tuple3i(Tuple3i t1) { 87 | this.x = t1.x; 88 | this.y = t1.y; 89 | this.z = t1.z; 90 | } 91 | 92 | 93 | /** 94 | * Constructs and initializes a Tuple3i to (0,0,0). 95 | */ 96 | public Tuple3i() { 97 | this.x = 0; 98 | this.y = 0; 99 | this.z = 0; 100 | } 101 | 102 | 103 | /** 104 | * Sets the value of this tuple to the specified x, y, and z 105 | * coordinates. 106 | * @param x the x coordinate 107 | * @param y the y coordinate 108 | * @param z the z coordinate 109 | */ 110 | public final void set(int x, int y, int z) { 111 | this.x = x; 112 | this.y = y; 113 | this.z = z; 114 | } 115 | 116 | 117 | /** 118 | * Sets the value of this tuple to the specified coordinates in the 119 | * array of length 3. 120 | * @param t the array of length 3 containing x, y, and z in order. 121 | */ 122 | public final void set(int[] t) { 123 | this.x = t[0]; 124 | this.y = t[1]; 125 | this.z = t[2]; 126 | } 127 | 128 | 129 | /** 130 | * Sets the value of this tuple to the value of tuple t1. 131 | * @param t1 the tuple to be copied 132 | */ 133 | public final void set(Tuple3i t1) { 134 | this.x = t1.x; 135 | this.y = t1.y; 136 | this.z = t1.z; 137 | } 138 | 139 | 140 | /** 141 | * Copies the values of this tuple into the array t. 142 | * @param t is the array 143 | */ 144 | public final void get(int[] t) { 145 | t[0] = this.x; 146 | t[1] = this.y; 147 | t[2] = this.z; 148 | } 149 | 150 | 151 | /** 152 | * Copies the values of this tuple into the tuple t. 153 | * @param t is the target tuple 154 | */ 155 | public final void get(Tuple3i t) { 156 | t.x = this.x; 157 | t.y = this.y; 158 | t.z = this.z; 159 | } 160 | 161 | 162 | /** 163 | * Sets the value of this tuple to the sum of tuples t1 and t2. 164 | * @param t1 the first tuple 165 | * @param t2 the second tuple 166 | */ 167 | public final void add(Tuple3i t1, Tuple3i t2) { 168 | this.x = t1.x + t2.x; 169 | this.y = t1.y + t2.y; 170 | this.z = t1.z + t2.z; 171 | } 172 | 173 | 174 | /** 175 | * Sets the value of this tuple to the sum of itself and t1. 176 | * @param t1 the other tuple 177 | */ 178 | public final void add(Tuple3i t1) { 179 | this.x += t1.x; 180 | this.y += t1.y; 181 | this.z += t1.z; 182 | } 183 | 184 | 185 | /** 186 | * Sets the value of this tuple to the difference 187 | * of tuples t1 and t2 (this = t1 - t2). 188 | * @param t1 the first tuple 189 | * @param t2 the second tuple 190 | */ 191 | public final void sub(Tuple3i t1, Tuple3i t2) { 192 | this.x = t1.x - t2.x; 193 | this.y = t1.y - t2.y; 194 | this.z = t1.z - t2.z; 195 | } 196 | 197 | 198 | /** 199 | * Sets the value of this tuple to the difference 200 | * of itself and t1 (this = this - t1). 201 | * @param t1 the other tuple 202 | */ 203 | public final void sub(Tuple3i t1) { 204 | this.x -= t1.x; 205 | this.y -= t1.y; 206 | this.z -= t1.z; 207 | } 208 | 209 | 210 | /** 211 | * Sets the value of this tuple to the negation of tuple t1. 212 | * @param t1 the source tuple 213 | */ 214 | public final void negate(Tuple3i t1) { 215 | this.x = -t1.x; 216 | this.y = -t1.y; 217 | this.z = -t1.z; 218 | } 219 | 220 | 221 | /** 222 | * Negates the value of this tuple in place. 223 | */ 224 | public final void negate() { 225 | this.x = -this.x; 226 | this.y = -this.y; 227 | this.z = -this.z; 228 | } 229 | 230 | 231 | /** 232 | * Sets the value of this tuple to the scalar multiplication 233 | * of tuple t1. 234 | * @param s the scalar value 235 | * @param t1 the source tuple 236 | */ 237 | public final void scale(int s, Tuple3i t1) { 238 | this.x = s*t1.x; 239 | this.y = s*t1.y; 240 | this.z = s*t1.z; 241 | } 242 | 243 | 244 | /** 245 | * Sets the value of this tuple to the scalar multiplication 246 | * of the scale factor with this. 247 | * @param s the scalar value 248 | */ 249 | public final void scale(int s) { 250 | this.x *= s; 251 | this.y *= s; 252 | this.z *= s; 253 | } 254 | 255 | 256 | /** 257 | * Sets the value of this tuple to the scalar multiplication 258 | * of tuple t1 plus tuple t2 (this = s*t1 + t2). 259 | * @param s the scalar value 260 | * @param t1 the tuple to be multipled 261 | * @param t2 the tuple to be added 262 | */ 263 | public final void scaleAdd(int s, Tuple3i t1, Tuple3i t2) { 264 | this.x = s*t1.x + t2.x; 265 | this.y = s*t1.y + t2.y; 266 | this.z = s*t1.z + t2.z; 267 | } 268 | 269 | 270 | /** 271 | * Sets the value of this tuple to the scalar multiplication 272 | * of itself and then adds tuple t1 (this = s*this + t1). 273 | * @param s the scalar value 274 | * @param t1 the tuple to be added 275 | */ 276 | public final void scaleAdd(int s, Tuple3i t1) { 277 | this.x = s*this.x + t1.x; 278 | this.y = s*this.y + t1.y; 279 | this.z = s*this.z + t1.z; 280 | } 281 | 282 | 283 | /** 284 | * Returns a string that contains the values of this Tuple3i. 285 | * The form is (x,y,z). 286 | * @return the String representation 287 | */ 288 | @Override 289 | public String toString() { 290 | return "(" + this.x + ", " + this.y + ", " + this.z + ")"; 291 | } 292 | 293 | 294 | /** 295 | * Returns true if the Object t1 is of type Tuple3i and all of the 296 | * data members of t1 are equal to the corresponding data members in 297 | * this Tuple3i. 298 | * @param t1 the object with which the comparison is made 299 | */ 300 | @Override 301 | public boolean equals(Object t1) { 302 | try { 303 | Tuple3i t2 = (Tuple3i) t1; 304 | return(this.x == t2.x && this.y == t2.y && this.z == t2.z); 305 | } 306 | catch (NullPointerException e2) { 307 | return false; 308 | } 309 | catch (ClassCastException e1) { 310 | return false; 311 | } 312 | } 313 | 314 | 315 | /** 316 | * Returns a hash code value based on the data values in this 317 | * object. Two different Tuple3i objects with identical data values 318 | * (i.e., Tuple3i.equals returns true) will return the same hash 319 | * code value. Two objects with different data members may return the 320 | * same hash value, although this is not likely. 321 | * @return the integer hash code value 322 | */ 323 | @Override 324 | public int hashCode() { 325 | long bits = 1L; 326 | bits = 31L * bits + (long)x; 327 | bits = 31L * bits + (long)y; 328 | bits = 31L * bits + (long)z; 329 | return (int) (bits ^ (bits >> 32)); 330 | } 331 | 332 | 333 | /** 334 | * Clamps the tuple parameter to the range [low, high] and 335 | * places the values into this tuple. 336 | * @param min the lowest value in the tuple after clamping 337 | * @param max the highest value in the tuple after clamping 338 | * @param t the source tuple, which will not be modified 339 | */ 340 | public final void clamp(int min, int max, Tuple3i t) { 341 | if( t.x > max ) { 342 | x = max; 343 | } else if( t.x < min ) { 344 | x = min; 345 | } else { 346 | x = t.x; 347 | } 348 | 349 | if( t.y > max ) { 350 | y = max; 351 | } else if( t.y < min ) { 352 | y = min; 353 | } else { 354 | y = t.y; 355 | } 356 | 357 | if( t.z > max ) { 358 | z = max; 359 | } else if( t.z < min ) { 360 | z = min; 361 | } else { 362 | z = t.z; 363 | } 364 | } 365 | 366 | 367 | /** 368 | * Clamps the minimum value of the tuple parameter to the min 369 | * parameter and places the values into this tuple. 370 | * @param min the lowest value in the tuple after clamping 371 | * @param t the source tuple, which will not be modified 372 | */ 373 | public final void clampMin(int min, Tuple3i t) { 374 | if( t.x < min ) { 375 | x = min; 376 | } else { 377 | x = t.x; 378 | } 379 | 380 | if( t.y < min ) { 381 | y = min; 382 | } else { 383 | y = t.y; 384 | } 385 | 386 | if( t.z < min ) { 387 | z = min; 388 | } else { 389 | z = t.z; 390 | } 391 | } 392 | 393 | 394 | /** 395 | * Clamps the maximum value of the tuple parameter to the max 396 | * parameter and places the values into this tuple. 397 | * @param max the highest value in the tuple after clamping 398 | * @param t the source tuple, which will not be modified 399 | */ 400 | public final void clampMax(int max, Tuple3i t) { 401 | if( t.x > max ) { 402 | x = max; 403 | } else { 404 | x = t.x; 405 | } 406 | 407 | if( t.y > max ) { 408 | y = max; 409 | } else { 410 | y = t.y; 411 | } 412 | 413 | if( t.z > max ) { 414 | z = max; 415 | } else { 416 | z = t.z; 417 | } 418 | } 419 | 420 | 421 | /** 422 | * Sets each component of the tuple parameter to its absolute 423 | * value and places the modified values into this tuple. 424 | * @param t the source tuple, which will not be modified 425 | */ 426 | public final void absolute(Tuple3i t) { 427 | x = Math.abs(t.x); 428 | y = Math.abs(t.y); 429 | z = Math.abs(t.z); 430 | } 431 | 432 | 433 | /** 434 | * Clamps this tuple to the range [low, high]. 435 | * @param min the lowest value in this tuple after clamping 436 | * @param max the highest value in this tuple after clamping 437 | */ 438 | public final void clamp(int min, int max) { 439 | if( x > max ) { 440 | x = max; 441 | } else if( x < min ) { 442 | x = min; 443 | } 444 | 445 | if( y > max ) { 446 | y = max; 447 | } else if( y < min ) { 448 | y = min; 449 | } 450 | 451 | if( z > max ) { 452 | z = max; 453 | } else if( z < min ) { 454 | z = min; 455 | } 456 | } 457 | 458 | 459 | /** 460 | * Clamps the minimum value of this tuple to the min parameter. 461 | * @param min the lowest value in this tuple after clamping 462 | */ 463 | public final void clampMin(int min) { 464 | if (x < min) 465 | x=min; 466 | 467 | if (y < min) 468 | y = min; 469 | 470 | if (z < min) 471 | z = min; 472 | } 473 | 474 | 475 | /** 476 | * Clamps the maximum value of this tuple to the max parameter. 477 | * @param max the highest value in the tuple after clamping 478 | */ 479 | public final void clampMax(int max) { 480 | if (x > max) 481 | x = max; 482 | 483 | if (y > max) 484 | y = max; 485 | 486 | if (z > max) 487 | z = max; 488 | } 489 | 490 | 491 | /** 492 | * Sets each component of this tuple to its absolute value. 493 | */ 494 | public final void absolute() { 495 | x = Math.abs(x); 496 | y = Math.abs(y); 497 | z = Math.abs(z); 498 | } 499 | 500 | /** 501 | * Creates a new object of the same class as this object. 502 | * 503 | * @return a clone of this instance. 504 | * @exception OutOfMemoryError if there is not enough memory. 505 | * @see java.lang.Cloneable 506 | * @since vecmath 1.3 507 | */ 508 | @Override 509 | public Object clone() { 510 | // Since there are no arrays we can just use Object.clone() 511 | try { 512 | return super.clone(); 513 | } catch (CloneNotSupportedException e) { 514 | // this shouldn't happen, since we are Cloneable 515 | throw new InternalError(); 516 | } 517 | } 518 | 519 | 520 | /** 521 | * Get the x coordinate. 522 | * 523 | * @return the x coordinate. 524 | * 525 | * @since vecmath 1.5 526 | */ 527 | public final int getX() { 528 | return x; 529 | } 530 | 531 | 532 | /** 533 | * Set the x coordinate. 534 | * 535 | * @param x value to x coordinate. 536 | * 537 | * @since vecmath 1.5 538 | */ 539 | public final void setX(int x) { 540 | this.x = x; 541 | } 542 | 543 | 544 | /** 545 | * Get the y coordinate. 546 | * 547 | * @return the y coordinate. 548 | * 549 | * @since vecmath 1.5 550 | */ 551 | public final int getY() { 552 | return y; 553 | } 554 | 555 | 556 | /** 557 | * Set the y coordinate. 558 | * 559 | * @param y value to y coordinate. 560 | * 561 | * @since vecmath 1.5 562 | */ 563 | public final void setY(int y) { 564 | this.y = y; 565 | } 566 | 567 | /** 568 | * Get the z coordinate. 569 | * 570 | * @return the z coordinate. 571 | * @since vecmath 1.5 572 | */ 573 | public final int getZ() { 574 | return z; 575 | } 576 | 577 | 578 | /** 579 | * Set the z coordinate. 580 | * 581 | * @param z value to z coordinate. 582 | * 583 | * @since vecmath 1.5 584 | */ 585 | public final void setZ(int z) { 586 | this.z = z; 587 | } 588 | } 589 | -------------------------------------------------------------------------------- /src/javax/vecmath/Tuple2d.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A generic 2-element tuple that is represented by double-precision 32 | * floating point x,y coordinates. 33 | * 34 | */ 35 | public abstract class Tuple2d implements java.io.Serializable, Cloneable { 36 | 37 | static final long serialVersionUID = 6205762482756093838L; 38 | 39 | /** 40 | * The x coordinate. 41 | */ 42 | public double x; 43 | 44 | /** 45 | * The y coordinate. 46 | */ 47 | public double y; 48 | 49 | 50 | /** 51 | * Constructs and initializes a Tuple2d from the specified xy coordinates. 52 | * @param x the x coordinate 53 | * @param y the y coordinate 54 | */ 55 | public Tuple2d(double x, double y) 56 | { 57 | this.x = x; 58 | this.y = y; 59 | } 60 | 61 | 62 | /** 63 | * Constructs and initializes a Tuple2d from the specified array. 64 | * @param t the array of length 2 containing xy in order 65 | */ 66 | public Tuple2d(double[] t) 67 | { 68 | this.x = t[0]; 69 | this.y = t[1]; 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Tuple2d from the specified Tuple2d. 75 | * @param t1 the Tuple2d containing the initialization x y data 76 | */ 77 | public Tuple2d(Tuple2d t1) 78 | { 79 | this.x = t1.x; 80 | this.y = t1.y; 81 | } 82 | 83 | 84 | /** 85 | * Constructs and initializes a Tuple2d from the specified Tuple2f. 86 | * @param t1 the Tuple2f containing the initialization x y data 87 | */ 88 | public Tuple2d(Tuple2f t1) 89 | { 90 | this.x = (double) t1.x; 91 | this.y = (double) t1.y; 92 | } 93 | 94 | /** 95 | * Constructs and initializes a Tuple2d to (0,0). 96 | */ 97 | public Tuple2d() 98 | { 99 | this.x = 0.0; 100 | this.y = 0.0; 101 | } 102 | 103 | 104 | /** 105 | * Sets the value of this tuple to the specified xy coordinates. 106 | * @param x the x coordinate 107 | * @param y the y coordinate 108 | */ 109 | public final void set(double x, double y) 110 | { 111 | this.x = x; 112 | this.y = y; 113 | } 114 | 115 | 116 | /** 117 | * Sets the value of this tuple from the 2 values specified in 118 | * the array. 119 | * @param t the array of length 2 containing xy in order 120 | */ 121 | public final void set(double[] t) 122 | { 123 | this.x = t[0]; 124 | this.y = t[1]; 125 | } 126 | 127 | 128 | /** 129 | * Sets the value of this tuple to the value of the Tuple2d argument. 130 | * @param t1 the tuple to be copied 131 | */ 132 | public final void set(Tuple2d t1) 133 | { 134 | this.x = t1.x; 135 | this.y = t1.y; 136 | } 137 | 138 | 139 | /** 140 | * Sets the value of this tuple to the value of Tuple2f t1. 141 | * @param t1 the tuple to be copied 142 | */ 143 | public final void set(Tuple2f t1) 144 | { 145 | this.x = (double) t1.x; 146 | this.y = (double) t1.y; 147 | } 148 | 149 | /** 150 | * Copies the value of the elements of this tuple into the array t. 151 | * @param t the array that will contain the values of the vector 152 | */ 153 | public final void get(double[] t) 154 | { 155 | t[0] = this.x; 156 | t[1] = this.y; 157 | } 158 | 159 | 160 | /** 161 | * Sets the value of this tuple to the vector sum of tuples t1 and t2. 162 | * @param t1 the first tuple 163 | * @param t2 the second tuple 164 | */ 165 | public final void add(Tuple2d t1, Tuple2d t2) 166 | { 167 | this.x = t1.x + t2.x; 168 | this.y = t1.y + t2.y; 169 | } 170 | 171 | 172 | /** 173 | * Sets the value of this tuple to the vector sum of itself and tuple t1. 174 | * @param t1 the other tuple 175 | */ 176 | public final void add(Tuple2d t1) 177 | { 178 | this.x += t1.x; 179 | this.y += t1.y; 180 | } 181 | 182 | 183 | /** 184 | * Sets the value of this tuple to the vector difference of 185 | * tuple t1 and t2 (this = t1 - t2). 186 | * @param t1 the first tuple 187 | * @param t2 the second tuple 188 | */ 189 | public final void sub(Tuple2d t1, Tuple2d t2) 190 | { 191 | this.x = t1.x - t2.x; 192 | this.y = t1.y - t2.y; 193 | } 194 | 195 | 196 | /** 197 | * Sets the value of this tuple to the vector difference of 198 | * itself and tuple t1 (this = this - t1). 199 | * @param t1 the other vector 200 | */ 201 | public final void sub(Tuple2d t1) 202 | { 203 | this.x -= t1.x; 204 | this.y -= t1.y; 205 | } 206 | 207 | 208 | /** 209 | * Sets the value of this tuple to the negation of tuple t1. 210 | * @param t1 the source vector 211 | */ 212 | public final void negate(Tuple2d t1) 213 | { 214 | this.x = -t1.x; 215 | this.y = -t1.y; 216 | } 217 | 218 | 219 | /** 220 | * Negates the value of this vector in place. 221 | */ 222 | public final void negate() 223 | { 224 | this.x = -this.x; 225 | this.y = -this.y; 226 | } 227 | 228 | 229 | /** 230 | * Sets the value of this tuple to the scalar multiplication 231 | * of tuple t1. 232 | * @param s the scalar value 233 | * @param t1 the source tuple 234 | */ 235 | public final void scale(double s, Tuple2d t1) 236 | { 237 | this.x = s*t1.x; 238 | this.y = s*t1.y; 239 | } 240 | 241 | 242 | /** 243 | * Sets the value of this tuple to the scalar multiplication 244 | * of itself. 245 | * @param s the scalar value 246 | */ 247 | public final void scale(double s) 248 | { 249 | this.x *= s; 250 | this.y *= s; 251 | } 252 | 253 | 254 | /** 255 | * Sets the value of this tuple to the scalar multiplication 256 | * of tuple t1 and then adds tuple t2 (this = s*t1 + t2). 257 | * @param s the scalar value 258 | * @param t1 the tuple to be multipled 259 | * @param t2 the tuple to be added 260 | */ 261 | public final void scaleAdd(double s, Tuple2d t1, Tuple2d t2) 262 | { 263 | this.x = s*t1.x + t2.x; 264 | this.y = s*t1.y + t2.y; 265 | } 266 | 267 | 268 | /** 269 | * Sets the value of this tuple to the scalar multiplication 270 | * of itself and then adds tuple t1 (this = s*this + t1). 271 | * @param s the scalar value 272 | * @param t1 the tuple to be added 273 | */ 274 | public final void scaleAdd(double s, Tuple2d t1) 275 | { 276 | this.x = s*this.x + t1.x; 277 | this.y = s*this.y + t1.y; 278 | } 279 | 280 | 281 | 282 | /** 283 | * Returns a hash code value based on the data values in this 284 | * object. Two different Tuple2d objects with identical data values 285 | * (i.e., Tuple2d.equals returns true) will return the same hash 286 | * code value. Two objects with different data members may return the 287 | * same hash value, although this is not likely. 288 | * @return the integer hash code value 289 | */ 290 | @Override 291 | public int hashCode() { 292 | long bits = 1L; 293 | bits = VecMathUtil.hashDoubleBits(bits, x); 294 | bits = VecMathUtil.hashDoubleBits(bits, y); 295 | return VecMathUtil.hashFinish(bits); 296 | } 297 | 298 | 299 | /** 300 | * Returns true if all of the data members of Tuple2d t1 are 301 | * equal to the corresponding data members in this Tuple2d. 302 | * @param t1 the vector with which the comparison is made 303 | * @return true or false 304 | */ 305 | public boolean equals(Tuple2d t1) 306 | { 307 | try { 308 | return(this.x == t1.x && this.y == t1.y); 309 | } 310 | catch (NullPointerException e2) {return false;} 311 | 312 | } 313 | 314 | /** 315 | * Returns true if the Object t1 is of type Tuple2d and all of the 316 | * data members of t1 are equal to the corresponding data members in 317 | * this Tuple2d. 318 | * @param t1 the object with which the comparison is made 319 | * @return true or false 320 | */ 321 | @Override 322 | public boolean equals(Object t1) 323 | { 324 | try { 325 | Tuple2d t2 = (Tuple2d) t1; 326 | return(this.x == t2.x && this.y == t2.y); 327 | } 328 | catch (NullPointerException e2) {return false;} 329 | catch (ClassCastException e1) {return false;} 330 | 331 | } 332 | 333 | /** 334 | * Returns true if the L-infinite distance between this tuple 335 | * and tuple t1 is less than or equal to the epsilon parameter, 336 | * otherwise returns false. The L-infinite 337 | * distance is equal to MAX[abs(x1-x2), abs(y1-y2)]. 338 | * @param t1 the tuple to be compared to this tuple 339 | * @param epsilon the threshold value 340 | * @return true or false 341 | */ 342 | public boolean epsilonEquals(Tuple2d t1, double epsilon) 343 | { 344 | double diff; 345 | 346 | diff = x - t1.x; 347 | if(Double.isNaN(diff)) return false; 348 | if((diff<0?-diff:diff) > epsilon) return false; 349 | 350 | diff = y - t1.y; 351 | if(Double.isNaN(diff)) return false; 352 | if((diff<0?-diff:diff) > epsilon) return false; 353 | 354 | return true; 355 | } 356 | 357 | /** 358 | * Returns a string that contains the values of this Tuple2d. 359 | * The form is (x,y). 360 | * @return the String representation 361 | */ 362 | @Override 363 | public String toString() 364 | { 365 | return("(" + this.x + ", " + this.y + ")"); 366 | } 367 | 368 | 369 | /** 370 | * Clamps the tuple parameter to the range [low, high] and 371 | * places the values into this tuple. 372 | * @param min the lowest value in the tuple after clamping 373 | * @param max the highest value in the tuple after clamping 374 | * @param t the source tuple, which will not be modified 375 | */ 376 | public final void clamp(double min, double max, Tuple2d t) 377 | { 378 | if( t.x > max ) { 379 | x = max; 380 | } else if( t.x < min ){ 381 | x = min; 382 | } else { 383 | x = t.x; 384 | } 385 | 386 | if( t.y > max ) { 387 | y = max; 388 | } else if( t.y < min ){ 389 | y = min; 390 | } else { 391 | y = t.y; 392 | } 393 | 394 | } 395 | 396 | 397 | /** 398 | * Clamps the minimum value of the tuple parameter to the min 399 | * parameter and places the values into this tuple. 400 | * @param min the lowest value in the tuple after clamping 401 | * @param t the source tuple, which will not be modified 402 | */ 403 | public final void clampMin(double min, Tuple2d t) 404 | { 405 | if( t.x < min ) { 406 | x = min; 407 | } else { 408 | x = t.x; 409 | } 410 | 411 | if( t.y < min ) { 412 | y = min; 413 | } else { 414 | y = t.y; 415 | } 416 | 417 | } 418 | 419 | 420 | /** 421 | * Clamps the maximum value of the tuple parameter to the max 422 | * parameter and places the values into this tuple. 423 | * @param max the highest value in the tuple after clamping 424 | * @param t the source tuple, which will not be modified 425 | */ 426 | public final void clampMax(double max, Tuple2d t) 427 | { 428 | if( t.x > max ) { 429 | x = max; 430 | } else { 431 | x = t.x; 432 | } 433 | 434 | if( t.y > max ) { 435 | y = max; 436 | } else { 437 | y = t.y; 438 | } 439 | 440 | } 441 | 442 | 443 | /** 444 | * Sets each component of the tuple parameter to its absolute 445 | * value and places the modified values into this tuple. 446 | * @param t the source tuple, which will not be modified 447 | */ 448 | public final void absolute(Tuple2d t) 449 | { 450 | x = Math.abs(t.x); 451 | y = Math.abs(t.y); 452 | } 453 | 454 | 455 | 456 | /** 457 | * Clamps this tuple to the range [low, high]. 458 | * @param min the lowest value in this tuple after clamping 459 | * @param max the highest value in this tuple after clamping 460 | */ 461 | public final void clamp(double min, double max) 462 | { 463 | if( x > max ) { 464 | x = max; 465 | } else if( x < min ){ 466 | x = min; 467 | } 468 | 469 | if( y > max ) { 470 | y = max; 471 | } else if( y < min ){ 472 | y = min; 473 | } 474 | 475 | } 476 | 477 | 478 | /** 479 | * Clamps the minimum value of this tuple to the min parameter. 480 | * @param min the lowest value in this tuple after clamping 481 | */ 482 | public final void clampMin(double min) 483 | { 484 | if( x < min ) x=min; 485 | if( y < min ) y=min; 486 | } 487 | 488 | 489 | /** 490 | * Clamps the maximum value of this tuple to the max parameter. 491 | * @param max the highest value in the tuple after clamping 492 | */ 493 | public final void clampMax(double max) 494 | { 495 | if( x > max ) x=max; 496 | if( y > max ) y=max; 497 | } 498 | 499 | 500 | /** 501 | * Sets each component of this tuple to its absolute value. 502 | */ 503 | public final void absolute() 504 | { 505 | x = Math.abs(x); 506 | y = Math.abs(y); 507 | } 508 | 509 | 510 | /** 511 | * Linearly interpolates between tuples t1 and t2 and places the 512 | * result into this tuple: this = (1-alpha)*t1 + alpha*t2. 513 | * @param t1 the first tuple 514 | * @param t2 the second tuple 515 | * @param alpha the alpha interpolation parameter 516 | */ 517 | public final void interpolate(Tuple2d t1, Tuple2d t2, double alpha) 518 | { 519 | this.x = (1-alpha)*t1.x + alpha*t2.x; 520 | this.y = (1-alpha)*t1.y + alpha*t2.y; 521 | } 522 | 523 | 524 | /** 525 | * Linearly interpolates between this tuple and tuple t1 and 526 | * places the result into this tuple: this = (1-alpha)*this + alpha*t1. 527 | * @param t1 the first tuple 528 | * @param alpha the alpha interpolation parameter 529 | */ 530 | public final void interpolate(Tuple2d t1, double alpha) 531 | { 532 | this.x = (1-alpha)*this.x + alpha*t1.x; 533 | this.y = (1-alpha)*this.y + alpha*t1.y; 534 | 535 | } 536 | 537 | /** 538 | * Creates a new object of the same class as this object. 539 | * 540 | * @return a clone of this instance. 541 | * @exception OutOfMemoryError if there is not enough memory. 542 | * @see java.lang.Cloneable 543 | * @since vecmath 1.3 544 | */ 545 | @Override 546 | public Object clone() { 547 | // Since there are no arrays we can just use Object.clone() 548 | try { 549 | return super.clone(); 550 | } catch (CloneNotSupportedException e) { 551 | // this shouldn't happen, since we are Cloneable 552 | throw new InternalError(); 553 | } 554 | } 555 | 556 | 557 | /** 558 | * Get the x coordinate. 559 | * 560 | * @return the x coordinate. 561 | * 562 | * @since vecmath 1.5 563 | */ 564 | public final double getX() { 565 | return x; 566 | } 567 | 568 | 569 | /** 570 | * Set the x coordinate. 571 | * 572 | * @param x value to x coordinate. 573 | * 574 | * @since vecmath 1.5 575 | */ 576 | public final void setX(double x) { 577 | this.x = x; 578 | } 579 | 580 | 581 | /** 582 | * Get the y coordinate. 583 | * 584 | * @return the y coordinate. 585 | * 586 | * @since vecmath 1.5 587 | */ 588 | public final double getY() { 589 | return y; 590 | } 591 | 592 | 593 | /** 594 | * Set the y coordinate. 595 | * 596 | * @param y value to y coordinate. 597 | * 598 | * @since vecmath 1.5 599 | */ 600 | public final void setY(double y) { 601 | this.y = y; 602 | } 603 | 604 | } 605 | -------------------------------------------------------------------------------- /src/javax/vecmath/Tuple2f.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 | * 5 | * This code is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU General Public License version 2 only, as 7 | * published by the Free Software Foundation. Sun designates this 8 | * particular file as subject to the "Classpath" exception as provided 9 | * by Sun in the LICENSE file that accompanied this code. 10 | * 11 | * This code is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 | * version 2 for more details (a copy is included in the LICENSE file that 15 | * accompanied this code). 16 | * 17 | * You should have received a copy of the GNU General Public License version 18 | * 2 along with this work; if not, write to the Free Software Foundation, 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 | * 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 | * CA 95054 USA or visit www.sun.com if you need additional information or 23 | * have any questions. 24 | * 25 | */ 26 | 27 | package javax.vecmath; 28 | 29 | 30 | /** 31 | * A generic 2-element tuple that is represented by single-precision 32 | * floating point x,y coordinates. 33 | * 34 | */ 35 | public abstract class Tuple2f implements java.io.Serializable, Cloneable { 36 | 37 | static final long serialVersionUID = 9011180388985266884L; 38 | 39 | /** 40 | * The x coordinate. 41 | */ 42 | public float x; 43 | 44 | /** 45 | * The y coordinate. 46 | */ 47 | public float y; 48 | 49 | 50 | /** 51 | * Constructs and initializes a Tuple2f from the specified xy coordinates. 52 | * @param x the x coordinate 53 | * @param y the y coordinate 54 | */ 55 | public Tuple2f(float x, float y) 56 | { 57 | this.x = x; 58 | this.y = y; 59 | } 60 | 61 | 62 | /** 63 | * Constructs and initializes a Tuple2f from the specified array. 64 | * @param t the array of length 2 containing xy in order 65 | */ 66 | public Tuple2f(float[] t) 67 | { 68 | this.x = t[0]; 69 | this.y = t[1]; 70 | } 71 | 72 | 73 | /** 74 | * Constructs and initializes a Tuple2f from the specified Tuple2f. 75 | * @param t1 the Tuple2f containing the initialization x y data 76 | */ 77 | public Tuple2f(Tuple2f t1) 78 | { 79 | this.x = t1.x; 80 | this.y = t1.y; 81 | } 82 | 83 | 84 | /** 85 | * Constructs and initializes a Tuple2f from the specified Tuple2d. 86 | * @param t1 the Tuple2d containing the initialization x y data 87 | */ 88 | public Tuple2f(Tuple2d t1) 89 | { 90 | this.x = (float) t1.x; 91 | this.y = (float) t1.y; 92 | } 93 | 94 | 95 | /** 96 | * Constructs and initializes a Tuple2f to (0,0). 97 | */ 98 | public Tuple2f() 99 | { 100 | this.x = (float) 0.0; 101 | this.y = (float) 0.0; 102 | } 103 | 104 | 105 | /** 106 | * Sets the value of this tuple to the specified xy coordinates. 107 | * @param x the x coordinate 108 | * @param y the y coordinate 109 | */ 110 | public final void set(float x, float y) 111 | { 112 | this.x = x; 113 | this.y = y; 114 | } 115 | 116 | 117 | /** 118 | * Sets the value of this tuple from the 2 values specified in 119 | * the array. 120 | * @param t the array of length 2 containing xy in order 121 | */ 122 | public final void set(float[] t) 123 | { 124 | this.x = t[0]; 125 | this.y = t[1]; 126 | } 127 | 128 | 129 | /** 130 | * Sets the value of this tuple to the value of the Tuple2f argument. 131 | * @param t1 the tuple to be copied 132 | */ 133 | public final void set(Tuple2f t1) 134 | { 135 | this.x = t1.x; 136 | this.y = t1.y; 137 | } 138 | 139 | 140 | /** 141 | * Sets the value of this tuple to the value of the Tuple2d argument. 142 | * @param t1 the tuple to be copied 143 | */ 144 | public final void set(Tuple2d t1) 145 | { 146 | this.x = (float) t1.x; 147 | this.y = (float) t1.y; 148 | } 149 | 150 | 151 | /** 152 | * Copies the value of the elements of this tuple into the array t. 153 | * @param t the array that will contain the values of the vector 154 | */ 155 | public final void get(float[] t) 156 | { 157 | t[0] = this.x; 158 | t[1] = this.y; 159 | } 160 | 161 | 162 | /** 163 | * Sets the value of this tuple to the vector sum of tuples t1 and t2. 164 | * @param t1 the first tuple 165 | * @param t2 the second tuple 166 | */ 167 | public final void add(Tuple2f t1, Tuple2f t2) 168 | { 169 | this.x = t1.x + t2.x; 170 | this.y = t1.y + t2.y; 171 | } 172 | 173 | 174 | /** 175 | * Sets the value of this tuple to the vector sum of itself and tuple t1. 176 | * @param t1 the other tuple 177 | */ 178 | public final void add(Tuple2f t1) 179 | { 180 | this.x += t1.x; 181 | this.y += t1.y; 182 | } 183 | 184 | 185 | /** 186 | * Sets the value of this tuple to the vector difference of 187 | * tuple t1 and t2 (this = t1 - t2). 188 | * @param t1 the first tuple 189 | * @param t2 the second tuple 190 | */ 191 | public final void sub(Tuple2f t1, Tuple2f t2) 192 | { 193 | this.x = t1.x - t2.x; 194 | this.y = t1.y - t2.y; 195 | } 196 | 197 | 198 | /** 199 | * Sets the value of this tuple to the vector difference of 200 | * itself and tuple t1 (this = this - t1). 201 | * @param t1 the other tuple 202 | */ 203 | public final void sub(Tuple2f t1) 204 | { 205 | this.x -= t1.x; 206 | this.y -= t1.y; 207 | } 208 | 209 | 210 | /** 211 | * Sets the value of this tuple to the negation of tuple t1. 212 | * @param t1 the source tuple 213 | */ 214 | public final void negate(Tuple2f t1) 215 | { 216 | this.x = -t1.x; 217 | this.y = -t1.y; 218 | } 219 | 220 | 221 | /** 222 | * Negates the value of this vector in place. 223 | */ 224 | public final void negate() 225 | { 226 | this.x = -this.x; 227 | this.y = -this.y; 228 | } 229 | 230 | 231 | /** 232 | * Sets the value of this tuple to the scalar multiplication 233 | * of tuple t1. 234 | * @param s the scalar value 235 | * @param t1 the source tuple 236 | */ 237 | public final void scale(float s, Tuple2f t1) 238 | { 239 | this.x = s*t1.x; 240 | this.y = s*t1.y; 241 | } 242 | 243 | 244 | /** 245 | * Sets the value of this tuple to the scalar multiplication 246 | * of itself. 247 | * @param s the scalar value 248 | */ 249 | public final void scale(float s) 250 | { 251 | this.x *= s; 252 | this.y *= s; 253 | } 254 | 255 | 256 | /** 257 | * Sets the value of this tuple to the scalar multiplication 258 | * of tuple t1 and then adds tuple t2 (this = s*t1 + t2). 259 | * @param s the scalar value 260 | * @param t1 the tuple to be multipled 261 | * @param t2 the tuple to be added 262 | */ 263 | public final void scaleAdd(float s, Tuple2f t1, Tuple2f t2) 264 | { 265 | this.x = s*t1.x + t2.x; 266 | this.y = s*t1.y + t2.y; 267 | } 268 | 269 | 270 | /** 271 | * Sets the value of this tuple to the scalar multiplication 272 | * of itself and then adds tuple t1 (this = s*this + t1). 273 | * @param s the scalar value 274 | * @param t1 the tuple to be added 275 | */ 276 | public final void scaleAdd(float s, Tuple2f t1) 277 | { 278 | this.x = s*this.x + t1.x; 279 | this.y = s*this.y + t1.y; 280 | } 281 | 282 | 283 | 284 | /** 285 | * Returns a hash code value based on the data values in this 286 | * object. Two different Tuple2f objects with identical data values 287 | * (i.e., Tuple2f.equals returns true) will return the same hash 288 | * code value. Two objects with different data members may return the 289 | * same hash value, although this is not likely. 290 | * @return the integer hash code value 291 | */ 292 | @Override 293 | public int hashCode() { 294 | long bits = 1L; 295 | bits = VecMathUtil.hashFloatBits(bits, x); 296 | bits = VecMathUtil.hashFloatBits(bits, y); 297 | return VecMathUtil.hashFinish(bits); 298 | } 299 | 300 | 301 | /** 302 | * Returns true if all of the data members of Tuple2f t1 are 303 | * equal to the corresponding data members in this Tuple2f. 304 | * @param t1 the vector with which the comparison is made 305 | * @return true or false 306 | */ 307 | public boolean equals(Tuple2f t1) 308 | { 309 | try { 310 | return(this.x == t1.x && this.y == t1.y); 311 | } 312 | catch (NullPointerException e2) {return false;} 313 | 314 | } 315 | 316 | /** 317 | * Returns true if the Object t1 is of type Tuple2f and all of the 318 | * data members of t1 are equal to the corresponding data members in 319 | * this Tuple2f. 320 | * @param t1 the object with which the comparison is made 321 | * @return true or false 322 | */ 323 | @Override 324 | public boolean equals(Object t1) 325 | { 326 | try { 327 | Tuple2f t2 = (Tuple2f) t1; 328 | return(this.x == t2.x && this.y == t2.y); 329 | } 330 | catch (NullPointerException e2) {return false;} 331 | catch (ClassCastException e1) {return false;} 332 | 333 | } 334 | 335 | /** 336 | * Returns true if the L-infinite distance between this tuple 337 | * and tuple t1 is less than or equal to the epsilon parameter, 338 | * otherwise returns false. The L-infinite 339 | * distance is equal to MAX[abs(x1-x2), abs(y1-y2)]. 340 | * @param t1 the tuple to be compared to this tuple 341 | * @param epsilon the threshold value 342 | * @return true or false 343 | */ 344 | public boolean epsilonEquals(Tuple2f t1, float epsilon) 345 | { 346 | float diff; 347 | 348 | diff = x - t1.x; 349 | if(Float.isNaN(diff)) return false; 350 | if((diff<0?-diff:diff) > epsilon) return false; 351 | 352 | diff = y - t1.y; 353 | if(Float.isNaN(diff)) return false; 354 | if((diff<0?-diff:diff) > epsilon) return false; 355 | 356 | return true; 357 | } 358 | 359 | /** 360 | * Returns a string that contains the values of this Tuple2f. 361 | * The form is (x,y). 362 | * @return the String representation 363 | */ 364 | @Override 365 | public String toString() 366 | { 367 | return("(" + this.x + ", " + this.y + ")"); 368 | } 369 | 370 | 371 | /** 372 | * Clamps the tuple parameter to the range [low, high] and 373 | * places the values into this tuple. 374 | * @param min the lowest value in the tuple after clamping 375 | * @param max the highest value in the tuple after clamping 376 | * @param t the source tuple, which will not be modified 377 | */ 378 | public final void clamp(float min, float max, Tuple2f t) 379 | { 380 | if( t.x > max ) { 381 | x = max; 382 | } else if( t.x < min ){ 383 | x = min; 384 | } else { 385 | x = t.x; 386 | } 387 | 388 | if( t.y > max ) { 389 | y = max; 390 | } else if( t.y < min ){ 391 | y = min; 392 | } else { 393 | y = t.y; 394 | } 395 | 396 | } 397 | 398 | 399 | /** 400 | * Clamps the minimum value of the tuple parameter to the min 401 | * parameter and places the values into this tuple. 402 | * @param min the lowest value in the tuple after clamping 403 | * @param t the source tuple, which will not be modified 404 | */ 405 | public final void clampMin(float min, Tuple2f t) 406 | { 407 | if( t.x < min ) { 408 | x = min; 409 | } else { 410 | x = t.x; 411 | } 412 | 413 | if( t.y < min ) { 414 | y = min; 415 | } else { 416 | y = t.y; 417 | } 418 | 419 | } 420 | 421 | 422 | /** 423 | * Clamps the maximum value of the tuple parameter to the max 424 | * parameter and places the values into this tuple. 425 | * @param max the highest value in the tuple after clamping 426 | * @param t the source tuple, which will not be modified 427 | */ 428 | public final void clampMax(float max, Tuple2f t) 429 | { 430 | if( t.x > max ) { 431 | x = max; 432 | } else { 433 | x = t.x; 434 | } 435 | 436 | if( t.y > max ) { 437 | y = max; 438 | } else { 439 | y = t.y; 440 | } 441 | 442 | } 443 | 444 | 445 | /** 446 | * Sets each component of the tuple parameter to its absolute 447 | * value and places the modified values into this tuple. 448 | * @param t the source tuple, which will not be modified 449 | */ 450 | public final void absolute(Tuple2f t) 451 | { 452 | x = Math.abs(t.x); 453 | y = Math.abs(t.y); 454 | } 455 | 456 | 457 | 458 | /** 459 | * Clamps this tuple to the range [low, high]. 460 | * @param min the lowest value in this tuple after clamping 461 | * @param max the highest value in this tuple after clamping 462 | */ 463 | public final void clamp(float min, float max) 464 | { 465 | if( x > max ) { 466 | x = max; 467 | } else if( x < min ){ 468 | x = min; 469 | } 470 | 471 | if( y > max ) { 472 | y = max; 473 | } else if( y < min ){ 474 | y = min; 475 | } 476 | 477 | } 478 | 479 | 480 | /** 481 | * Clamps the minimum value of this tuple to the min parameter. 482 | * @param min the lowest value in this tuple after clamping 483 | */ 484 | public final void clampMin(float min) 485 | { 486 | if( x < min ) x=min; 487 | if( y < min ) y=min; 488 | } 489 | 490 | 491 | /** 492 | * Clamps the maximum value of this tuple to the max parameter. 493 | * @param max the highest value in the tuple after clamping 494 | */ 495 | public final void clampMax(float max) 496 | { 497 | if( x > max ) x=max; 498 | if( y > max ) y=max; 499 | } 500 | 501 | 502 | /** 503 | * Sets each component of this tuple to its absolute value. 504 | */ 505 | public final void absolute() 506 | { 507 | x = Math.abs(x); 508 | y = Math.abs(y); 509 | } 510 | 511 | 512 | /** 513 | * Linearly interpolates between tuples t1 and t2 and places the 514 | * result into this tuple: this = (1-alpha)*t1 + alpha*t2. 515 | * @param t1 the first tuple 516 | * @param t2 the second tuple 517 | * @param alpha the alpha interpolation parameter 518 | */ 519 | public final void interpolate(Tuple2f t1, Tuple2f t2, float alpha) 520 | { 521 | this.x = (1-alpha)*t1.x + alpha*t2.x; 522 | this.y = (1-alpha)*t1.y + alpha*t2.y; 523 | 524 | } 525 | 526 | 527 | /** 528 | * Linearly interpolates between this tuple and tuple t1 and 529 | * places the result into this tuple: this = (1-alpha)*this + alpha*t1. 530 | * @param t1 the first tuple 531 | * @param alpha the alpha interpolation parameter 532 | */ 533 | public final void interpolate(Tuple2f t1, float alpha) 534 | { 535 | 536 | this.x = (1-alpha)*this.x + alpha*t1.x; 537 | this.y = (1-alpha)*this.y + alpha*t1.y; 538 | 539 | } 540 | 541 | /** 542 | * Creates a new object of the same class as this object. 543 | * 544 | * @return a clone of this instance. 545 | * @exception OutOfMemoryError if there is not enough memory. 546 | * @see java.lang.Cloneable 547 | * @since vecmath 1.3 548 | */ 549 | @Override 550 | public Object clone() { 551 | // Since there are no arrays we can just use Object.clone() 552 | try { 553 | return super.clone(); 554 | } catch (CloneNotSupportedException e) { 555 | // this shouldn't happen, since we are Cloneable 556 | throw new InternalError(); 557 | } 558 | } 559 | 560 | 561 | /** 562 | * Get the x coordinate. 563 | * 564 | * @return the x coordinate. 565 | * 566 | * @since vecmath 1.5 567 | */ 568 | public final float getX() { 569 | return x; 570 | } 571 | 572 | 573 | /** 574 | * Set the x coordinate. 575 | * 576 | * @param x value to x coordinate. 577 | * 578 | * @since vecmath 1.5 579 | */ 580 | public final void setX(float x) { 581 | this.x = x; 582 | } 583 | 584 | 585 | /** 586 | * Get the y coordinate. 587 | * 588 | * @return the y coordinate. 589 | * 590 | * @since vecmath 1.5 591 | */ 592 | public final float getY() { 593 | return y; 594 | } 595 | 596 | 597 | /** 598 | * Set the y coordinate. 599 | * 600 | * @param y value to y coordinate. 601 | * 602 | * @since vecmath 1.5 603 | */ 604 | public final void setY(float y) { 605 | this.y = y; 606 | } 607 | } 608 | --------------------------------------------------------------------------------