Vectors.pas 874 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. {$mode objfpc}
  2. unit vectors;
  3. interface
  4. uses
  5. BrowserConsole, JS;
  6. type
  7. TScalar = single;
  8. TScalarArray = array of TScalar;
  9. type
  10. TVec2 = class (TJSArray)
  11. private
  12. procedure SetX (newValue: TScalar);
  13. procedure SetY (newValue: TScalar);
  14. function GetX: TScalar;
  15. function GetY: TScalar;
  16. public
  17. constructor Create;
  18. property x: TScalar read GetX write SetX;
  19. property y: TScalar read GetY write SetY;
  20. end;
  21. implementation
  22. procedure TVec2.SetX (newValue: TScalar);
  23. begin
  24. //SetElements(0, newValue);
  25. Elements[0] := newValue;
  26. end;
  27. procedure TVec2.SetY (newValue: TScalar);
  28. begin
  29. Elements[1] := newValue;
  30. end;
  31. function TVec2.GetX: TScalar;
  32. begin
  33. result := TScalar(Elements[0]); // Illegal type conversion: "set" to "Double"
  34. end;
  35. function TVec2.GetY: TScalar;
  36. begin
  37. result := TScalar(Elements[1]);
  38. end;
  39. constructor TVec2.Create;
  40. begin
  41. end;
  42. end.