运算符重载
定义
public class Vector3i {
public val x as int;
public val y as int;
public val z as int;
public this(x as int, y as int, z as int) {
this.x = x;
this.y = y;
this.z = z;
}
public +(other as Vector3i) as Vector3i {
return new Vector3i(this.x + other.x, this.y + other.y, this.z + other.z);
}
public -(other as Vector3i) as Vector3i {
return new Vector3i(this.x - other.x, this.y - other.y, this.z - other.z);
}
public *(multiply as int) as Vector3i {
return new Vector3i(this.x * multiply, this.y * multiply, this.z * multiply);
}
public ~(other as Vector3i) as int {
return this.x * other.x + this.y * other.y + this.z * other.z;
}
public *(other as Vector3i) as Vector3i {
return new Vector3i(this.y * other.z - this.z * other.y, this.z * other.x - this.x * other.z, this.x * other.y - this.y * other.x);
}
public implicit as string {
return "Vector3i[" + this.x + ", " + this.y + ", " + this.z + "]";
}
}使用
自动类型转换
IndexGet 与 IndexSet
最后更新于