• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Recached

DomCR / ACadSharp / 15854598527

24 Jun 2025 03:21PM UTC coverage: 75.356% (-0.1%) from 75.453%
15854598527

Pull #663

github

web-flow
Merge 96d566193 into 8a289c201
Pull Request #663: Dimension Text

5803 of 8457 branches covered (68.62%)

Branch coverage included in aggregate %.

96 of 167 new or added lines in 4 files covered. (57.49%)

9 existing lines in 1 file now uncovered.

23013 of 29783 relevant lines covered (77.27%)

82775.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ACadSharp/Extensions/UnitFormatExtensions.cs
1
using ACadSharp.Tables;
2
using System;
3

4
namespace ACadSharp.Extensions
5
{
6
        public class UnitFormatExtensions
7
        {
8
                public static string ToFractional(double value, FractionFormat fractionFormat, double linearDecimalPlaces, double fractionHeightScale)
NEW
9
                {
×
NEW
10
                        int num = (int)value;
×
NEW
11
                        getFraction(value, (short)Math.Pow(2, linearDecimalPlaces), out int numerator, out int denominator);
×
NEW
12
                        if (numerator == 0)
×
NEW
13
                        {
×
NEW
14
                                return string.Format("{0}", (int)value);
×
15
                        }
16

NEW
17
                        string text = string.Empty;
×
NEW
18
                        switch (fractionFormat)
×
19
                        {
20
                                case FractionFormat.Diagonal:
NEW
21
                                        text = $"\\A1;{num}{{\\H{fractionHeightScale}x;\\S{numerator}#{denominator};}}";
×
NEW
22
                                        break;
×
23
                                case FractionFormat.Horizontal:
NEW
24
                                        text = $"\\A1;{num}{{\\H{fractionHeightScale}x;\\S{numerator}/{denominator};}}";
×
NEW
25
                                        break;
×
26
                                case FractionFormat.None:
NEW
27
                                        text = num + " " + numerator + "/" + denominator;
×
NEW
28
                                        break;
×
29
                        }
30

NEW
31
                        return text;
×
NEW
32
                }
×
33

34
                private static void getFraction(double number, int precision, out int numerator, out int denominator)
NEW
35
                {
×
NEW
36
                        numerator = Convert.ToInt32((number - (int)number) * precision);
×
NEW
37
                        int commonFactor = getGCD(numerator, precision);
×
NEW
38
                        if (commonFactor <= 0)
×
NEW
39
                        {
×
NEW
40
                                commonFactor = 1;
×
NEW
41
                        }
×
NEW
42
                        numerator = numerator / commonFactor;
×
NEW
43
                        denominator = precision / commonFactor;
×
NEW
44
                }
×
45

46
                private static int getGCD(int number1, int number2)
NEW
47
                {
×
NEW
48
                        int a = number1;
×
NEW
49
                        int b = number2;
×
NEW
50
                        while (b != 0)
×
NEW
51
                        {
×
NEW
52
                                int count = a % b;
×
NEW
53
                                a = b;
×
NEW
54
                                b = count;
×
NEW
55
                        }
×
NEW
56
                        return a;
×
NEW
57
                }
×
58
        }
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc