MandelUtil.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "MandelUtil.h"
  2. using mnd::MandelViewport;
  3. using mnd::MandelInfo;
  4. void MandelViewport::adjustAspectRatio(double nwidth, double nheight)
  5. {
  6. double otherRatio = nwidth / nheight;
  7. if (width < height * otherRatio)
  8. width = height * otherRatio;
  9. else if (height < width / otherRatio)
  10. height = width / otherRatio;
  11. }
  12. void MandelViewport::normalize(void)
  13. {
  14. if (width < 0) {
  15. x += width;
  16. width = -width;
  17. }
  18. if (height < 0) {
  19. y += height;
  20. height = -height;
  21. }
  22. }
  23. void MandelViewport::zoomCenter(float scale)
  24. {
  25. /*x += width * (1 - scale) / 2;
  26. y += height * (1 - scale) / 2;
  27. width *= scale;
  28. height *= scale;*/
  29. zoom(scale, 0.5f, 0.5f);
  30. }
  31. void MandelViewport::zoomCenter(const mnd::Real& scale)
  32. {
  33. /*x += width * (1 - scale) / 2;
  34. y += height * (1 - scale) / 2;
  35. width *= scale;
  36. height *= scale;*/
  37. zoom(scale, mnd::Real(0.5), mnd::Real(0.5));
  38. }
  39. void MandelViewport::zoom(float scale, float xz, float yz)
  40. {
  41. mnd::Real scaleR = 1.0f - scale;
  42. this->x += width * scaleR * mnd::Real(xz);
  43. this->y += height * scaleR * mnd::Real(yz);
  44. width *= scale;
  45. height *= scale;
  46. }
  47. void MandelViewport::zoom(const mnd::Real& scale, const mnd::Real& xz, const mnd::Real& yz)
  48. {
  49. mnd::Real scaleR = 1.0f - scale;
  50. this->x += width * scaleR * mnd::Real(xz);
  51. this->y += height * scaleR * mnd::Real(yz);
  52. width *= scale;
  53. height *= scale;
  54. }
  55. MandelViewport MandelViewport::standardView(void)
  56. {
  57. return MandelViewport{
  58. -2.25,
  59. -1.5,
  60. 3,
  61. 3
  62. };
  63. }
  64. MandelViewport MandelViewport::centerView(void)
  65. {
  66. return MandelViewport{
  67. -2,
  68. -2,
  69. 4,
  70. 4
  71. };
  72. }