checkRotationLine method

dynamic checkRotationLine({
  1. required Layer activeLayer,
  2. required Size editorSize,
  3. required bool configEnabledHitVibration,
})

Checks the rotation line based on user interactions, adjusting rotation accordingly.

Implementation

checkRotationLine({
  required Layer activeLayer,
  required Size editorSize,
  required bool configEnabledHitVibration,
}) {
  double rotation = activeLayer.rotation - baseAngleFactor;
  double hitSpanX = hitSpan / 2;
  double deg = activeLayer.rotation * 180 / pi;
  double degChange = rotation * 180 / pi;
  double degHit = (snapStartRotation + degChange) % 45;

  bool hitAreaBelow = degHit <= hitSpanX;
  bool hitAreaAfter = degHit >= 45 - hitSpanX;
  bool hitArea = hitAreaBelow || hitAreaAfter;

  if ((!showRotationHelperLine &&
          ((degHit > 0 && degHit <= hitSpanX && snapLastRotation < deg) ||
              (degHit < 45 &&
                  degHit >= 45 - hitSpanX &&
                  snapLastRotation > deg))) ||
      (showRotationHelperLine && hitArea)) {
    if (rotationStartedHelper) {
      activeLayer.rotation =
          (deg - (degHit > 45 - hitSpanX ? degHit - 45 : degHit)) / 180 * pi;
      rotationHelperLineDeg = activeLayer.rotation;

      double posY = activeLayer.offset.dy;
      double posX = activeLayer.offset.dx;

      rotationHelperLineX = posX + editorSize.width / 2;
      rotationHelperLineY = posY + editorSize.height / 2;
      if (configEnabledHitVibration && !showRotationHelperLine) {
        _lineHitVibrate();
      }
      showRotationHelperLine = true;
    }
    snapLastRotation = deg;
  } else {
    showRotationHelperLine = false;
    rotationStartedHelper = true;
  }
}