/// <summary> /// Return objects that are within maxDistance of the specified ray. /// </summary> /// <param name="ray">The ray.</param> /// <param name="maxDistance">Maximum distance from the ray to consider.</param> /// <param name="result">List result.</param> /// <returns>Objects within range.</returns> public void GetNearby(ref XYZ point, ref float maxDistance, List <T> result) { // Does the ray hit this node at all? // Note: Expanding the bounds is not exactly the same as a real distance check, but it's fast. // TODO: Does someone have a fast AND accurate formula to do this check? //bounds.ExpandToContain(new XYZ(maxDistance * 2, maxDistance * 2, maxDistance * 2)); HLBoundingBoxXYZ d = new HLBoundingBoxXYZ(bounds.MidPoint, bounds.Size); d.ExpandToContain(new XYZ(bounds.Max.X + maxDistance, bounds.Max.Y + maxDistance, bounds.Max.Z + maxDistance)); d.ExpandToContain(new XYZ(bounds.Min.X - maxDistance, bounds.Min.Y - maxDistance, bounds.Min.Z - maxDistance)); bool intersected = d.Contains(point); d.Size = actualBoundsSize; if (!intersected) { return; } // Check against any objects in this node for (int i = 0; i < objects.Count; i++) { if (System.Math.Abs(objects[i].Pos.DistanceTo(point)) <= maxDistance) { result.Add(objects[i].Obj); } } // Check children if (children != null) { for (int i = 0; i < 8; i++) { children[i].GetNearby(ref point, ref maxDistance, result); } } }
/// <summary> /// Checks if outerBounds encapsulates the given point. /// </summary> /// <param name="outerBounds">Outer bounds.</param> /// <param name="point">Point.</param> /// <returns>True if innerBounds is fully encapsulated by outerBounds.</returns> static bool Encapsulates(HLBoundingBoxXYZ outerBounds, XYZ point) { return(outerBounds.Contains(point)); }
/// <summary> /// Checks if outerBounds encapsulates innerBounds. /// </summary> /// <param name="outerBounds">Outer bounds.</param> /// <param name="innerBounds">Inner bounds.</param> /// <returns>True if innerBounds is fully encapsulated by outerBounds.</returns> static bool Encapsulates(HLBoundingBoxXYZ outerBounds, HLBoundingBoxXYZ innerBounds) { return(outerBounds.Contains(innerBounds.Min) && outerBounds.Contains(innerBounds.Max)); }