Vec3.cs 695 B

12345678910111213141516171819202122232425262728293031
  1. namespace Day24;
  2. public readonly record struct Vec3(long X, long Y, long Z)
  3. {
  4. public static Vec3 Zero { get; } = new Vec3(0, 0, 0);
  5. public static Vec3 FromSpan(Span<long> nums)
  6. {
  7. return new Vec3(nums[0], nums[1], nums[2]);
  8. }
  9. public Vec3 Add(Vec3 other)
  10. {
  11. return new Vec3(X + other.X, Y + other.Y, Z + other.Z);
  12. }
  13. public Vec3 Subtract(Vec3 other)
  14. {
  15. return new Vec3(X - other.X, Y - other.Y, Z - other.Z);
  16. }
  17. public Vec3 Multiply(long f)
  18. {
  19. return new Vec3(f * X, f * Y, f * Z);
  20. }
  21. public static explicit operator Vec(Vec3 v)
  22. {
  23. return new Vec(v.X, v.Y);
  24. }
  25. }