Vector.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package me.hammerle.supersnuvi.math;
  2. public class Vector implements IVector
  3. {
  4. private float x = 0.0f;
  5. private float y = 0.0f;
  6. public Vector(float x, float y)
  7. {
  8. this.x = x;
  9. this.y = y;
  10. }
  11. public Vector()
  12. {
  13. this(0.0f, 0.0f);
  14. }
  15. public void setX(float x)
  16. {
  17. this.x = x;
  18. }
  19. public void setY(float y)
  20. {
  21. this.y = y;
  22. }
  23. public void set(float x, float y)
  24. {
  25. this.x = x;
  26. this.y = y;
  27. }
  28. public void set(Vector v)
  29. {
  30. set(v.x, v.y);
  31. }
  32. public void add(float x, float y)
  33. {
  34. this.x += x;
  35. this.y += y;
  36. }
  37. public void add(Vector v)
  38. {
  39. add(v.x, v.y);
  40. }
  41. public void sub(Vector v)
  42. {
  43. add(-v.x, -v.y);
  44. }
  45. public void addY(float y)
  46. {
  47. this.y += y;
  48. }
  49. public void addX(float x)
  50. {
  51. this.x += x;
  52. }
  53. public void mul(Vector v)
  54. {
  55. x *= v.x;
  56. y *= v.y;
  57. }
  58. public void mul(float fx, float fy)
  59. {
  60. x *= fx;
  61. y *= fy;
  62. }
  63. @Override
  64. public float getX()
  65. {
  66. return x;
  67. }
  68. @Override
  69. public float getY()
  70. {
  71. return y;
  72. }
  73. @Override
  74. public String toString()
  75. {
  76. return String.format("Vector(x = %f, y = %f)", x, y);
  77. }
  78. }