001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019/* 020* 021 022Licensed under the Apache License, Version 2.0 (the "License"); 023you may not use this file except in compliance with the License. 024You may obtain a copy of the License at 025 026 http://www.apache.org/licenses/LICENSE-2.0 027 028Unless required by applicable law or agreed to in writing, software 029distributed under the License is distributed on an "AS IS" BASIS, 030WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 031See the License for the specific language governing permissions and 032limitations under the License. 033*/ 034 035package lucee.runtime.img.vecmath; 036 037/** 038 * Vector math package, converted to look similar to javax.vecmath. 039 */ 040public class Tuple3f { 041 public float x, y, z; 042 043 public Tuple3f() { 044 this( 0, 0, 0 ); 045 } 046 047 public Tuple3f( float[] x ) { 048 this.x = x[0]; 049 this.y = x[1]; 050 this.z = x[2]; 051 } 052 053 public Tuple3f( float x, float y, float z ) { 054 this.x = x; 055 this.y = y; 056 this.z = z; 057 } 058 059 public Tuple3f( Tuple3f t ) { 060 this.x = t.x; 061 this.y = t.y; 062 this.z = t.z; 063 } 064 065 public void absolute() { 066 x = Math.abs(x); 067 y = Math.abs(y); 068 z = Math.abs(z); 069 } 070 071 public void absolute( Tuple3f t ) { 072 x = Math.abs(t.x); 073 y = Math.abs(t.y); 074 z = Math.abs(t.z); 075 } 076 077 public void clamp( float min, float max ) { 078 if ( x < min ) 079 x = min; 080 else if ( x > max ) 081 x = max; 082 if ( y < min ) 083 y = min; 084 else if ( y > max ) 085 y = max; 086 if ( z < min ) 087 z = min; 088 else if ( z > max ) 089 z = max; 090 } 091 092 public void set( float x, float y, float z ) { 093 this.x = x; 094 this.y = y; 095 this.z = z; 096 } 097 098 public void set( float[] x ) { 099 this.x = x[0]; 100 this.y = x[1]; 101 this.z = x[2]; 102 } 103 104 public void set( Tuple3f t ) { 105 x = t.x; 106 y = t.y; 107 z = t.z; 108 } 109 110 public void get( Tuple3f t ) { 111 t.x = x; 112 t.y = y; 113 t.z = z; 114 } 115 116 public void get( float[] t ) { 117 t[0] = x; 118 t[1] = y; 119 t[2] = z; 120 } 121 122 public void negate() { 123 x = -x; 124 y = -y; 125 z = -z; 126 } 127 128 public void negate( Tuple3f t ) { 129 x = -t.x; 130 y = -t.y; 131 z = -t.z; 132 } 133 134 public void interpolate( Tuple3f t, float alpha ) { 135 float a = 1-alpha; 136 x = a*x + alpha*t.x; 137 y = a*y + alpha*t.y; 138 z = a*z + alpha*t.z; 139 } 140 141 public void scale( float s ) { 142 x *= s; 143 y *= s; 144 z *= s; 145 } 146 147 public void add( Tuple3f t ) { 148 x += t.x; 149 y += t.y; 150 z += t.z; 151 } 152 153 public void add( Tuple3f t1, Tuple3f t2 ) { 154 x = t1.x+t2.x; 155 y = t1.y+t2.y; 156 z = t1.z+t2.z; 157 } 158 159 public void sub( Tuple3f t ) { 160 x -= t.x; 161 y -= t.y; 162 z -= t.z; 163 } 164 165 public void sub( Tuple3f t1, Tuple3f t2 ) { 166 x = t1.x-t2.x; 167 y = t1.y-t2.y; 168 z = t1.z-t2.z; 169 } 170 171 public void scaleAdd( float s, Tuple3f t ) { 172 x += s*t.x; 173 y += s*t.y; 174 z += s*t.z; 175 } 176 177 public void scaleAdd( float s, Tuple3f t1, Tuple3f t2 ) { 178 x = s*t1.x + t2.x; 179 y = s*t1.y + t2.y; 180 z = s*t1.z + t2.z; 181 } 182 183 public String toString() { 184 return "["+x+", "+y+", "+z+"]"; 185 } 186 187}