ncannasse 12 年之前
父节点
当前提交
a09574a59c
共有 1 个文件被更改,包括 37 次插入0 次删除
  1. 37 0
      h2d/col/Point.hx

+ 37 - 0
h2d/col/Point.hx

@@ -23,5 +23,42 @@ class Point {
 	public function toString() {
 		return "{" + h3d.FMath.fmt(x) + "," + h3d.FMath.fmt(y) + "}";
 	}
+		
+	public inline function sub( p : Point ) {
+		return new Point(x - p.x, y - p.y);
+	}
+
+	public inline function add( p : Point ) {
+		return new Point(x + p.x, y + p.y);
+	}
+
+	public inline function dot( p : Point ) {
+		return x * p.x + y * p.y;
+	}
+
+	public inline function lengthSq() {
+		return x * x + y * y;
+	}
+
+	public inline function length() {
+		return h3d.FMath.sqrt(lengthSq());
+	}
+
+	public function normalize() {
+		var k = lengthSq();
+		if( k < h3d.FMath.EPSILON ) k = 0 else k = h3d.FMath.isqrt(k);
+		x *= k;
+		y *= k;
+	}
+
+	public inline function set(x,y) {
+		this.x = x;
+		this.y = y;
+	}
+
+	public inline function scale( f : Float ) {
+		x *= f;
+		y *= f;
+	}
 	
 }