Skip to content

Commit 979811b

Browse files
committed
Using MathF to avoid unnecessary double <> float conversions.
1 parent cb346e7 commit 979811b

22 files changed

+387
-390
lines changed

src/System.Windows.Forms.DataVisualization/Annotation/ArrowAnnotation.cs

+27-27
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ private GraphicsPath GetArrowPath(
332332
// Calculate arrow length
333333
float deltaX = secondPoint.X - firstPoint.X;
334334
float deltaY = secondPoint.Y - firstPoint.Y;
335-
float arrowLength = (float)Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
335+
float arrowLength = MathF.Sqrt(deltaX * deltaX + deltaY * deltaY);
336336

337337
// Create unrotated graphics path for the arrow started at the annotation location
338338
// and going to the right for the length of the rotated arrow.
@@ -343,40 +343,40 @@ private GraphicsPath GetArrowPath(
343343
if (this.ArrowStyle == ArrowStyle.Simple)
344344
{
345345
points = [
346-
firstPoint,
347-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
348-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
349-
new PointF(firstPoint.X + arrowLength, firstPoint.Y - this.ArrowSize),
350-
new PointF(firstPoint.X + arrowLength, firstPoint.Y + this.ArrowSize),
351-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
352-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio) ];
346+
firstPoint,
347+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
348+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
349+
new PointF(firstPoint.X + arrowLength, firstPoint.Y - this.ArrowSize),
350+
new PointF(firstPoint.X + arrowLength, firstPoint.Y + this.ArrowSize),
351+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
352+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio) ];
353353
}
354354
else if (this.ArrowStyle == ArrowStyle.DoubleArrow)
355355
{
356356
points = [
357-
firstPoint,
358-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
359-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
360-
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
361-
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
362-
new PointF(firstPoint.X + arrowLength, firstPoint.Y),
363-
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio),
364-
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
365-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
366-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio) ];
357+
firstPoint,
358+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
359+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
360+
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
361+
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
362+
new PointF(firstPoint.X + arrowLength, firstPoint.Y),
363+
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio),
364+
new PointF(firstPoint.X + arrowLength - this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
365+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
366+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio) ];
367367
}
368368
else if (this.ArrowStyle == ArrowStyle.Tailed)
369369
{
370370
float tailRatio = 2.1f;
371371
points = [
372-
firstPoint,
373-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
374-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
375-
new PointF(firstPoint.X + arrowLength, firstPoint.Y - this.ArrowSize*tailRatio),
376-
new PointF(firstPoint.X + arrowLength - this.ArrowSize*tailRatio, firstPoint.Y),
377-
new PointF(firstPoint.X + arrowLength, firstPoint.Y + this.ArrowSize*tailRatio),
378-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
379-
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio) ];
372+
firstPoint,
373+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize*pointerRatio),
374+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y - this.ArrowSize),
375+
new PointF(firstPoint.X + arrowLength, firstPoint.Y - this.ArrowSize*tailRatio),
376+
new PointF(firstPoint.X + arrowLength - this.ArrowSize*tailRatio, firstPoint.Y),
377+
new PointF(firstPoint.X + arrowLength, firstPoint.Y + this.ArrowSize*tailRatio),
378+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize),
379+
new PointF(firstPoint.X + this.ArrowSize*pointerRatio, firstPoint.Y + this.ArrowSize*pointerRatio) ];
380380
}
381381
else
382382
{
@@ -387,7 +387,7 @@ private GraphicsPath GetArrowPath(
387387
path.CloseAllFigures();
388388

389389
// Calculate arrow angle
390-
float angle = (float)(Math.Atan(deltaY / deltaX) * 180f / Math.PI);
390+
float angle = MathF.Atan(deltaY / deltaX) * 180f / MathF.PI;
391391
if (deltaX < 0)
392392
{
393393
angle += 180f;

src/System.Windows.Forms.DataVisualization/ChartTypes/AreaChart.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,17 @@ protected override void DrawLine(
239239
// Calculate points position
240240
PointF point1 = points[pointIndex - 1];
241241
PointF point2 = points[pointIndex];
242-
point1.X = (float)Math.Round(point1.X);
243-
point1.Y = (float)Math.Round(point1.Y);
244-
point2.X = (float)Math.Round(point2.X);
245-
point2.Y = (float)Math.Round(point2.Y);
242+
point1.X = MathF.Round(point1.X);
243+
point1.Y = MathF.Round(point1.Y);
244+
point2.X = MathF.Round(point2.X);
245+
point2.Y = MathF.Round(point2.Y);
246246
if (axisPos == PointF.Empty)
247247
{
248248
axisPos.X = (float)VAxis.GetPosition(this.VAxis.Crossing);
249249
axisPos.Y = (float)VAxis.GetPosition(this.VAxis.Crossing);
250250
axisPos = graph.GetAbsolutePoint(axisPos);
251-
axisPos.X = (float)Math.Round(axisPos.X);
252-
axisPos.Y = (float)Math.Round(axisPos.Y);
251+
axisPos.X = MathF.Round(axisPos.X);
252+
axisPos.Y = MathF.Round(axisPos.Y);
253253
}
254254

255255
// Point properties

src/System.Windows.Forms.DataVisualization/ChartTypes/BarChart.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ private void ProcessChartType(
477477
{
478478
// The formula for position is based on a distance
479479
// from the grid line or nPoints position.
480-
xPosition = vAxis.GetPosition((double)pointIndex + 1) - width * numOfSeries / 2.0 + width / 2 + seriesIndx * width;
480+
xPosition = vAxis.GetPosition(pointIndex + 1) - width * numOfSeries / 2.0 + width / 2 + seriesIndx * width;
481481
}
482482
else if (sameInterval)
483483
{
@@ -2037,18 +2037,18 @@ private void DrawLabels3D(
20372037
// Adjust rotation point
20382038
rotationCenter = rotationCenterProjection[0].PointF;
20392039

2040-
// Adjust angle of the horisontal text
2040+
// Adjust angle of the horizontal text
20412041
if (angle == 0 || angle == 180)
20422042
{
20432043
// Convert coordinates to absolute
20442044
rotationCenterProjection[0].PointF = graph.GetAbsolutePoint(rotationCenterProjection[0].PointF);
20452045
rotationCenterProjection[1].PointF = graph.GetAbsolutePoint(rotationCenterProjection[1].PointF);
20462046

2047-
// Calcuate axis angle
2048-
float angleXAxis = (float)Math.Atan(
2047+
// Calculate axis angle
2048+
float angleXAxis = MathF.Atan(
20492049
(rotationCenterProjection[1].Y - rotationCenterProjection[0].Y) /
20502050
(rotationCenterProjection[1].X - rotationCenterProjection[0].X));
2051-
angleXAxis = (float)Math.Round(angleXAxis * 180f / (float)Math.PI);
2051+
angleXAxis = MathF.Round(angleXAxis * 180f / MathF.PI);
20522052
angle += (int)angleXAxis;
20532053
}
20542054

src/System.Windows.Forms.DataVisualization/ChartTypes/BoxPlotChart.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,13 @@ protected virtual void ProcessChartType(
353353

354354
low = vAxis.GetLinearPosition(low);
355355

356-
// Remeber pre-calculated point position
356+
// Remember pre-calculated point position
357357
point.positionRel = new PointF(xPosition, (float)Math.Min(high, low));
358358

359359
if (common.ProcessModePaint)
360360
{
361361

362-
// Check if chart is partialy in the data scaleView
362+
// Check if chart is partially in the data scaleView
363363
bool clipRegionSet = false;
364364
if (xValue == hAxis.ViewMinimum || xValue == hAxis.ViewMaximum)
365365
{
@@ -1132,7 +1132,7 @@ protected virtual void ProcessChartType3D(
11321132

11331133
low = vAxis.GetLinearPosition(low);
11341134

1135-
// Remeber pre-calculated point position
1135+
// Remember pre-calculated point position
11361136
point.positionRel = new PointF(xPosition, (float)Math.Min(high, low));
11371137

11381138
// 3D Transform coordinates
@@ -1149,7 +1149,7 @@ protected virtual void ProcessChartType3D(
11491149

11501150
if (common.ProcessModePaint)
11511151
{
1152-
// Check if chart is partialy in the data scaleView
1152+
// Check if chart is partially in the data scaleView
11531153
bool clipRegionSet = false;
11541154
if (xValue == hAxis.ViewMinimum || xValue == hAxis.ViewMaximum)
11551155
{

src/System.Windows.Forms.DataVisualization/ChartTypes/ErrorBarChart.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ protected virtual void ProcessChartType(
431431

432432
if (showSideBySide)
433433
{
434-
xPosition = (float)(hAxis.GetPosition(xValue) - sideBySideWidth * (double)numberOfLinkedSeries / 2.0 + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth);
434+
xPosition = (float)hAxis.GetPosition(xValue) - sideBySideWidth * numberOfLinkedSeries / 2f + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth;
435435
}
436436
else
437437
{
@@ -442,7 +442,7 @@ protected virtual void ProcessChartType(
442442
double yValue1 = vAxis.GetLogValue(point.YValues[2]);
443443
xValue = hAxis.GetLogValue(xValue);
444444

445-
// Check if chart is completly out of the data scaleView
445+
// Check if chart is completely out of the data scaleView
446446
if (xValue < hAxis.ViewMinimum ||
447447
xValue > hAxis.ViewMaximum ||
448448
(yValue0 < vAxis.ViewMinimum && yValue1 < vAxis.ViewMinimum) ||
@@ -513,13 +513,13 @@ protected virtual void ProcessChartType(
513513

514514
low = vAxis.GetLinearPosition(low);
515515

516-
// Remeber pre-calculated point position
516+
// Remember pre-calculated point position
517517
point.positionRel = new PointF(xPosition, (float)Math.Min(high, low));
518518

519519
if (common.ProcessModePaint)
520520
{
521521

522-
// Check if chart is partialy in the data scaleView
522+
// Check if chart is partially in the data scaleView
523523
bool clipRegionSet = false;
524524
if (xValue == hAxis.ViewMinimum || xValue == hAxis.ViewMaximum)
525525
{
@@ -584,11 +584,11 @@ protected virtual void ProcessChartType(
584584
if (indexedSeries)
585585
{
586586
xValue = index;
587-
xPosition = (float)(hAxis.GetPosition(index) - sideBySideWidth * (double)numberOfLinkedSeries / 2.0 + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth);
587+
xPosition = (float)hAxis.GetPosition(index) - sideBySideWidth * numberOfLinkedSeries / 2f + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth;
588588
}
589589
else if (showSideBySide)
590590
{
591-
xPosition = (float)(hAxis.GetPosition(xValue) - sideBySideWidth * (double)numberOfLinkedSeries / 2.0 + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth);
591+
xPosition = (float)hAxis.GetPosition(xValue) - sideBySideWidth * numberOfLinkedSeries / 2f + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth;
592592
}
593593
else
594594
{
@@ -599,7 +599,7 @@ protected virtual void ProcessChartType(
599599
double yValue1 = vAxis.GetLogValue(point.YValues[2]);
600600
xValue = hAxis.GetLogValue(xValue);
601601

602-
// Check if chart is completly out of the data scaleView
602+
// Check if chart is completely out of the data scaleView
603603
if (xValue < hAxis.ViewMinimum ||
604604
xValue > hAxis.ViewMaximum ||
605605
(yValue0 < vAxis.ViewMinimum && yValue1 < vAxis.ViewMinimum) ||
@@ -1177,11 +1177,11 @@ protected virtual void ProcessChartType3D(
11771177
if (indexedSeries)
11781178
{
11791179
xValue = index;
1180-
xPosition = (float)(hAxis.GetPosition(index) - sideBySideWidth * (double)numberOfLinkedSeries / 2.0 + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth);
1180+
xPosition = (float)hAxis.GetPosition(index) - sideBySideWidth * numberOfLinkedSeries / 2f + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth;
11811181
}
11821182
else if (showSideBySide)
11831183
{
1184-
xPosition = (float)(hAxis.GetPosition(xValue) - sideBySideWidth * (double)numberOfLinkedSeries / 2.0 + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth);
1184+
xPosition = (float)hAxis.GetPosition(xValue) - sideBySideWidth * numberOfLinkedSeries / 2f + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth;
11851185
}
11861186
else
11871187
{
@@ -1192,7 +1192,7 @@ protected virtual void ProcessChartType3D(
11921192
double yValue1 = vAxis.GetLogValue(point.YValues[2]);
11931193
xValue = hAxis.GetLogValue(xValue);
11941194

1195-
// Check if chart is completly out of the data scaleView
1195+
// Check if chart is completely out of the data scaleView
11961196
if (xValue < hAxis.ViewMinimum ||
11971197
xValue > hAxis.ViewMaximum ||
11981198
(yValue0 < vAxis.ViewMinimum && yValue1 < vAxis.ViewMinimum) ||
@@ -1262,7 +1262,7 @@ protected virtual void ProcessChartType3D(
12621262

12631263
low = vAxis.GetLinearPosition(low);
12641264

1265-
// Remeber pre-calculated point position
1265+
// Remember pre-calculated point position
12661266
point.positionRel = new PointF(xPosition, (float)Math.Min(high, low));
12671267

12681268
// 3D Transform coordinates
@@ -1276,7 +1276,7 @@ protected virtual void ProcessChartType3D(
12761276
if (common.ProcessModePaint)
12771277
{
12781278

1279-
// Check if chart is partialy in the data scaleView
1279+
// Check if chart is partially in the data scaleView
12801280
bool clipRegionSet = false;
12811281
if (xValue == hAxis.ViewMinimum || xValue == hAxis.ViewMaximum)
12821282
{
@@ -1352,11 +1352,11 @@ protected virtual void ProcessChartType3D(
13521352
if (indexedSeries)
13531353
{
13541354
xValue = index;
1355-
xPosition = (float)(hAxis.GetPosition(index) - sideBySideWidth * (double)numberOfLinkedSeries / 2.0 + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth);
1355+
xPosition = (float)hAxis.GetPosition(index) - sideBySideWidth * numberOfLinkedSeries / 2f + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth;
13561356
}
13571357
else if (showSideBySide)
13581358
{
1359-
xPosition = (float)(hAxis.GetPosition(xValue) - sideBySideWidth * (double)numberOfLinkedSeries / 2.0 + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth);
1359+
xPosition = (float)hAxis.GetPosition(xValue) - sideBySideWidth * numberOfLinkedSeries / 2f + sideBySideWidth / 2 + indexOfLinkedSeries * sideBySideWidth;
13601360
}
13611361
else
13621362
{
@@ -1368,7 +1368,7 @@ protected virtual void ProcessChartType3D(
13681368
double yValue1 = vAxis.GetLogValue(point.YValues[2]);
13691369
xValue = hAxis.GetLogValue(xValue);
13701370

1371-
// Check if chart is completly out of the data scaleView
1371+
// Check if chart is completely out of the data scaleView
13721372
if (xValue < hAxis.ViewMinimum ||
13731373
xValue > hAxis.ViewMaximum ||
13741374
(yValue0 < vAxis.ViewMinimum && yValue1 < vAxis.ViewMinimum) ||

src/System.Windows.Forms.DataVisualization/ChartTypes/FastPointChart.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ protected virtual void DrawMarker(
492492
case MarkerStyle.Cross:
493493
{
494494
// Calculate cross line width and size
495-
float crossLineWidth = (float)Math.Ceiling(markerSize / 4F);
495+
float crossLineWidth = MathF.Ceiling(markerSize / 4F);
496496
float crossSize = markerSize; // * (float)Math.Sin(45f/180f*Math.PI);
497497

498498
// Calculate cross coordinates

0 commit comments

Comments
 (0)