PointApi.hx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package h2d.impl;
  2. /**
  3. A base common API interface for the points to validate API parity between 3D and 2D classes.
  4. Intended for internal usage. Use `-D apicheck` compilation flag to enable parity validation.
  5. **/
  6. interface GenPointApi<Point,Unit> {
  7. /**
  8. Returns a copy of the Point/
  9. **/
  10. function clone() : Point;
  11. /**
  12. Copy the position data from a given Point `p` to this Point.
  13. **/
  14. function load( p : Point ) : Void;
  15. /**
  16. Returns a new Point with the sum of this Point and a given Point `p`.
  17. **/
  18. function add( p : Point ) : Point;
  19. /**
  20. Returns a new Point with the results of a subtraction of a given Point `p` from this Point.
  21. **/
  22. function sub( p : Point ) : Point;
  23. /**
  24. Returns a new Point with the position of this Point multiplied by scalar `v`.
  25. **/
  26. function multiply( v : Unit ) : Point;
  27. /**
  28. Multiplies position of this Point by scalar `v`.
  29. **/
  30. function scale( v : Unit ) : Void;
  31. /**
  32. Returns a squared length of the Point.
  33. **/
  34. function lengthSq() : Unit;
  35. /**
  36. Return the length of the Point.
  37. **/
  38. function length() : Float;
  39. /**
  40. Returns the distance between this Point and given Point `p`.
  41. **/
  42. function distance( p : Point ) : Float;
  43. /**
  44. Returns a squared distance between this Point and given Point `p`.
  45. **/
  46. function distanceSq( p : Point ) : Unit;
  47. /**
  48. Tests if this Point position equals to the position of an `other` Point.
  49. **/
  50. function equals( other : Point ) : Bool;
  51. /**
  52. Returns a dot product between this Point and given Point `p`.
  53. **/
  54. function dot( p : Point ) : Unit;
  55. /**
  56. Returns a human-readable string representation of the Point.
  57. **/
  58. function toString() : String;
  59. // function set(x=0., y=0., z=0.) : Void;
  60. // function cross( p : Point ) : Point (3D)
  61. // function cross( p : Point ) : Unit (2D)
  62. }
  63. /**
  64. A common API interface for the floating-point Points to validate API parity between 3D and 2D classes.
  65. Intended for internal usage. Use `-D apicheck` compilation flag to enable parity validation.
  66. **/
  67. interface PointApi<Point,M> extends GenPointApi<Point,Float> {
  68. /**
  69. Sets this Point position to a result of linear interpolation between Points `p1` and `p2` at the interpolant position `k`.
  70. **/
  71. function lerp( p1 : Point, p2 : Point, k : Float ) : Void;
  72. /**
  73. Normalizes the Point.
  74. **/
  75. function normalize() : Void;
  76. /**
  77. Returns a new Point with the normalized values of this Point.
  78. **/
  79. function normalized() : Point;
  80. /**
  81. Applies a given Matrix `m` transformation to this Point position.
  82. **/
  83. function transform( m : M ) : Void;
  84. /**
  85. Returns a new Point with a result of applying a Matrix `m` to this Point position.
  86. **/
  87. function transformed( m : M ) : Point;
  88. // function transform3x3( m : Matrix ) : Void (3D)
  89. // function transform2x2( m : Matrix ) : Void (2D)
  90. }
  91. /**
  92. A common API interface for the integer Points to validate API parity between 3D and 2D classes.
  93. Intended for internal usage. Use `-D apicheck` compilation flag to enable parity validation.
  94. **/
  95. interface IPointApi<Point> extends GenPointApi<Point,Int> {
  96. }