public FloatRectangle Intersection(FloatRectangle o) { if (!Intersects(o)) { return(new FloatRectangle(float.NaN, float.NaN, float.NaN, float.NaN)); } var x1 = (float)Math.Max(X, o.X); var x2 = (float)Math.Min(X + Width, o.X + o.Width); var y1 = (float)Math.Max(Y, o.Y); var y2 = (float)Math.Min(Y + Height, o.Y + o.Height); return(new FloatRectangle(x1, y1, x2 - x1, y2 - y1)); }
public bool ContainsCompletely(FloatRectangle o) => X <= o.X && Y <= o.Y && X + Width >= o.X + o.Width && Y + Height >= o.Y + o.Height;
public bool Intersects(FloatRectangle o) => !(X > o.X + o.Width || o.X > X + Width || Y > o.Y + o.Height || o.Y > Y + Height);
public bool StrictlyIntersects(FloatRectangle o) => !(X >= o.X + o.Width || o.X >= X + Width || Y >= o.Y + o.Height || o.Y >= Y + Height);
private FloatRectangle DeriveBoundingBox() { // Find the curve's bounding box float minx = float.PositiveInfinity; float maxx = float.NegativeInfinity; float miny = float.PositiveInfinity; float maxy = float.NegativeInfinity; for (int i = 0; i < NumDrawings; i++) { for (int j = DrawingIndicesStartingIds[i]; j < DrawingIndicesStartingIds[i + 1]; j++) { var v = Vector4.Transform(AllVertices[DrawingIndices[j]], DrawingTransforms[i]); minx = Math.Min(minx, v.X); maxx = Math.Max(maxx, v.X); miny = Math.Min(miny, v.Y); maxy = Math.Max(maxy, v.Y); } for (int j = DrawingCurveVerticesStartingIds[i]; j < DrawingCurveVerticesStartingIds[i + 1]; j++) { var v = Vector4.Transform(DrawingCurveVertices[j].Position, DrawingTransforms[i]); minx = Math.Min(minx, v.X); maxx = Math.Max(maxx, v.X); miny = Math.Min(miny, v.Y); maxy = Math.Max(maxy, v.Y); } for (int j = DrawingDoubleCurveVerticesStartingIds[i]; j < DrawingDoubleCurveVerticesStartingIds[i + 1]; j++) { var v = Vector4.Transform(DrawingDoubleCurveVertices[j].Position, DrawingTransforms[i]); minx = Math.Min(minx, v.X); maxx = Math.Max(maxx, v.X); miny = Math.Min(miny, v.Y); maxy = Math.Max(maxy, v.Y); } } var rectangle = new FloatRectangle(minx, miny, maxx - minx, maxy - miny); // Adjust it to the aspect ratio var value = rectangle.Width * 9 - rectangle.Height * 16; if (value < 0) { var oldWidth = rectangle.Width; rectangle.Width = rectangle.Height * 16 / 9; rectangle.X -= (rectangle.Width - oldWidth) / 2; } else if (value > 0) { var oldHeight = rectangle.Height; rectangle.Height = rectangle.Width * 9 / 16; rectangle.Y -= (rectangle.Height - oldHeight) / 2; } // Enlarge it a bit var owidth = rectangle.Width; var oheight = rectangle.Height; rectangle.Width = rectangle.Width * 6 / 5; rectangle.Height = rectangle.Height * 6 / 5; rectangle.X -= (rectangle.Width - owidth) / 2; rectangle.Y -= (rectangle.Height - oheight) / 2; return(rectangle); }