MandelUtil.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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::zoom(float scale, float xz, float yz)
  32. {
  33. mnd::Real scaleR = 1.0f - scale;
  34. this->x += width * scaleR * mnd::Real(xz);
  35. this->y += height * scaleR * mnd::Real(yz);
  36. width *= scale;
  37. height *= scale;
  38. }
  39. MandelViewport MandelViewport::standardView(void)
  40. {
  41. return MandelViewport{
  42. -2.25,
  43. -1.5,
  44. 3,
  45. 3
  46. };
  47. }
  48. MandelViewport MandelViewport::centerView(void)
  49. {
  50. return MandelViewport{
  51. -2,
  52. -2,
  53. 4,
  54. 4
  55. };
  56. }