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

DomCR / ACadSharp / 12945074137

24 Jan 2025 07:18AM UTC coverage: 76.216% (+74.2%) from 2.0%
12945074137

Pull #523

github

web-flow
Merge c8486121e into 5c1c15065
Pull Request #523: Issue 521 predefined patterns

5311 of 7702 branches covered (68.96%)

Branch coverage included in aggregate %.

97 of 115 new or added lines in 4 files covered. (84.35%)

21235 of 27128 relevant lines covered (78.28%)

39696.57 hits per line

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

73.56
/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
using System.Text;
11

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

18
                [DxfCodeValue(2)]
19
                public string Name { get; set; }
2,097✔
20

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

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

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

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

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

47
                        return clone;
2✔
48
                }
2✔
49

50
                /// <inheritdoc/>
51
                public override string ToString()
NEW
52
                {
×
NEW
53
                        return $"{this.Name}";
×
NEW
54
                }
×
55

56
                /// <summary>
57
                /// Load a collection of patterns from a .pat file.
58
                /// </summary>
59
                /// <param name="path"></param>
60
                /// <returns></returns>
61
                public static IEnumerable<HatchPattern> LoadFrom(string path)
62
                {
10✔
63
                        List<HatchPattern> patterns = new List<HatchPattern>();
10✔
64
                        HatchPattern current = null;
10✔
65

66
                        var lines = File.ReadLines(path)
10✔
67
                                .Select(line => line.Trim())
1,760✔
68
                                .Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith(";"))
1,760✔
69
                                .ToQueue();
10✔
70

71
                        List<int> leadingIndices = lines.Select((line, i) => (line, i))
1,762✔
72
                                .Where(t => t.line.StartsWith("*"))
1,752✔
73
                                .Select(t => t.i)
16✔
74
                                .OrderBy(i => i).ToList();
26✔
75

76
                        leadingIndices.Add(lines.Count);
10✔
77

78
                        while (lines.TryDequeue(out string line))
1,762✔
79
                        {
1,752✔
80
                                if (line.StartsWith("*"))
1,752✔
81
                                {
16✔
82
                                        int index = line.IndexOf(',');
16✔
83
                                        string noPrefix = line.Remove(0, 1);
16✔
84
                                        current = new HatchPattern(noPrefix.Substring(0, index - 1));
16✔
85
                                        current.Description = new string(noPrefix.Skip(index).ToArray()).Trim();
16✔
86

87
                                        patterns.Add(current);
16✔
88
                                }
16✔
89
                                else
90
                                {
1,736✔
91
                                        string[] data = line.Split(',');
1,736✔
92
                                        Line l = new Line();
1,736✔
93
                                        l.Angle = MathHelper.DegToRad(double.Parse(data[0], CultureInfo.InvariantCulture));
1,736✔
94
                                        l.BasePoint = new XY(double.Parse(data[1], CultureInfo.InvariantCulture), double.Parse(data[2], CultureInfo.InvariantCulture));
1,736✔
95

96
                                        XY offset = new XY(double.Parse(data[3], CultureInfo.InvariantCulture), double.Parse(data[4], CultureInfo.InvariantCulture));
1,736✔
97
                                        double cos = Math.Cos(l.Angle);
1,736✔
98
                                        double sin = Math.Sin(l.Angle);
1,736✔
99
                                        l.Offset = new XY(offset.X * cos - offset.Y * sin, offset.X * sin + offset.Y * cos);
1,736✔
100

101
                                        IEnumerable<string> dashes = data.Skip(5);
1,736✔
102
                                        if (dashes.Any())
1,736✔
103
                                        {
1,736✔
104
                                                l.DashLengths.AddRange(dashes.Select(d => double.Parse(d, CultureInfo.InvariantCulture)));
5,208✔
105
                                        }
1,736✔
106

107
                                        current.Lines.Add(l);
1,736✔
108
                                }
1,736✔
109
                        }
1,752✔
110

111
                        return patterns;
10✔
112
                }
10✔
113

114
                /// <summary>
115
                /// 
116
                /// </summary>
117
                /// <param name="writer"></param>
118
                /// <param name="patterns"></param>
119
                public static void SavePatterns(TextWriter writer, params IEnumerable<HatchPattern> patterns)
NEW
120
                {
×
NEW
121
                        foreach (HatchPattern p in patterns)
×
NEW
122
                        {
×
NEW
123
                                writer.WriteLine("*", p.Name, p.Description);
×
124

NEW
125
                                foreach (Line l in p.Lines)
×
NEW
126
                                {
×
NEW
127
                                        StringBuilder sb = new StringBuilder();
×
128

129
                                        //sb.Append($"{}{}{}{}{}");
NEW
130
                                }
×
131

NEW
132
                        }
×
NEW
133
                }
×
134
        }
135
}
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