瀏覽代碼

IPoint: Use round() instead of floor(). IBounds: make sure rounded bounds include original bounds

trethaller 7 年之前
父節點
當前提交
51072f1d6e
共有 2 個文件被更改,包括 4 次插入2 次删除
  1. 3 1
      h2d/col/Bounds.hx
  2. 1 1
      h2d/col/Point.hx

+ 3 - 1
h2d/col/Bounds.hx

@@ -20,7 +20,9 @@ class Bounds {
 	}
 	}
 
 
 	public inline function toIBounds( scale = 1. ) {
 	public inline function toIBounds( scale = 1. ) {
-		return IBounds.fromValues(Math.floor(x * scale), Math.floor(y * scale), Math.floor(width * scale), Math.floor(height * scale));
+		var ix = Math.floor(x * scale);
+		var iy = Math.floor(y * scale);
+		return IBounds.fromValues(ix, iy, Math.ceil(xMax * scale) - ix, Math.ceil(yMax * scale) - iy);
 	}
 	}
 
 
 	public inline function intersects( b : Bounds ) {
 	public inline function intersects( b : Bounds ) {

+ 1 - 1
h2d/col/Point.hx

@@ -12,7 +12,7 @@ class Point {
 	}
 	}
 
 
 	public inline function toIPoint( scale = 1. ) {
 	public inline function toIPoint( scale = 1. ) {
-		return new IPoint(Math.floor(x * scale), Math.floor(y * scale));
+		return new IPoint(Math.round(x * scale), Math.round(y * scale));
 	}
 	}
 
 
 	public inline function distanceSq( p : Point ) {
 	public inline function distanceSq( p : Point ) {