How to use the transformation-matrix.rotateDEG function in transformation-matrix

To help you get started, we’ve selected a few transformation-matrix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jeremyckahn / merkaba / src / utils.js View on Github external
export const computeMidDragMatrix = function() {
  const {
    rotate,
    originX,
    originY,
    scaleX,
    scaleY,
    transformX,
    transformY,
  } = computeMidDragTransform(...arguments);

  return Matrix.from(
    transform([
      rotateDEG(rotate, originX, originY),
      translate(transformX, transformY),
      scale(scaleX, scaleY),
      translate(-transformX, -transformY),
    ])
  );
};
/* eslint-enable jsdoc/check-param-names */
github jeremyckahn / merkaba / src / components / merkaba.js View on Github external
const oldCenter = {
      x: x + width / 2,
      y: y + height / 2,
    };

    const newCenter = this.getMidDragMatrix().applyToPoint(
      oldCenter.x,
      oldCenter.y
    );

    // Logic taken from
    // https://github.com/SVG-Edit/svgedit/blob/396cce40ebfde03f7245c682041f63f07f69e3d3/editor/recalculate.js#L790-L800
    return Matrix.from(
      transform(
        inverse(rotateDEG(rotate, newCenter.x, newCenter.y)),
        rotateDEG(rotate, oldCenter.x, oldCenter.y),
        this.getMidDragMatrix({
          rotationOffset: -rotate,
        })
      )
    );
  }
github image-js / mrz-detection / src / getMrz.js View on Github external
function getRotationAround(image, angle) {
  const middle = { x: image.width / 2, y: image.height / 2 };
  return transform(
    translate(middle.x, middle.y),
    rotateDEG(angle),
    translate(-middle.x, -middle.y)
  );
}
github image-js / mrz-detection / src / getMrz.js View on Github external
distinctColor: true,
      alpha: 50
    });
    images.painted = painted;
  }

  let toCrop = original;

  const mrzRoi = rois[0];
  let angle = mrzRoi.meta.angle;
  let regionTransform;
  if (Math.abs(angle) > 45) {
    if (angle < 0) {
      toCrop = toCrop.rotateRight();
      angle += 90;
      regionTransform = transform(translate(toCrop.width, 0), rotateDEG(90));
    } else {
      toCrop = toCrop.rotateLeft();
      angle -= 90;
      regionTransform = transform(translate(0, toCrop.height), rotateDEG(-90));
    }
  }
  let mrzCropOptions;
  if (Math.abs(angle) < 1) {
    mrzCropOptions = {
      x: mrzRoi.roi.minX * originalToTreatedRatio,
      y: mrzRoi.roi.minY * originalToTreatedRatio,
      width: (mrzRoi.roi.maxX - mrzRoi.roi.minX) * originalToTreatedRatio,
      height: (mrzRoi.roi.maxY - mrzRoi.roi.minY) * originalToTreatedRatio
    };
    if (regionTransform) {
      const rotated = applyToPoint(regionTransform, mrzCropOptions);
github jeremyckahn / merkaba / src / components / merkaba.js View on Github external
transformDragStartX: rawSelectionDragStartX,
      transformDragStartY: rawSelectionDragStartY,
      transformDragX: rawSelectionDragX,
      transformDragY: rawSelectionDragY,
    } = this.state;

    const { x: transformDragStartX, y: transformDragStartY } = applyToPoint(
      rotateDEG(rotationOffset),
      {
        x: rawSelectionDragStartX,
        y: rawSelectionDragStartY,
      }
    );

    const { x: transformDragX, y: transformDragY } = applyToPoint(
      rotateDEG(rotationOffset),
      {
        x: rawSelectionDragX || rawSelectionDragStartX,
        y: rawSelectionDragY || rawSelectionDragStartY,
      }
    );

    return computeMidDragMatrix(
      { x, y, width, height, rotate },
      draggedHandleOrientation,
      transformDragX - transformDragStartX,
      transformDragY - transformDragStartY
    );
  }
github image-js / mrz-detection / src / getMrz.js View on Github external
}

  let toCrop = original;

  const mrzRoi = rois[0];
  let angle = mrzRoi.meta.angle;
  let regionTransform;
  if (Math.abs(angle) > 45) {
    if (angle < 0) {
      toCrop = toCrop.rotateRight();
      angle += 90;
      regionTransform = transform(translate(toCrop.width, 0), rotateDEG(90));
    } else {
      toCrop = toCrop.rotateLeft();
      angle -= 90;
      regionTransform = transform(translate(0, toCrop.height), rotateDEG(-90));
    }
  }
  let mrzCropOptions;
  if (Math.abs(angle) < 1) {
    mrzCropOptions = {
      x: mrzRoi.roi.minX * originalToTreatedRatio,
      y: mrzRoi.roi.minY * originalToTreatedRatio,
      width: (mrzRoi.roi.maxX - mrzRoi.roi.minX) * originalToTreatedRatio,
      height: (mrzRoi.roi.maxY - mrzRoi.roi.minY) * originalToTreatedRatio
    };
    if (regionTransform) {
      const rotated = applyToPoint(regionTransform, mrzCropOptions);
      const tmp = mrzCropOptions.width;
      mrzCropOptions.width = mrzCropOptions.height;
      mrzCropOptions.height = tmp;
      mrzCropOptions.x = rotated.x;
github jeremyckahn / merkaba / src / components / merkaba.js View on Github external
getMidDragMatrix({ rotationOffset = 0 } = {}) {
    const [focusedShape] = this.getFocusedShapes();
    const { x, y, width, height } = focusedShape;
    const rotate = focusedShape.rotate + rotationOffset;
    const {
      draggedHandleOrientation,
      transformDragStartX: rawSelectionDragStartX,
      transformDragStartY: rawSelectionDragStartY,
      transformDragX: rawSelectionDragX,
      transformDragY: rawSelectionDragY,
    } = this.state;

    const { x: transformDragStartX, y: transformDragStartY } = applyToPoint(
      rotateDEG(rotationOffset),
      {
        x: rawSelectionDragStartX,
        y: rawSelectionDragStartY,
      }
    );

    const { x: transformDragX, y: transformDragY } = applyToPoint(
      rotateDEG(rotationOffset),
      {
        x: rawSelectionDragX || rawSelectionDragStartX,
        y: rawSelectionDragY || rawSelectionDragStartY,
      }
    );

    return computeMidDragMatrix(
      { x, y, width, height, rotate },