瀏覽代碼

added distance()

Nicolas Cannasse 4 年之前
父節點
當前提交
b3b002c726
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      h2d/col/Polygon.hx

+ 8 - 1
h2d/col/Polygon.hx

@@ -280,10 +280,17 @@ abstract Polygon(Array<Point>) from Array<Point> to Array<Point> {
 	}
 
 	/**
-		Return the squared distance of `pt` to the closest edge.
+		Return the distance of `pt` to the closest edge.
 		If outside is `true`, only return a positive value if `pt` is outside the polygon, zero otherwise
 		If outside is `false`, only return a positive value if `pt` is inside the polygon, zero otherwise
 	**/
+	public function distance(pt : Point, ?outside : Bool) {
+		return Math.sqrt(distanceSq(pt, outside));
+	}
+
+	/**
+	 * Same as `distance` but returns the squared value
+	 */
 	public function distanceSq(pt : Point, ?outside : Bool) {
 		var p1 = points[points.length - 1];
 		var minDistSq = 1e10;