vector2.vala 728 B

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