You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.7 KiB

  1. #include <macros.h>
  2. #include <transform.h>
  3. TRANSFORM& TRANSFORM::operator=( const TRANSFORM& aTransform )
  4. {
  5. if( this == &aTransform ) // Check for self assingnemt;
  6. return *this;
  7. x1 = aTransform.x1;
  8. y1 = aTransform.y1;
  9. x2 = aTransform.x2;
  10. y2 = aTransform.y2;
  11. return *this;
  12. }
  13. bool TRANSFORM::operator==( const TRANSFORM& aTransform ) const
  14. {
  15. return ( x1 == aTransform.x1 &&
  16. y1 == aTransform.y1 &&
  17. x2 == aTransform.x2 &&
  18. y2 == aTransform.y2 );
  19. }
  20. wxPoint TRANSFORM::TransformCoordinate( const wxPoint& aPoint ) const
  21. {
  22. return wxPoint( ( x1 * aPoint.x ) + ( y1 * aPoint.y ),
  23. ( x2 * aPoint.x ) + ( y2 * aPoint.y ) );
  24. }
  25. /*
  26. * Calculate the Inverse mirror/rotation transform.
  27. */
  28. TRANSFORM TRANSFORM::InverseTransform( ) const
  29. {
  30. int invx1;
  31. int invx2;
  32. int invy1;
  33. int invy2;
  34. /* Calculates the inverse matrix coeffs:
  35. * for a matrix m{x1, x2, y1, y2}
  36. * the inverse matrix is 1/(x1*y2 -x2*y1) m{y2,-x2,-y1,x1)
  37. */
  38. int det = x1*y2 -x2*y1; // Is never null, because the inverse matrix exists
  39. invx1 = y2/det;
  40. invx2 = -x2/det;
  41. invy1 = -y1/det;
  42. invy2 = x1/det;
  43. TRANSFORM invtransform( invx1, invy1, invx2, invy2 );
  44. return invtransform;
  45. }
  46. bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const
  47. {
  48. wxCHECK_MSG( aAngle1 != NULL && aAngle2 != NULL, false,
  49. wxT( "Cannot map NULL point angles." ) );
  50. int Angle, Delta;
  51. double x, y, t;
  52. bool swap = false;
  53. Delta = *aAngle2 - *aAngle1;
  54. if( Delta >= 1800 )
  55. {
  56. *aAngle1 -= 1;
  57. *aAngle2 += 1;
  58. }
  59. x = cos( *aAngle1 * M_PI / 1800.0 );
  60. y = sin( *aAngle1 * M_PI / 1800.0 );
  61. t = x * x1 + y * y1;
  62. y = x * x2 + y * y2;
  63. x = t;
  64. *aAngle1 = (int) ( atan2( y, x ) * 1800.0 / M_PI + 0.5 );
  65. x = cos( *aAngle2 * M_PI / 1800.0 );
  66. y = sin( *aAngle2 * M_PI / 1800.0 );
  67. t = x * x1 + y * y1;
  68. y = x * x2 + y * y2;
  69. x = t;
  70. *aAngle2 = (int) ( atan2( y, x ) * 1800.0 / M_PI + 0.5 );
  71. NORMALIZE_ANGLE_POS( *aAngle1 );
  72. NORMALIZE_ANGLE_POS( *aAngle2 );
  73. if( *aAngle2 < *aAngle1 )
  74. *aAngle2 += 3600;
  75. if( *aAngle2 - *aAngle1 > 1800 ) /* Need to swap the two angles. */
  76. {
  77. Angle = (*aAngle1);
  78. *aAngle1 = (*aAngle2);
  79. *aAngle2 = Angle;
  80. NORMALIZE_ANGLE_POS( *aAngle1 );
  81. NORMALIZE_ANGLE_POS( *aAngle2 );
  82. if( *aAngle2 < *aAngle1 )
  83. *aAngle2 += 3600;
  84. swap = true;
  85. }
  86. if( Delta >= 1800 )
  87. {
  88. *aAngle1 += 1;
  89. *aAngle2 -= 1;
  90. }
  91. return swap;
  92. }