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)