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.

36 lines
1.0 KiB

  1. /**
  2. * Copyright 2013 Matthieu Moquet
  3. * Copyright 2016-2017 LasLabs Inc.
  4. * License MIT (https://opensource.org/licenses/MIT)
  5. **/
  6. (function() {
  7. 'use strict';
  8. Darkroom.Utils = {
  9. extend: extend,
  10. computeImageViewPort: computeImageViewPort,
  11. };
  12. // Utility method to easily extend objects.
  13. function extend(b, a) {
  14. var prop;
  15. if (b === undefined) {
  16. return a;
  17. }
  18. for (prop in a) {
  19. if (a.hasOwnProperty(prop) && b.hasOwnProperty(prop) === false) {
  20. b[prop] = a[prop];
  21. }
  22. }
  23. return b;
  24. }
  25. function computeImageViewPort(image) {
  26. return {
  27. height: Math.abs(image.getWidth() * (Math.sin(image.getAngle() * Math.PI/180))) + Math.abs(image.getHeight() * (Math.cos(image.getAngle() * Math.PI/180))),
  28. width: Math.abs(image.getHeight() * (Math.sin(image.getAngle() * Math.PI/180))) + Math.abs(image.getWidth() * (Math.cos(image.getAngle() * Math.PI/180))),
  29. };
  30. }
  31. })();