public void CTOR_PointsCalculated() { var s = new bool[2, 2]; s[0, 0] = true; s[1, 1] = true; var shape = new InventoryShape(s); Assert.That(shape.Points.Count, Is.EqualTo(2)); Assert.That(shape.Contains(Vector2Int.zero), Is.True); Assert.That(shape.Contains(Vector2Int.one), Is.True); }
public void Position_PointsCalculated() { var s = new bool[2, 2]; s[0, 0] = true; s[1, 1] = true; var shape = new InventoryShape(s); shape.Position = new Vector2Int(6, 9); Assert.That(shape.Points.Count, Is.EqualTo(2)); Assert.That(shape.Contains(new Vector2Int(6, 9)), Is.True); Assert.That(shape.Contains(new Vector2Int(7, 10)), Is.True); }
/// <summary> /// Returns true of this item overlaps the given item /// </summary> /// <param name="otherShape">Other shape to check</param> public bool Overlaps(InventoryShape otherShape) { if (Rect.Overlaps(otherShape.Rect)) // Check rect first since its faster { // Check point by point to account for shape for (int i = 0; i < Points.Length; i++) { if (otherShape.Contains(Points[i])) { return(true); // Items overlap } } } return(false); // Items does not overlap }