[Suggest] Remove `Vector3Int(Vector3 v)` constructor and create static factroy methods.

In Release 2, Vector3Int has constructor that takes Vector3 argument.

I suggest remove the Vector3Int(Vector3 v) constructor and create static factroy methods,

  • Vector3Int.FloorToInt(Vector3 v)

  • Vector3Int.RoundToInt(Vector3 v)

  • Vector3Int.CeilToInt(Vector3 v)

I’ll describe it.

Please check next test result.

   [Test]
    public void Vector3ConstructorTest()
    {
        Assert.AreEqual(
            new Vector3Int(0, 0, 0),
            new Vector3Int(new Vector3(0, 0, 0))
        );

        Assert.AreEqual(
            new Vector3Int(1, 2, -1),
            new Vector3Int(new Vector3(1.0F, 2.0F, -1.0F))
        );

        Assert.AreEqual(
            new Vector3Int(1, 2, -1),
            new Vector3Int(new Vector3(1.2F, 2.1F, -0.7F))
        );
    }

And next code is the Vector3Int constructor implementation (via MonoDevelop assembly browser).

        public Vector3Int (Vector3 v)
        {
            this.x = Mathf.FloorToInt (v.x);
            this.y = Mathf.FloorToInt (v.y);
            this.z = Mathf.FloorToInt (v.z);
        }

Vector3Int(Vector3 v) uses FloorToInt in its implementation.

I think that the Vector3Int(Vector3 v) is not good, because the constructor is ambiguous and easy to be misunderstood.

I think that
most users expect Vector3Int(Vector3 v) uses FloorToInt in the constructor implementation
but some users expect Vector3Int(Vector3 v) uses RoundToInt in the constructor implementation.
(Maybe, few users expect Vector3Int(Vector3 v) uses CeilToInt in the constructor implementation.)

So the Vector3Int(Vector3 v) behaviour is ambiguous and someone may make mistake with the behaviour.
(Of course, reference document will show Vector3Int(Vector3 v) behaviour exactly, but some users don’t read reference document.)
(I understand the current Vector3Int(Vector3 v) constructor is useful for TileMap. But…)

So, I suggest 2 issues.

  • remove Vector3Int(Vector3 v) constructor.

  • added static factory methods

  • Vector3Int.FloorToInt(Vector3 v)

  • Vector3Int.RoundToInt(Vector3 v)

  • Vector3Int.CeilToInt(Vector3 v)

The static factory methods behaviour are so clear from their names. Their implementation are like next code.

public static Vector3Int FloorToInt(Vector3 v)
{
    return new Vector3Int(
        Mathf.FloorToInt (v.x),
        Mathf.FloorToInt (v.y),
        Mathf.FloorToInt (v.z)
    );
}
public static Vector3Int RoundToInt(Vector3 v)
{
    return new Vector3Int(
        Mathf.RoundToInt (v.x),
        Mathf.RoundToInt (v.y),
        Mathf.RoundToInt (v.z)
    );
}
public static Vector3Int CeilToInt(Vector3 v)
{
    return new Vector3Int(
        Mathf.CeilToInt (v.x),
        Mathf.CeilToInt (v.y),
        Mathf.CeilToInt (v.z)
    );
}

And Vector2Int(Vector2 v) constructor is same.

  • remove Vector2Int(Vector2 v) constructor.

  • added static factory methods

  • Vector2Int.FloorToInt(Vector2 v)

  • Vector2Int.RoundToInt(Vector2 v)

  • Vector2Int.CeilToInt(Vector2 v)

This seems like a wise idea.

1 Like

In Release3, Vector3Int does not have constructor with Vector3 and Vector3Int has CeilToInt, FloorToInt and RoundToInt.

Unity 2D development team members! Thank you for your adopting my suggestion!!!

By the way, I think it is breaking change.But there are no description about it in Release Note for Release3.

How about add them.

  • Remove Vector3Int(Vector3) constructor
  • Remove Vector2Int(Vector2) constructor
  • Add Factory methods to create Vector3Int: Vector3Int.CeilToInt, Vector3Int.FloorToInt, Vector3Int.RoundToInt
  • Add Factory methods to create Vector2Int: Vector2Int.CeilToInt, Vector2Int.FloorToInt, Vector2Int.RoundToInt
1 Like

Agreed that it should be in the release notes: this was a breaking change for me. More inconvenient than the Tilemaps/TileMap syntax change, funnily enough!

agree