Skip to content

Commit bf865c3

Browse files
committed
Rotation #6
1 parent eeb75dd commit bf865c3

File tree

2 files changed

+3
-82
lines changed

2 files changed

+3
-82
lines changed

packages/box_transform/lib/src/resizers/freeform_resizing.dart

+2-11
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,6 @@ final class FreeformResizer extends Resizer {
120120
}
121121
}
122122

123-
if (rotation != 0) {
124-
// final Vector2 positionDelta = newRect.topLeft - initialRect.topLeft;
125-
// final Vector2 newPos = BoxTransformer.calculateUnrotatedPos(
126-
// initialRect,
127-
// rotation,
128-
// positionDelta,
129-
// newRect.size,
130-
// );
131-
// newRect = Box.fromLTWH(newPos.x, newPos.y, newRect.width, newRect.height);
132-
}
133-
134123
final Box effectiveBindingRect = switch (bindingStrategy) {
135124
BindingStrategy.originalBox => effectiveInitialRect,
136125
BindingStrategy.boundingBox => effectiveInitialBoundingRect,
@@ -150,6 +139,8 @@ final class FreeformResizer extends Resizer {
150139
return (rect: newRect, largest: area, hasValidFlip: isBound);
151140
}
152141

142+
/// Repositions a rotated and resized box back to its original unrotated
143+
/// position.
153144
Box repositionRotatedResizedBox({
154145
required Box newRect,
155146
required Box initialRect,

packages/box_transform/lib/src/transformer.dart

+1-71
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:developer';
21
import 'dart:math' hide log;
32

43
import 'package:vector_math/vector_math.dart';
@@ -219,11 +218,10 @@ class BoxTransformer {
219218
BindingStrategy bindingStrategy = BindingStrategy.boundingBox,
220219
}) {
221220
if (handle == HandlePosition.none) {
222-
log('Using bottomRight handle instead of none.');
223221
handle = HandlePosition.bottomRight;
224222
}
225223

226-
final initialBoundingRect = calculateBoundingRect(
224+
final Box initialBoundingRect = calculateBoundingRect(
227225
rotation: rotation,
228226
unrotatedBox: initialRect,
229227
);
@@ -567,72 +565,4 @@ class BoxTransformer {
567565

568566
return explodedRect;
569567
}
570-
571-
static Constraints calculateBoundingConstraints(
572-
{required double rotation, required Constraints constraints}) {
573-
final double sinA = sin(rotation);
574-
final double cosA = cos(rotation);
575-
576-
final double maxWidth = constraints.maxWidth;
577-
final double maxHeight = constraints.maxHeight;
578-
final double minWidth = constraints.minWidth;
579-
final double minHeight = constraints.minHeight;
580-
581-
final double maxBoundingWidth = !maxWidth.isFinite
582-
? double.infinity
583-
: (maxWidth * cosA).abs() + (maxHeight * sinA).abs();
584-
final double maxBoundingHeight = !maxHeight.isFinite
585-
? double.infinity
586-
: (maxWidth * sinA).abs() + (maxHeight * cosA).abs();
587-
final double minBoundingWidth = !minWidth.isFinite
588-
? double.infinity
589-
: (minWidth * cosA).abs() + (minHeight * sinA).abs();
590-
final double minBoundingHeight = !minHeight.isFinite
591-
? double.infinity
592-
: (minWidth * sinA).abs() + (minHeight * cosA).abs();
593-
594-
return Constraints(
595-
minWidth: minBoundingWidth,
596-
minHeight: minBoundingHeight,
597-
maxWidth: maxBoundingWidth,
598-
maxHeight: maxBoundingHeight,
599-
);
600-
}
601-
602-
// static Dimension calculateBoundingSize({
603-
// required double rotation,
604-
// required Dimension unrotatedSize,
605-
// }) {
606-
// final double sinA = sin(rotation);
607-
// final double cosA = cos(rotation);
608-
//
609-
// final double width = unrotatedSize.width;
610-
// final double height = unrotatedSize.height;
611-
// final double boundingWidth = (width * cosA).abs() + (height * sinA).abs();
612-
// final double boundingHeight = (width * sinA).abs() + (height * cosA).abs();
613-
//
614-
// return Dimension(boundingWidth, boundingHeight);
615-
// }
616-
617-
// static Box calculateUnrotatedRect({
618-
// required Box boundingBox,
619-
// required double rotation,
620-
// required double aspectRatio,
621-
// }) {
622-
// final Vector2 center = boundingBox.center;
623-
//
624-
// final double width = boundingBox.width * cos(-rotation) +
625-
// boundingBox.height * sin(-rotation);
626-
//
627-
// // derive from aspect ratio.
628-
// final double height = width / aspectRatio;
629-
//
630-
// final Box unrotatedRect = Box.fromCenter(
631-
// center: center,
632-
// width: width,
633-
// height: height,
634-
// );
635-
//
636-
// return unrotatedRect;
637-
// }
638568
}

0 commit comments

Comments
 (0)