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