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.

37 lines
1.0 KiB

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