MandelUtil.cpp 810 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "MandelUtil.h"
  2. using mnd::MandelViewport;
  3. void MandelViewport::adjustAspectRatio(double nwidth, double nheight)
  4. {
  5. double otherRatio = nwidth / nheight;
  6. if (width < height * otherRatio)
  7. width = height * otherRatio;
  8. else if (height < width / otherRatio)
  9. height = width / otherRatio;
  10. }
  11. void MandelViewport::normalize(void)
  12. {
  13. if (width < 0) {
  14. x += width;
  15. width = -width;
  16. }
  17. if (height < 0) {
  18. y += height;
  19. height = -height;
  20. }
  21. }
  22. void MandelViewport::zoomCenter(float scale)
  23. {
  24. x += width * (1 - scale) / 2;
  25. y += height * (1 - scale) / 2;
  26. width *= scale;
  27. height *= scale;
  28. }
  29. MandelViewport MandelViewport::standardView(void)
  30. {
  31. return MandelViewport{
  32. -2.25,
  33. -1.5,
  34. 3,
  35. 3
  36. };
  37. }