/// <summary> /// Gets the first intersection of a ray with a box (closest intersection to the /// ray origin)</summary> /// <param name="ray">Ray</param> /// <param name="box">Box</param> /// <param name="intersection">Intersection point</param> /// <returns>True iff ray hits box</returns> public static bool Intersect(Ray2F ray, Box2F box, ref Vec2F intersection) { // do X slab float tmin, tmax; SlabIntersect( ray.Direction.X, ray.Origin.X, box.Min.X, box.Max.X, out tmin, out tmax); // do Y slab float tminTemp, tmaxTemp; SlabIntersect( ray.Direction.Y, ray.Origin.Y, box.Min.Y, box.Max.Y, out tminTemp, out tmaxTemp); if ((tmin > tmaxTemp) || (tminTemp > tmax)) { return(false); } tmin = Math.Max(tmin, tminTemp); tmax = Math.Min(tmax, tmaxTemp); // intersection at tmin, the maximal-minimal value if (tmin > 0) { intersection = ray.Origin + ray.Direction * tmin; return(true); } return(false); }
/// <summary> /// Gets the first intersection of a ray with a box (closest intersection to the /// ray origin)</summary> /// <param name="ray">Ray</param> /// <param name="box">Box</param> /// <param name="intersection">Intersection point</param> /// <returns>True iff ray hits box</returns> public static bool Intersect(Ray2F ray, Box2F box, ref Vec2F intersection) { // do X slab float tmin, tmax; SlabIntersect( ray.Direction.X, ray.Origin.X, box.Min.X, box.Max.X, out tmin, out tmax); // do Y slab float tminTemp, tmaxTemp; SlabIntersect( ray.Direction.Y, ray.Origin.Y, box.Min.Y, box.Max.Y, out tminTemp, out tmaxTemp); if ((tmin > tmaxTemp) || (tminTemp > tmax)) return false; tmin = Math.Max(tmin, tminTemp); tmax = Math.Min(tmax, tmaxTemp); // intersection at tmin, the maximal-minimal value if (tmin > 0) { intersection = ray.Origin + ray.Direction * tmin; return true; } return false; }
private void TestToStringWithCulture(CultureInfo culture) { CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = culture; try { string listSeparator = culture.TextInfo.ListSeparator; string decimalSeparator = culture.NumberFormat.NumberDecimalSeparator; var corner1 = new Vec2F(1.1f, 2.2f); var corner2 = new Vec2F(4.4f, 5.5f); var o = new Box2F(corner1, corner2); string s = o.ToString(null, null); TestToStringResults(o, s, listSeparator, decimalSeparator); string s2 = o.ToString(); Assert.AreEqual(s, s2); s = o.ToString("G", culture); TestToStringResults(o, s, listSeparator, decimalSeparator); s = o.ToString("R", culture); TestToStringResults(o, s, listSeparator, decimalSeparator); } finally { Thread.CurrentThread.CurrentCulture = originalCulture; } }
/// <summary> /// Extends the box to contain the given box</summary> /// <param name="other">Given box</param> /// <returns>Extended box</returns> public Box2F Extend(Box2F other) { if (!other.IsEmpty) { Extend(other.Min); Extend(other.Max); } return(this); }
private void TestToStringResults(Box2F o, string s, string listSeparator, string decimalSeparator) { string[] results = s.Split(new[] { listSeparator }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual(results.Length, 4); foreach (string oneFloatString in results) Assert.True(oneFloatString.Contains(decimalSeparator)); Assert.AreEqual(float.Parse(results[0]), o.Min.X); Assert.AreEqual(float.Parse(results[1]), o.Min.Y); Assert.AreEqual(float.Parse(results[2]), o.Max.X); Assert.AreEqual(float.Parse(results[3]), o.Max.Y); }
/// <summary> /// Extends the box to contain the given box</summary> /// <param name="other">Given box</param> /// <returns>Extended box</returns> public Box2F Extend(Box2F other) { if (!other.IsEmpty) { Extend(other.Min); Extend(other.Max); } return this; }