refactor: moved rotate to separate method

pull/87/head
RuiAlonso 4 years ago
parent 1ddeebe8b4
commit a4f387edbb

@ -13,17 +13,14 @@ class ArcShape extends ChainShape {
required this.center, required this.center,
required this.arcRadius, required this.arcRadius,
required this.angle, required this.angle,
this.rotation = 0,
}) { }) {
final points = calculateArc( createChain(
calculateArc(
center: center, center: center,
radius: arcRadius, radius: arcRadius,
angle: angle, angle: angle,
).map((vector) => vector..rotate(rotation)).toList(); ),
if (rotation != 0) { );
points.map((vector) => vector..rotate(rotation)).toList();
}
createChain(points);
} }
/// The center of the arc. /// The center of the arc.
@ -38,19 +35,19 @@ class ArcShape extends ChainShape {
/// For example, two pi returns a complete circumference. /// For example, two pi returns a complete circumference.
final double angle; final double angle;
/// Angle in radians to rotate the arc around its [center]. /// Rotates the arc by a given [angle] in radians.
final double rotation; void rotate(double angle) {
vertices.map((vector) => vector..rotate(angle)).toList();
}
ArcShape copyWith({ ArcShape copyWith({
Vector2? center, Vector2? center,
double? arcRadius, double? arcRadius,
double? angle, double? angle,
double? rotation,
}) => }) =>
ArcShape( ArcShape(
center: center ?? this.center, center: center ?? this.center,
arcRadius: arcRadius ?? this.arcRadius, arcRadius: arcRadius ?? this.arcRadius,
angle: angle ?? this.angle, angle: angle ?? this.angle,
rotation: rotation ?? this.rotation,
); );
} }

@ -11,15 +11,8 @@ class BezierCurveShape extends ChainShape {
/// {@macro bezier_curve_shape} /// {@macro bezier_curve_shape}
BezierCurveShape({ BezierCurveShape({
required this.controlPoints, required this.controlPoints,
this.rotation = 0,
}) { }) {
final points = calculateBezierCurve(controlPoints: controlPoints) createChain(calculateBezierCurve(controlPoints: controlPoints));
.map((vector) => vector..rotate(rotation))
.toList();
if (rotation != 0) {
points.map((vector) => vector..rotate(rotation)).toList();
}
createChain(points);
} }
/// Specifies the control points of the curve. /// Specifies the control points of the curve.
@ -28,6 +21,8 @@ class BezierCurveShape extends ChainShape {
/// inner points between them set its final shape. /// inner points between them set its final shape.
final List<Vector2> controlPoints; final List<Vector2> controlPoints;
/// Which can be rotated by a given [rotation] in radians. /// Rotates the bezier curve by a given [angle] in radians.
final double rotation; void rotate(double angle) {
vertices.map((vector) => vector..rotate(angle)).toList();
}
} }

@ -13,17 +13,14 @@ class EllipseShape extends ChainShape {
required this.center, required this.center,
required this.majorRadius, required this.majorRadius,
required this.minorRadius, required this.minorRadius,
this.rotation = 0,
}) { }) {
final points = calculateEllipse( createChain(
calculateEllipse(
center: center, center: center,
majorRadius: majorRadius, majorRadius: majorRadius,
minorRadius: minorRadius, minorRadius: minorRadius,
),
); );
if (rotation != 0) {
points.map((vector) => vector..rotate(rotation)).toList();
}
createChain(points);
} }
/// The top left corner of the ellipse. /// The top left corner of the ellipse.
@ -38,19 +35,19 @@ class EllipseShape extends ChainShape {
/// Minor radius is specified by [minorRadius]. /// Minor radius is specified by [minorRadius].
final double minorRadius; final double minorRadius;
/// Which can be rotated by a given [rotation] in radians. /// Rotates the ellipse by a given [angle] in radians.
final double rotation; void rotate(double angle) {
vertices.map((vector) => vector..rotate(angle)).toList();
}
EllipseShape copyWith({ EllipseShape copyWith({
Vector2? center, Vector2? center,
double? majorRadius, double? majorRadius,
double? minorRadius, double? minorRadius,
double? rotation,
}) => }) =>
EllipseShape( EllipseShape(
center: center ?? this.center, center: center ?? this.center,
majorRadius: majorRadius ?? this.majorRadius, majorRadius: majorRadius ?? this.majorRadius,
minorRadius: minorRadius ?? this.minorRadius, minorRadius: minorRadius ?? this.minorRadius,
rotation: rotation ?? this.rotation,
); );
} }

Loading…
Cancel
Save