001 /* 002 * 003 004 Licensed under the Apache License, Version 2.0 (the "License"); 005 you may not use this file except in compliance with the License. 006 You may obtain a copy of the License at 007 008 http://www.apache.org/licenses/LICENSE-2.0 009 010 Unless required by applicable law or agreed to in writing, software 011 distributed under the License is distributed on an "AS IS" BASIS, 012 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 See the License for the specific language governing permissions and 014 limitations under the License. 015 */ 016 017 package railo.runtime.img.vecmath; 018 019 /** 020 * Vector math package, converted to look similar to javax.vecmath. 021 */ 022 public class Point3f extends Tuple3f { 023 024 public Point3f() { 025 this( 0, 0, 0 ); 026 } 027 028 public Point3f( float[] x ) { 029 this.x = x[0]; 030 this.y = x[1]; 031 this.z = x[2]; 032 } 033 034 public Point3f( float x, float y, float z ) { 035 this.x = x; 036 this.y = y; 037 this.z = z; 038 } 039 040 public Point3f( Point3f t ) { 041 this.x = t.x; 042 this.y = t.y; 043 this.z = t.z; 044 } 045 046 public Point3f( Tuple3f t ) { 047 this.x = t.x; 048 this.y = t.y; 049 this.z = t.z; 050 } 051 052 public float distanceL1( Point3f p ) { 053 return Math.abs(x-p.x) + Math.abs(y-p.y) + Math.abs(z-p.z); 054 } 055 056 public float distanceSquared( Point3f p ) { 057 float dx = x-p.x; 058 float dy = y-p.y; 059 float dz = z-p.z; 060 return dx*dx+dy*dy+dz*dz; 061 } 062 063 public float distance( Point3f p ) { 064 float dx = x-p.x; 065 float dy = y-p.y; 066 float dz = z-p.z; 067 return (float)Math.sqrt( dx*dx+dy*dy+dz*dz ); 068 } 069 070 }