LibAC-dart/lib/utils/Vector3.dart
2024-05-06 13:45:52 -07:00

165 lines
3 KiB
Dart

class Vector3d {
static final Vector3d ZERO = Vector3d(X: 0, Y: 0, Z: 0);
double X = 0.0;
double Y = 0.0;
double Z = 0.0;
Vector3d({this.X = 0.0, this.Y = 0.0, this.Z = 0.0});
@override
bool operator ==(Object otherz) {
if (otherz is Vector3d) {
Vector3d other = otherz;
return X == other.X && Y == other.Y && Z == other.Z;
}
return false;
}
Vector3d operator +(Vector3d other) {
Vector3d n = Clone();
n.X += other.X;
n.Y += other.Y;
n.Z += other.Z;
return n;
}
Vector3d operator -(Vector3d other) {
Vector3d n = Clone();
n.X -= other.X;
n.Y -= other.Y;
n.Z -= other.Z;
return n;
}
Vector3d operator *(Vector3d other) {
Vector3d n = Clone();
n.X *= other.X;
n.Y *= other.Y;
n.Z *= other.Z;
return n;
}
Vector3d operator /(Vector3d other) {
Vector3d n = Clone();
n.X /= other.X;
n.Y /= other.Y;
n.Z /= other.Z;
return n;
}
bool operator >(Vector3d other) {
return (X > other.X) || (Y > other.Y) || (X > other.Z);
}
bool operator <(Vector3d other) {
return (X < other.X) || (Y < other.Y) || (X < other.Z);
}
Vector3d Clone() {
return Vector3d(X: X, Y: Y, Z: Z);
}
@override
String toString() {
return "<$X, $Y, $Z>";
}
bool inside(Vector3d min, Vector3d max) {
if (min.X <= X && max.X >= X) {
if (min.Y <= Y && max.Y >= Y) {
if (min.Z <= Z && max.Z >= Z) {
return true;
}
}
}
return false;
}
}
class Vector3i {
static final Vector3i ZERO = Vector3i(X: 0, Y: 0, Z: 0);
int X = 0;
int Y = 0;
int Z = 0;
Vector3i({this.X = 0, this.Y = 0, this.Z = 0});
@override
bool operator ==(Object otherz) {
if (otherz is Vector3i) {
Vector3i other = otherz;
return X == other.X && Y == other.Y && Z == other.Z;
}
return false;
}
Vector3i operator +(Vector3i other) {
Vector3i n = Clone();
n.X += other.X;
n.Y += other.Y;
n.Z += other.Z;
return n;
}
Vector3i operator -(Vector3i other) {
Vector3i n = Clone();
n.X -= other.X;
n.Y -= other.Y;
n.Z -= other.Z;
return n;
}
Vector3i operator *(Vector3i other) {
Vector3i n = Clone();
n.X *= other.X;
n.Y *= other.Y;
n.Z *= other.Z;
return n;
}
Vector3i operator /(Vector3i other) {
Vector3i n = Clone();
n.X = (n.X / other.X).round();
n.Y = (n.Y / other.Y).round();
n.Z = (n.Z / other.Z).round();
return n;
}
bool operator >(Vector3i other) {
return (X > other.X) || (Y > other.Y) || (X > other.Z);
}
bool operator <(Vector3i other) {
return (X < other.X) || (Y < other.Y) || (X < other.Z);
}
Vector3i Clone() {
return Vector3i(X: X, Y: Y, Z: Z);
}
@override
String toString() {
return "<$X, $Y, $Z>";
}
bool inside(Vector3i min, Vector3i max) {
if (min.X <= X && max.X >= X) {
if (min.Y <= Y && max.Y >= Y) {
if (min.Z <= Z && max.Z >= Z) {
return true;
}
}
}
return false;
}
}