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

DomCR / ACadSharp / 12804163838

16 Jan 2025 07:33AM UTC coverage: 75.876% (+0.1%) from 75.732%
12804163838

Pull #523

github

web-flow
Merge 0e0ca78e3 into 639b4e770
Pull Request #523: Issue 521 predefined patterns

5270 of 7670 branches covered (68.71%)

Branch coverage included in aggregate %.

96 of 104 new or added lines in 4 files covered. (92.31%)

5 existing lines in 3 files now uncovered.

21052 of 27021 relevant lines covered (77.91%)

39205.94 hits per line

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

87.5
/src/ACadSharp/Entities/HatchPattern.cs
1
using ACadSharp.Attributes;
2
using CSMath;
3
using CSUtilities.Extensions;
4
using System;
5
using System.Collections.Generic;
6
using System.Diagnostics;
7
using System.Globalization;
8
using System.IO;
9
using System.Linq;
10

11
namespace ACadSharp.Entities
12
{
13
        public partial class HatchPattern
14
        {
15
                public static HatchPattern Solid { get { return new HatchPattern("SOLID"); } }
2,679✔
16

17
                [DxfCodeValue(2)]
18
                public string Name { get; set; }
1,889✔
19

20
                /// <summary>
21
                /// Description for this pattern.
22
                /// </summary>
23
                /// <remarks>
24
                /// The description is not saved in dxf or dwg files, its only used in the .pat files.
25
                /// </remarks>
26
                public string Description { get; set; }
8✔
27

28
                [DxfCodeValue(DxfReferenceType.Count, 79)]
29
                public List<Line> Lines { get; set; } = new List<Line>();
6,755✔
30

31
                public HatchPattern(string name)
1,237✔
32
                {
1,237✔
33
                        this.Name = name;
1,237✔
34
                }
1,237✔
35

36
                public HatchPattern Clone()
37
                {
2✔
38
                        HatchPattern clone = (HatchPattern)this.MemberwiseClone();
2✔
39

40
                        clone.Lines = new List<Line>();
2✔
41
                        foreach (var item in this.Lines)
6!
42
                        {
×
43
                                clone.Lines.Add(item.Clone());
×
44
                        }
×
45

46
                        return clone;
2✔
47
                }
2✔
48

49
                public static IEnumerable<HatchPattern> LoadFrom(string path)
50
                {
5✔
51
                        List<HatchPattern> patterns = new List<HatchPattern>();
5✔
52
                        HatchPattern current = null;
5✔
53

54
                        var lines = File.ReadLines(path)
5✔
55
                                .Select(line => line.Trim())
880✔
56
                                .Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith(";"))
880✔
57
                                .ToQueue();
5✔
58

59
                        List<int> leadingIndices = lines.Select((line, i) => (line, i))
881✔
60
                                .Where(t => t.line.StartsWith("*"))
876✔
61
                                .Select(t => t.i)
8✔
62
                                .OrderBy(i => i).ToList();
13✔
63

64
                        leadingIndices.Add(lines.Count);
5✔
65

66
                        while (lines.TryDequeue(out string line))
881✔
67
                        {
876✔
68
                                if (line.StartsWith("*"))
876✔
69
                                {
8✔
70
                                        int index = line.IndexOf(',');
8✔
71
                                        string noPrefix = line.Remove(0, 1);
8✔
72
                                        current = new HatchPattern(noPrefix.Substring(0, index - 1));
8✔
73
                                        current.Description = new string(noPrefix.Skip(index).ToArray()).Trim();
8✔
74

75
                                        patterns.Add(current);
8✔
76
                                }
8✔
77
                                else
78
                                {
868✔
79
                                        string[] data = line.Split(',');
868✔
80
                                        Line l = new Line();
868✔
81
                                        l.Angle = MathHelper.DegToRad(double.Parse(data[0], CultureInfo.InvariantCulture));
868✔
82
                                        l.BasePoint = new XY(double.Parse(data[1], CultureInfo.InvariantCulture), double.Parse(data[2], CultureInfo.InvariantCulture));
868✔
83

84
                                        XY offset = new XY(double.Parse(data[3], CultureInfo.InvariantCulture), double.Parse(data[4], CultureInfo.InvariantCulture));
868✔
85
                                        double cos = Math.Cos(l.Angle);
868✔
86
                                        double sin = Math.Sin(l.Angle);
868✔
87
                                        l.Offset = new XY(offset.X * cos - offset.Y * sin, offset.X * sin + offset.Y * cos);
868✔
88

89
                                        IEnumerable<string> dashes = data.Skip(5);
868✔
90
                                        if (dashes.Any())
868✔
91
                                        {
868✔
92
                                                l.DashLengths.AddRange(dashes.Select(d => double.Parse(d, CultureInfo.InvariantCulture)));
2,604✔
93
                                        }
868✔
94
                                }
868✔
95
                        }
876✔
96

97
                        return patterns;
5✔
98
                }
5✔
99

100
                /// <inheritdoc/>
101
                public override string ToString()
NEW
102
                {
×
NEW
103
                        return $"{this.Name}";
×
NEW
104
                }
×
105
        }
106
}
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