1
1

point.d 960 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 three.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. this(T[] data...) {
  14. this.data = data;
  15. }
  16. static if(D >= 1) {
  17. T x() @safe @property const {
  18. return data[0];
  19. }
  20. void x(T t) @safe @property {
  21. data[0] = t;
  22. }
  23. }
  24. static if(D >= 2) {
  25. T y() @safe @property const {
  26. return data[1];
  27. }
  28. void y(T t) @safe @property {
  29. data[1] = t;
  30. }
  31. }
  32. static if(D >= 3) {
  33. T z() @safe @property const {
  34. return data[2];
  35. }
  36. void z(T t) @safe @property {
  37. data[2] = t;
  38. }
  39. }
  40. }
  41. alias Vector2f = Vector!(2, float);
  42. alias Vector3f = Vector!(3, float);
  43. alias Point2f = Vector2f;
  44. alias Point3f = Vector3f;