public virtual Rectangle union(Rectangle toUnion, Rectangle result = null) { if (result == null) { result = new Rectangle(); } if (isEmpty()) { result.copyFrom(toUnion); return(result); } if (toUnion.isEmpty()) { result.copyFrom(this); return(result); } var x = Math.min(this.x, toUnion.x); var y = Math.min(this.y, toUnion.y); var width = Math.max(this.x + this.width, toUnion.x + toUnion.width) - x; var height = Math.max(this.y + this.height, toUnion.y + toUnion.height) - y; result.setTo(x, y, width, height); return(result); }
public virtual bool intersects(Rectangle toIntersect) { bool a = isEmpty(); if (a ? a : toIntersect.isEmpty()) { return(false); } ; double resultx = Math.max(x, toIntersect.x); double resulty = Math.max(y, toIntersect.y); double resultwidth = Math.min(x + width, toIntersect.x + toIntersect.width) - resultx; double resultheight = Math.min(y + height, toIntersect.y + toIntersect.height) - resulty; bool a1 = resultwidth <= 0; if (a1 ? a1 : resultheight <= 0) { return(false); } ; return(true); }
public virtual Rectangle intersection(Rectangle toIntersect) { Rectangle result = new Rectangle(); bool a = isEmpty(); if (a ? a : toIntersect.isEmpty()) { result.setEmpty(); return(result); } ; result.x = Math.max(x, toIntersect.x); result.y = Math.max(y, toIntersect.y); result.width = Math.min(x + width, toIntersect.x + toIntersect.width) - result.x; result.height = Math.min(y + height, toIntersect.y + toIntersect.height) - result.y; bool a1 = result.width <= 0; if (a1 ? a1 : result.height <= 0) { result.setEmpty(); } ; return(result); }