point.d 916 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Written in the D programming language.
  2. /**
  3. Copyright: Copyright Felix 'Zoadian' Hufnagel 2014-.
  4. License: $(WEB http://www.gnu.org/licenses/lgpl.html, LGPLv3).
  5. Authors: $(WEB zoadian.de, Felix 'Zoadian' Hufnagel)
  6. */
  7. module aurora.primitives.point;
  8. import std.traits;
  9. struct Vector(size_t D, T) if(D > 0 && isNumeric!T) {
  10. public:
  11. T[D] data;
  12. alias data this;
  13. static if(D >= 1) {
  14. T x() @safe @property const {
  15. return data[0];
  16. }
  17. void x(T t) @safe @property {
  18. data[0] = t;
  19. }
  20. }
  21. static if(D >= 2) {
  22. T y() @safe @property const {
  23. return data[1];
  24. }
  25. void y(T t) @safe @property {
  26. data[1] = t;
  27. }
  28. }
  29. static if(D >= 3) {
  30. T z() @safe @property const {
  31. return data[2];
  32. }
  33. void z(T t) @safe @property {
  34. data[2] = t;
  35. }
  36. }
  37. }
  38. alias Vector2f = Vector!(2, float);
  39. alias Vector3f = Vector!(3, float);
  40. alias Point2f = Vector2f;
  41. alias Point3f = Vector3f;