ソースを参照

Added Distance method to Vec2, Vec3.

Mark Sibly 8 年 前
コミット
57ab543cc7
2 ファイル変更22 行追加19 行削除
  1. 13 14
      modules/std/geom/vec2.monkey2
  2. 9 5
      modules/std/geom/vec3.monkey2

+ 13 - 14
modules/std/geom/vec2.monkey2

@@ -122,23 +122,10 @@ Struct Vec2<T>
 		Return Sqrt( x*x+y*y )
 	End
 
-	#rem monkeydoc The normal to the vector.
-	#end	
-	Property Normal:Vec2()
-		Return New Vec2( -y,x )
-	End
-
-	#rem monkeydoc Computes the dot product of the vector with another vector.
-	#end
-	Method Dot:Double( v:Vec2 )
-		Return x*v.x+y*v.y
-	End
-	
 	#rem monkeydoc Computes the distance from this vector to another.
 	#end
 	Method Distance:Double( v:Vec2 )
-		Local d:=v-Self
-		Return Sqrt( d.Dot( d ) )
+		Return (v-Self).Length
 	End
 	
 	#rem monkeydoc Normalizes the vector and returns the result.
@@ -147,6 +134,18 @@ Struct Vec2<T>
 		Return Self/Length
 	End
 	
+	#rem monkeydoc The normal to the vector.
+	#end	
+	Property Normal:Vec2()
+		Return New Vec2( -y,x )
+	End
+
+	#rem monkeydoc Computes the dot product of the vector with another vector.
+	#end
+	Method Dot:T( v:Vec2 )
+		Return x*v.x+y*v.y
+	End
+	
 	#rem monkeydoc Blends the vector with another vector and returns the result.
 	#end
 	Method Blend:Vec2( v:Vec2,alpha:Double )

+ 9 - 5
modules/std/geom/vec3.monkey2

@@ -107,8 +107,16 @@ Struct Vec3<T>
 	Property Length:Double()
 		Return Sqrt( x*x+y*y+z*z )
 	End
+
+	Method Distance:Double( v:Vec3 )
+		Return (v-Self).Length
+	End
+
+	Method Normalize:Vec3()
+		Return Self/Length
+	End
 	
-	Method Dot:Double( v:Vec3 )
+	Method Dot:T( v:Vec3 )
 		Return x*v.x+y*v.y+z*v.z
 	End
 
@@ -116,10 +124,6 @@ Struct Vec3<T>
 		Return New Vec3( y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x )
 	End
 	
-	Method Normalize:Vec3()
-		Return Self/Length
-	End
-	
 	Method Blend:Vec3( v:Vec3,alpha:Double )
 		Return New Vec3( (v.x-x)*alpha+x,(v.y-y)*alpha+y,(v.z-z)*alpha+z )
 	End