Skip to content

Commit 8cbcb25

Browse files
committed
Fixes #942 - Added ToDegrees() to handle angular string representation
- corrected default AngularZeroHandling - adjusted GetZeroHandlingFormat to actually use AngularDecimalPlaces - added/adjusted UnitTests
1 parent d476fba commit 8cbcb25

File tree

4 files changed

+88
-7
lines changed

4 files changed

+88
-7
lines changed

src/ACadSharp.Tests/Tables/DimensionStyleTests.cs

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ static DimensionStyleTests()
3131
},
3232
{
3333
new DimensionStyle {
34-
AngularUnit = AngularUnitFormat.Radians
34+
AngularUnit = AngularUnitFormat.Radians,
35+
AngularDecimalPlaces = 2
3536
},
3637
new DimensionAngular2Line{
3738
FirstPoint = XYZ.Zero,
@@ -51,11 +52,39 @@ static DimensionStyleTests()
5152
AngleVertex = XYZ.Zero,
5253
DefinitionPoint = new XYZ(0,10, 0),
5354
},
54-
"1.57"
55+
"90°"
5556
},
5657
{
5758
new DimensionStyle {
5859
AngularUnit = AngularUnitFormat.DecimalDegrees,
60+
AngularZeroHandling = ZeroHandling.SuppressDecimalLeadingZeroes,
61+
AngularDecimalPlaces = 2
62+
},
63+
new DimensionAngular2Line{
64+
FirstPoint = XYZ.Zero,
65+
SecondPoint = new XYZ(10, 0, 0),
66+
AngleVertex = XYZ.Zero,
67+
DefinitionPoint = new XYZ(0,10, 0),
68+
},
69+
"90.00°"
70+
},
71+
{
72+
new DimensionStyle {
73+
AngularUnit = AngularUnitFormat.Radians,
74+
AngularDecimalPlaces = 2
75+
},
76+
new DimensionAngular2Line{
77+
FirstPoint = XYZ.Zero,
78+
SecondPoint = new XYZ(10, 0, 0),
79+
AngleVertex = XYZ.Zero,
80+
DefinitionPoint = new XYZ(0,10, 0),
81+
},
82+
"1.57r"
83+
},
84+
{
85+
new DimensionStyle {
86+
AngularUnit = AngularUnitFormat.Radians,
87+
AngularDecimalPlaces = 2,
5988
DecimalSeparator = ','
6089
},
6190
new DimensionAngular2Line{
@@ -64,11 +93,26 @@ static DimensionStyleTests()
6493
AngleVertex = XYZ.Zero,
6594
DefinitionPoint = new XYZ(0,10, 0),
6695
},
67-
"1,57"
96+
"1,57r"
6897
},
6998
{
7099
new DimensionStyle {
71-
AngularUnit = AngularUnitFormat.Gradians
100+
AngularUnit = AngularUnitFormat.Gradians,
101+
AngularDecimalPlaces = 2
102+
},
103+
new DimensionAngular2Line{
104+
FirstPoint = XYZ.Zero,
105+
SecondPoint = new XYZ(10, 0, 0),
106+
AngleVertex = XYZ.Zero,
107+
DefinitionPoint = new XYZ(0,10, 0),
108+
},
109+
"100g"
110+
},
111+
{
112+
new DimensionStyle {
113+
AngularUnit = AngularUnitFormat.Gradians,
114+
AngularZeroHandling = ZeroHandling.SuppressDecimalLeadingZeroes,
115+
AngularDecimalPlaces = 2
72116
},
73117
new DimensionAngular2Line{
74118
FirstPoint = XYZ.Zero,
@@ -107,6 +151,14 @@ static DimensionStyleTests()
107151
new DimensionAligned(XYZ.Zero, new XYZ(10.5, 0, 0)),
108152
"10.5"
109153
},
154+
{
155+
new DimensionStyle {
156+
LinearUnitFormat = LinearUnitFormat.Decimal,
157+
Rounding = 1
158+
},
159+
new DimensionAligned(XYZ.Zero, new XYZ(10.1, 0, 0)),
160+
"10"
161+
},
110162
{
111163
new DimensionStyle {
112164
LinearUnitFormat = LinearUnitFormat.Decimal,
@@ -145,6 +197,15 @@ static DimensionStyleTests()
145197
new DimensionAligned(XYZ.Zero, new XYZ(10.25, 0, 0)),
146198
"1.03E+01"
147199
},
200+
{
201+
new DimensionStyle {
202+
LinearUnitFormat = LinearUnitFormat.Decimal,
203+
Prefix = "Pre",
204+
Suffix = "Suf"
205+
},
206+
new DimensionAligned(XYZ.Zero, new XYZ(10.5, 0, 0)),
207+
"Pre10.5Suf"
208+
},
148209
};
149210
}
150211

src/ACadSharp/Entities/Dimension.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ public string GetMeasurementText(DimensionStyle style)
348348
{
349349
switch (style.AngularUnit)
350350
{
351+
case AngularUnitFormat.DecimalDegrees:
352+
text = unitFormat.ToDegrees(value);
353+
break;
351354
case AngularUnitFormat.DegreesMinutesSeconds:
352355
text = unitFormat.ToDegreesMinutesSeconds(value);
353356
break;
@@ -357,7 +360,6 @@ public string GetMeasurementText(DimensionStyle style)
357360
case AngularUnitFormat.Radians:
358361
text = unitFormat.ToRadians(value);
359362
break;
360-
case AngularUnitFormat.DecimalDegrees:
361363
case AngularUnitFormat.SurveyorsUnits:
362364
default:
363365
text = unitFormat.ToDecimal(value, true);

src/ACadSharp/Tables/DimensionStyle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public class DimensionStyle : TableEntry
139139
/// (see DIMAZIN System Variable).
140140
/// </summary>
141141
[DxfCodeValue(79)]
142-
public ZeroHandling AngularZeroHandling { get; set; } = ZeroHandling.SuppressZeroFeetAndInches;
142+
public ZeroHandling AngularZeroHandling { get; set; } = ZeroHandling.SuppressDecimalLeadingAndTrailingZeroes;
143143

144144
/// <summary>
145145
/// Controls display of the arc symbol in an arc length dimension

src/ACadSharp/Types/Units/UnitStyleFormat.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,18 @@ public UnitStyleFormat()
232232
/// <returns></returns>
233233
public string GetZeroHandlingFormat(bool isAngular = false)
234234
{
235-
short decimalPlaces = this.LinearDecimalPlaces;
235+
short decimalPlaces;
236236
ZeroHandling handling;
237237

238238
if (isAngular)
239239
{
240240
handling = this.AngularZeroHandling;
241+
decimalPlaces = this.AngularDecimalPlaces;
241242
}
242243
else
243244
{
244245
handling = this.LinearZeroHandling;
246+
decimalPlaces = this.LinearDecimalPlaces;
245247
}
246248

247249
char leading = handling == ZeroHandling.SuppressDecimalLeadingZeroes
@@ -386,6 +388,22 @@ public string ToDecimal(double value, bool isAngular = false)
386388
return value.ToString(this.GetZeroHandlingFormat(isAngular), numberFormat);
387389
}
388390

391+
/// <summary>
392+
/// Converts an angle value in degrees string representation.
393+
/// </summary>
394+
/// <param name="angle">Angle value in radians.</param>
395+
/// <returns></returns>
396+
/// <exception cref="ArgumentNullException"></exception>
397+
public string ToDegrees(double angle)
398+
{
399+
double degrees = MathHelper.RadToDeg(angle);
400+
NumberFormatInfo numberFormat = new NumberFormatInfo
401+
{
402+
NumberDecimalSeparator = this.DecimalSeparator
403+
};
404+
return degrees.ToString(GetZeroHandlingFormat(isAngular: true), numberFormat) + this.DegreesSymbol;
405+
}
406+
389407
/// <summary>
390408
/// Converts an angle value in degrees into its degrees, minutes and seconds string representation.
391409
/// </summary>

0 commit comments

Comments
 (0)