gescl2d.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // DESCRIPTION:
  13. //
  14. // This file contains the class AcGeScale2d - a mathematical entity used
  15. // to represent scaling transformations in 2-space.
  16. // Contract: The scale vector components must never be set to zero
  17. // (or near zero within floating point tolerances).
  18. #ifndef AC_GESCL2D_H
  19. #define AC_GESCL2D_H
  20. #include "adesk.h"
  21. #include "gegbl.h"
  22. #pragma pack (push, 8)
  23. class AcGeMatrix2d;
  24. class AcGeScale3d;
  25. class
  26. GE_DLLEXPIMPORT
  27. AcGeScale2d
  28. {
  29. public:
  30. AcGeScale2d();
  31. AcGeScale2d(const AcGeScale2d& src);
  32. AcGeScale2d(double factor);
  33. AcGeScale2d(double xFactor, double yFactor);
  34. // The identity scaling operation.
  35. //
  36. static const AcGeScale2d kIdentity;
  37. // Multiplication.
  38. //
  39. AcGeScale2d operator * (const AcGeScale2d& sclVec) const;
  40. AcGeScale2d& operator *= (const AcGeScale2d& scl);
  41. AcGeScale2d& preMultBy (const AcGeScale2d& leftSide);
  42. AcGeScale2d& postMultBy (const AcGeScale2d& rightSide);
  43. AcGeScale2d& setToProduct(const AcGeScale2d& sclVec1, const AcGeScale2d& sclVec2);
  44. AcGeScale2d operator * (double s) const;
  45. AcGeScale2d& operator *= (double s);
  46. AcGeScale2d& setToProduct(const AcGeScale2d& sclVec, double s);
  47. friend
  48. GE_DLLEXPIMPORT
  49. AcGeScale2d operator * (double, const AcGeScale2d& scl);
  50. // Multiplicative inverse.
  51. //
  52. AcGeScale2d inverse () const;
  53. AcGeScale2d& invert ();
  54. Adesk::Boolean isProportional(const AcGeTol& tol = AcGeContext::gTol) const;
  55. // Tests for equivalence using the infinity norm.
  56. //
  57. bool operator == (const AcGeScale2d& sclVec) const;
  58. bool operator != (const AcGeScale2d& sclVec) const;
  59. bool isEqualTo (const AcGeScale2d& scaleVec,
  60. const AcGeTol& tol = AcGeContext::gTol) const;
  61. // For convenient access to the data.
  62. //
  63. double operator [] (unsigned int i) const;
  64. double& operator [] (unsigned int i);
  65. AcGeScale2d& set (double sc0, double sc1);
  66. // Conversion to/from matrix form.
  67. //
  68. operator AcGeMatrix2d () const;
  69. void getMatrix (AcGeMatrix2d& mat) const;
  70. AcGeScale2d& extractScale ( const AcGeMatrix2d& mat );
  71. AcGeScale2d& removeScale ( AcGeMatrix2d& mat );
  72. // Cast up to 3d scale.
  73. //
  74. operator AcGeScale3d () const;
  75. // The scale components in x and y.
  76. //
  77. double sx, sy;
  78. };
  79. inline double
  80. AcGeScale2d::operator [] (unsigned int i) const
  81. {
  82. return *(&sx+i);
  83. }
  84. inline double&
  85. AcGeScale2d::operator [] (unsigned int i)
  86. {
  87. return *(&sx+i);
  88. }
  89. inline bool
  90. AcGeScale2d::operator == (const AcGeScale2d& s) const
  91. {
  92. return this->isEqualTo(s);
  93. }
  94. // This operator is the logical negation of the `==' operator.
  95. //
  96. inline bool
  97. AcGeScale2d::operator != (const AcGeScale2d& s) const
  98. {
  99. return !this->isEqualTo(s);
  100. }
  101. #pragma pack (pop)
  102. #endif