/// <summary> /// Applies the specified image. /// </summary> /// <param name="image">The image.</param> /// <param name="targetLocation">The target location.</param> /// <returns></returns> public override unsafe Image Apply(Image image, Numerics.Rectangle targetLocation = default(Numerics.Rectangle)) { targetLocation = targetLocation == default(Numerics.Rectangle) ? new Numerics.Rectangle(0, 0, image.Width, image.Height) : targetLocation.Clamp(image); Bounds = Bounds.Clamp(targetLocation); return(Fill ? DrawFilledRectangle(image, Bounds) : DrawRectangleOutline(image, targetLocation)); }
public bool TryAdd(ref T item) { #if ENABLE_UNITY_COLLECTIONS_CHECKS AtomicSafetyHandle.CheckWriteAndThrow(_safety); #endif var bounds = new Bounds(item.GetCenter(), item.GetSize()); bounds.Clamp(_data->WorldBounds); var itemID = Interlocked.Increment(ref _data->Counter); item.SpatialHashingIndex = itemID; if (_itemIDToBounds.TryAdd(itemID, bounds) == false || _itemIDToItem.TryAdd(itemID, item) == false) { return(false); } CalculStartEndIterationInternal(_data, bounds, out var start, out var end); var hashPosition = new int3(0F); for (int x = start.x; x < end.x; ++x) { hashPosition.x = x; for (int y = start.y; y < end.y; ++y) { hashPosition.y = y; for (int z = start.z; z < end.z; ++z) { hashPosition.z = z; var hash = Hash(hashPosition); _buckets.Add(hash, itemID); } } } return(true); }
public static void ClampPosition(this Transform transform, Bounds bounds) { transform.position = bounds.Clamp(transform.position); }