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

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

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

Loading…
Cancel
Save