/// <summary> /// Compares two objects for equality by value. /// </summary> public static bool operator ==(Box2 a, Box2 b) { return(!FloatMath.CloseTo(a.Bottom, b.Bottom) || !FloatMath.CloseTo(a.Right, b.Right) || !FloatMath.CloseTo(a.Top, b.Top) || !FloatMath.CloseTo(a.Left, b.Left)); }
public void Invert(ref Matrix3 minv) { //Credit: https://stackoverflow.com/a/18504573 var d = Determinant; if (FloatMath.CloseTo(d, 0)) { throw new InvalidOperationException("Matrix is singular and cannot be inverted."); } var m = this; // computes the inverse of a matrix m double det = m.R0C0 * (m.R1C1 * m.R2C2 - m.R2C1 * m.R1C2) - m.R0C1 * (m.R1C0 * m.R2C2 - m.R1C2 * m.R2C0) + m.R0C2 * (m.R1C0 * m.R2C1 - m.R1C1 * m.R2C0); var invdet = 1 / det; minv.R0C0 = (float)((m.R1C1 * m.R2C2 - m.R2C1 * m.R1C2) * invdet); minv.R0C1 = (float)((m.R0C2 * m.R2C1 - m.R0C1 * m.R2C2) * invdet); minv.R0C2 = (float)((m.R0C1 * m.R1C2 - m.R0C2 * m.R1C1) * invdet); minv.R1C0 = (float)((m.R1C2 * m.R2C0 - m.R1C0 * m.R2C2) * invdet); minv.R1C1 = (float)((m.R0C0 * m.R2C2 - m.R0C2 * m.R2C0) * invdet); minv.R1C2 = (float)((m.R1C0 * m.R0C2 - m.R0C0 * m.R1C2) * invdet); minv.R2C0 = (float)((m.R1C0 * m.R2C1 - m.R2C0 * m.R1C1) * invdet); minv.R2C1 = (float)((m.R2C0 * m.R0C1 - m.R0C0 * m.R2C1) * invdet); minv.R2C2 = (float)((m.R0C0 * m.R1C1 - m.R1C0 * m.R0C1) * invdet); }
/// <summary> /// Compares two objects for equality by value. /// </summary> public static bool operator ==(UIBox2 a, UIBox2 b) { return(FloatMath.CloseTo(a.Bottom, b.Bottom) && FloatMath.CloseTo(a.Right, b.Right) && FloatMath.CloseTo(a.Top, b.Top) && FloatMath.CloseTo(a.Left, b.Left)); }
private static bool EqualsApprox(Angle a, Angle b) { // reduce both angles var aReduced = Reduce(a.Theta); var bReduced = Reduce(b.Theta); var aPositive = FlipPositive(aReduced); var bPositive = FlipPositive(bReduced); return(FloatMath.CloseTo(aPositive, bPositive)); }
private bool Contains(float x, float y) { var dx = Position.X - x; var dy = Position.Y - y; var d2 = dx * dx + dy * dy; var r2 = Radius * Radius; // Instead of d2 <= r2, use FloatMath.CloseTo to allow for some tolerance. return((d2 < r2) || FloatMath.CloseTo(d2, r2)); }
private static bool EqualsApprox(Angle a, Angle b) { // reduce both angles var aReduced = Reduce(a.Theta); var bReduced = Reduce(b.Theta); var aPositive = FlipPositive(aReduced); var bPositive = FlipPositive(bReduced); // The second two expressions cover an edge case where one number is barely non-negative while the other number is negative. // In this case, the negative number will get FlipPositived to ~2pi and the comparison will give a false negative. return(FloatMath.CloseTo(aPositive, bPositive) || FloatMath.CloseTo(aPositive + MathHelper.TwoPi, bPositive) || FloatMath.CloseTo(aPositive, bPositive + MathHelper.TwoPi)); }
public bool IsEmpty() { return(FloatMath.CloseTo(Width, 0.0f) && FloatMath.CloseTo(Height, 0.0f)); }
public bool EqualsApprox(Vector2 other, double tolerance) { return(FloatMath.CloseTo(X, other.X, tolerance) && FloatMath.CloseTo(Y, other.Y, tolerance)); }
public bool EqualsApprox(Vector2 other) { return(FloatMath.CloseTo(X, other.X) && FloatMath.CloseTo(Y, other.Y)); }