Skip to content

Commit 452e6af

Browse files
committed
Refactor 4
1 parent cfdafe4 commit 452e6af

File tree

1 file changed

+57
-90
lines changed

1 file changed

+57
-90
lines changed

src/Files.App.Controls/Storage/RingShape/RingShape.cs

Lines changed: 57 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ private void UpdatePath()
7373
// If the ring is closed and complete
7474
if (EndAngle >= StartAngle + 360)
7575
{
76-
Data = DrawEllipse();
76+
Data = new()
77+
{
78+
Center = Center,
79+
RadiusX = IsCircle ? _equalRadius : RadiusWidth,
80+
RadiusY = IsCircle ? _equalRadius : RadiusHeight,
81+
};
7782
}
7883
else
7984
{
@@ -86,32 +91,6 @@ private void UpdatePath()
8691

8792
#region Drawing Updates
8893

89-
private EllipseGeometry DrawEllipse()
90-
{
91-
EllipseGeometry eg;
92-
93-
if (IsCircle)
94-
{
95-
eg = new()
96-
{
97-
Center = Center,
98-
RadiusX = _equalRadius,
99-
RadiusY = _equalRadius,
100-
};
101-
}
102-
else
103-
{
104-
eg = new()
105-
{
106-
Center = Center,
107-
RadiusX = _equalRadius,
108-
RadiusY = _equalRadius,
109-
};
110-
}
111-
112-
return eg;
113-
}
114-
11594
private PathGeometry DrawArc()
11695
{
11796
var newCenter = Center;
@@ -125,90 +104,78 @@ private PathGeometry DrawArc()
125104

126105
if (IsCircle)
127106
{
128-
ActualRadiusWidth = _equalRadius;
129-
ActualRadiusHeight = _equalRadius;
130-
131-
// Start Point
132-
pathFigure.StartPoint = ArcStartPoint();
133-
134-
// Arc Segment and End Point
135-
arcSegment = CreateArcSegment();
107+
pathFigure.StartPoint = ArcStartPoint(_equalRadius, _equalRadius);
108+
arcSegment = CreateArcSegment(_equalRadius, _equalRadius);
136109
}
137110
else
138111
{
139-
ActualRadiusWidth = RadiusWidth;
140-
ActualRadiusHeight = RadiusHeight;
141-
142-
// Start Point
143-
pathFigure.StartPoint = ArcStartPoint();
144-
145-
// Arc Segment and End Point
146-
arcSegment = CreateArcSegment();
112+
pathFigure.StartPoint = ArcStartPoint(RadiusWidth, RadiusHeight);
113+
arcSegment = CreateArcSegment(RadiusWidth, RadiusHeight);
147114
}
148115

149116
pathFigure.Segments.Add(arcSegment);
150117
pathGeometry.Figures.Add(pathFigure);
151118

152119
return pathGeometry;
153-
}
154120

155-
private Point ArcStartPoint()
156-
{
157-
return SweepDirection is SweepDirection.Counterclockwise
158-
? new(
159-
Center.X - Math.Sin(StartAngle * DegreesToRadians ) * RadiusWidth,
160-
Center.Y - Math.Cos(StartAngle * DegreesToRadians ) * RadiusHeight)
161-
: new(
162-
Center.X + Math.Sin(StartAngle * DegreesToRadians) * RadiusWidth,
163-
Center.Y - Math.Cos(StartAngle * DegreesToRadians) * RadiusHeight);
164-
}
165-
166-
private ArcSegment CreateArcSegment()
167-
{
168-
var finalArcSegment = new ArcSegment();
169-
170-
if (SweepDirection is SweepDirection.Counterclockwise)
121+
Point ArcStartPoint(double radius, double radius)
171122
{
172-
finalArcSegment.Point =
173-
new(
174-
Center.X - Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
175-
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);
176-
177-
if (EndAngle < StartAngle)
178-
{
179-
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
180-
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
181-
}
182-
else
183-
{
184-
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
185-
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
186-
}
123+
return SweepDirection is SweepDirection.Counterclockwise
124+
? new(
125+
Center.X - Math.Sin(StartAngle * DegreesToRadians ) * RadiusWidth,
126+
Center.Y - Math.Cos(StartAngle * DegreesToRadians ) * RadiusHeight)
127+
: new(
128+
Center.X + Math.Sin(StartAngle * DegreesToRadians) * RadiusWidth,
129+
Center.Y - Math.Cos(StartAngle * DegreesToRadians) * RadiusHeight);
187130
}
188-
else
189-
{
190-
finalArcSegment.Point =
191-
new(
192-
Center.X + Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
193-
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);
194131

195-
//ArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
132+
ArcSegment CreateArcSegment(double radius, double radius)
133+
{
134+
var finalArcSegment = new ArcSegment();
196135

197-
if (EndAngle < StartAngle)
136+
if (SweepDirection is SweepDirection.Counterclockwise)
198137
{
199-
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
200-
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
138+
finalArcSegment.Point =
139+
new(
140+
Center.X - Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
141+
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);
142+
143+
if (EndAngle < StartAngle)
144+
{
145+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
146+
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
147+
}
148+
else
149+
{
150+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
151+
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
152+
}
201153
}
202154
else
203155
{
204-
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
205-
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
156+
finalArcSegment.Point =
157+
new(
158+
Center.X + Math.Sin(EndAngle * DegreesToRadians) * RadiusWidth,
159+
Center.Y - Math.Cos(EndAngle * DegreesToRadians) * RadiusHeight);
160+
161+
//ArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
162+
163+
if (EndAngle < StartAngle)
164+
{
165+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) <= -180.0;
166+
finalArcSegment.SweepDirection = SweepDirection.Counterclockwise;
167+
}
168+
else
169+
{
170+
finalArcSegment.IsLargeArc = (EndAngle - StartAngle) >= 180.0;
171+
finalArcSegment.SweepDirection = SweepDirection.Clockwise;
172+
}
206173
}
207-
}
208174

209-
finalArcSegment.Size = new(RadiusWidth, RadiusHeight);
175+
finalArcSegment.Size = new(RadiusWidth, RadiusHeight);
210176

211-
return finalArcSegment;
177+
return finalArcSegment;
178+
}
212179
}
213180

214181
#endregion

0 commit comments

Comments
 (0)