Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4d97bd

Browse files
authored
Merge pull request ZEISS-PiWeb#29 from ZEISS-PiWeb/hotfix/CircleToStraightnessPosition
fix: simplified the conversion of circle segments to straightness to …
2 parents a054f37 + 349c22f commit b4d97bd

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

src/Formplot/FileFormat/FormplotConverter.cs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Zeiss.PiWeb.Formplot.FileFormat
1313
#region usings
1414

1515
using System;
16+
using System.Collections.Generic;
1617
using System.Linq;
1718

1819
#endregion
@@ -145,37 +146,24 @@ private static StraightnessPlot ConvertCircleToStraightness<TPoint, TGeometry>(
145146
result.Actual.CoordinateSystem = source.Actual.CoordinateSystem;
146147
result.Nominal.CoordinateSystem = source.Nominal.CoordinateSystem;
147148

148-
double? lastAngle = null;
149149
const double radToDeg = 180 / Math.PI;
150150

151151
foreach( var segment in source.Segments )
152152
{
153153
var resultSegment = new Segment<LinePoint, LineGeometry>( segment.Name, segment.SegmentType );
154+
var points = new List<LinePoint>( segment.Points.Count );
155+
154156
result.Segments.Add( resultSegment );
155157

156158
foreach( var point in segment.Points )
157159
{
158-
double position;
159-
if( !lastAngle.HasValue )
160-
{
161-
lastAngle = AdjustAngle( point.Angle * radToDeg );
162-
position = lastAngle.Value;
163-
}
164-
else
165-
{
166-
var angle = AdjustAngle( point.Angle * radToDeg );
167-
168-
while( angle < lastAngle )
169-
angle += 360;
170-
171-
lastAngle = angle;
172-
position = angle;
173-
}
174-
175-
var resultPoint = new LinePoint( position, point.Deviation );
160+
var resultPoint = new LinePoint( AdjustAngle( point.Angle * radToDeg ), point.Deviation );
176161
CopyDefaults( point, resultPoint );
177-
resultSegment.Points.Add( resultPoint );
162+
points.Add( resultPoint );
178163
}
164+
165+
foreach( var point in points.OrderBy( p => p.Position ) )
166+
resultSegment.Points.Add( point );
179167
}
180168

181169
return result;

0 commit comments

Comments
 (0)