Vector.java 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 addY(float y)
  42. {
  43. this.y += y;
  44. }
  45. public void addX(float x)
  46. {
  47. this.x += x;
  48. }
  49. public void mul(Vector v)
  50. {
  51. x *= v.x;
  52. y *= v.y;
  53. }
  54. @Override
  55. public float getX()
  56. {
  57. return x;
  58. }
  59. @Override
  60. public float getY()
  61. {
  62. return y;
  63. }
  64. @Override
  65. public String toString()
  66. {
  67. return String.format("Vector(x = %f, y = %f)", x, y);
  68. }
  69. }