utils.mjs 994 B

12345678910111213141516171819202122232425262728293031
  1. import { calcLength } from './delta-calc.mjs';
  2. function isAxisDeltaZero(delta) {
  3. return delta.translate === 0 && delta.scale === 1;
  4. }
  5. function isDeltaZero(delta) {
  6. return isAxisDeltaZero(delta.x) && isAxisDeltaZero(delta.y);
  7. }
  8. function axisEquals(a, b) {
  9. return a.min === b.min && a.max === b.max;
  10. }
  11. function boxEquals(a, b) {
  12. return axisEquals(a.x, b.x) && axisEquals(a.y, b.y);
  13. }
  14. function axisEqualsRounded(a, b) {
  15. return (Math.round(a.min) === Math.round(b.min) &&
  16. Math.round(a.max) === Math.round(b.max));
  17. }
  18. function boxEqualsRounded(a, b) {
  19. return axisEqualsRounded(a.x, b.x) && axisEqualsRounded(a.y, b.y);
  20. }
  21. function aspectRatio(box) {
  22. return calcLength(box.x) / calcLength(box.y);
  23. }
  24. function axisDeltaEquals(a, b) {
  25. return (a.translate === b.translate &&
  26. a.scale === b.scale &&
  27. a.originPoint === b.originPoint);
  28. }
  29. export { aspectRatio, axisDeltaEquals, axisEquals, axisEqualsRounded, boxEquals, boxEqualsRounded, isDeltaZero };