vector2.vala 732 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2012-2025 Daniele Bartolini et al.
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. namespace Crown
  6. {
  7. [Compact]
  8. public struct Vector2
  9. {
  10. public double x;
  11. public double y;
  12. public Vector2(double x, double y)
  13. {
  14. this.x = x;
  15. this.y = y;
  16. }
  17. public Vector2.from_array(Gee.ArrayList<Value?> arr)
  18. {
  19. this.x = (double)arr[0];
  20. this.y = (double)arr[1];
  21. }
  22. public Gee.ArrayList<Value?> to_array()
  23. {
  24. Gee.ArrayList<Value?> arr = new Gee.ArrayList<Value?>();
  25. arr.add(this.x);
  26. arr.add(this.y);
  27. return arr;
  28. }
  29. public string to_string()
  30. {
  31. return "%f, %f".printf(x, y);
  32. }
  33. }
  34. public const Vector2 VECTOR2_ZERO = { 0.0, 0.0 };
  35. public const Vector2 VECTOR2_ONE = { 1.0, 1.0 };
  36. } /* namespace Crown */