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

DomCR / ACadSharp / 17710069422

14 Sep 2025 10:41AM UTC coverage: 78.147% (-0.1%) from 78.245%
17710069422

Pull #787

github

web-flow
Merge 57c93f01a into 2bca657be
Pull Request #787: Shape shx

6682 of 9285 branches covered (71.97%)

Branch coverage included in aggregate %.

139 of 201 new or added lines in 6 files covered. (69.15%)

8 existing lines in 2 files now uncovered.

25824 of 32311 relevant lines covered (79.92%)

107954.76 hits per line

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

56.98
/src/ACadSharp/IO/ShapeFile.ShapeBuilder.cs
1
using CSMath;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5

6
namespace ACadSharp.IO
7
{
8
        public partial class ShapeFile
9
        {
10
                internal class ShapeBuilder
11
                {
12
                        public List<XY> CurrentLine
13
                        {
14
                                get
15
                                {
2✔
16
                                        if (this.Polylines.Count == 0)
2!
NEW
17
                                        {
×
NEW
18
                                                this.Polylines.Add(new List<XY>());
×
NEW
19
                                        }
×
20

21
                                        return this.Polylines.Last();
2✔
22
                                }
2✔
23
                        }
24

25
                        public XY LastPt { get; set; }
12✔
26

27
                        public bool NotStore { get; set; }
34✔
28

29
                        public List<List<XY>> Polylines { get; } = new();
6✔
30

31
                        internal bool DrawModeOn
32
                        {
33
                                get
NEW
34
                                {
×
NEW
35
                                        return this._drawModeOn;
×
NEW
36
                                }
×
37
                                set
38
                                {
4✔
39
                                        this._drawModeOn = value;
4✔
40
                                        this._isLine = false;
4✔
41
                                }
4✔
42
                        }
43

NEW
44
                        private static readonly XY[] _vectors =
×
NEW
45
                        {
×
NEW
46
                                new XY(1.0, 0.0),
×
NEW
47
                                new XY(1.0, 0.5),
×
NEW
48
                                new XY(1.0, 1.0),
×
NEW
49
                                new XY(0.5, 1.0),
×
NEW
50
                                new XY(0.0, 1.0),
×
NEW
51
                                new XY(-0.5, 1.0),
×
NEW
52
                                new XY(-1.0, 1.0),
×
NEW
53
                                new XY(-1.0, 0.5),
×
NEW
54
                                new XY(-1.0, 0.0),
×
NEW
55
                                new XY(-1.0, -0.5),
×
NEW
56
                                new XY(-1.0, -1.0),
×
NEW
57
                                new XY(-0.5, -1.0),
×
NEW
58
                                new XY(0.0, -1.0),
×
NEW
59
                                new XY(0.5, -1.0),
×
NEW
60
                                new XY(1.0, -1.0),
×
NEW
61
                                new XY(1.0, -0.5)
×
NEW
62
                        };
×
63

64
                        private readonly Stack<XY> _locationStack = new();
1✔
65

66
                        private double _current = 1.0d;
1✔
67

68
                        private bool _drawModeOn = true;
1✔
69

70
                        private bool _isLine = false;
1✔
71

72
                        public ShapeBuilder()
1✔
73
                        {
1✔
74
                        }
1✔
75

76
                        public bool HasToStore()
77
                        {
17✔
78
                                bool result = !this.NotStore;
17✔
79
                                this.NotStore = false;
17✔
80

81
                                return result;
17✔
82
                        }
17✔
83

84
                        public int ProcessValue(int index, byte[] data)
85
                        {
18✔
86
                                byte code = data[index];
18✔
87
                                switch (code)
18!
88
                                {
89
                                        case 0x0:
90
                                                // End of shape definition
91
                                                return 1;
1✔
92
                                        case 0x1:
93
                                                // Activate Draw mode(pen down)
94
                                                if (this.HasToStore())
2✔
95
                                                {
2✔
96
                                                        this.DrawModeOn = true;
2✔
97
                                                }
2✔
98
                                                return 1;
2✔
99
                                        case 0x2:
100
                                                //Deactivate Draw mode (pen up)
101
                                                if (this.HasToStore())
2✔
102
                                                {
2✔
103
                                                        this.DrawModeOn = false;
2✔
104
                                                }
2✔
105
                                                return 1;
2✔
106
                                        case 0x3:
107
                                                if (this.HasToStore())
5✔
108
                                                {
5✔
109
                                                        //Divide vector lengths by next byte
110
                                                        double div = (sbyte)data[index + 1];
5✔
111
                                                        this._current /= div;
5✔
112
                                                }
5✔
113
                                                return 2;
5✔
114
                                        case 0x4:
115
                                                if (this.HasToStore())
5✔
116
                                                {
5✔
117
                                                        //Multiply vector lengths by next byte
118
                                                        double mult = (sbyte)data[index + 1];
5✔
119
                                                        this._current *= mult;
5✔
120
                                                }
5✔
121
                                                return 2;
5✔
122
                                        case 0x5:
NEW
123
                                                if (this.HasToStore())
×
NEW
124
                                                {
×
125
                                                        //Push current location onto stack
NEW
126
                                                        this._locationStack.Push(this.LastPt);
×
NEW
127
                                                }
×
NEW
128
                                                return 1;
×
129
                                        case 0x6:
NEW
130
                                                if (this.HasToStore())
×
NEW
131
                                                {
×
132
                                                        //Pop current location from stack
NEW
133
                                                        if (this._locationStack.Count > 0)
×
NEW
134
                                                        {
×
NEW
135
                                                                this.LastPt = this._locationStack.Pop();
×
NEW
136
                                                        }
×
137

NEW
138
                                                        this._isLine = false;
×
NEW
139
                                                }
×
NEW
140
                                                return 1;
×
141
                                        case 0x7:
142
                                                //Draw subshape number given by next byte
NEW
143
                                                throw new NotImplementedException();
×
144
                                        case 0x8:
NEW
145
                                                if (this.HasToStore())
×
NEW
146
                                                {
×
147
                                                        //X-Y displacement given by next two bytes
NEW
148
                                                        var x = (sbyte)data[index + 1];
×
NEW
149
                                                        var y = (sbyte)data[index + 2];
×
150

NEW
151
                                                        this.drawLine(x, y);
×
NEW
152
                                                }
×
NEW
153
                                                return 3;
×
154
                                        case 0x9:
155
                                                //Multiple X-Y displacements, terminated (0,0)
156
                                                bool flag = this.HasToStore();
3✔
157
                                                int i;
158
                                                for (i = index + 1; data[i] != 0 || data[i + 1] != 0; i += 2)
14✔
159
                                                {
4✔
160
                                                        if (flag)
4✔
161
                                                        {
4✔
162
                                                                this.drawLine((sbyte)data[i], (sbyte)data[i + 1]);
4✔
163
                                                        }
4✔
164
                                                }
4✔
165
                                                return i - index + 2;
3✔
166
                                        case 0xA:
167
                                        //Octant arc defined by next two bytes
168
                                        case 0xB:
169
                                        //Fractional arc defined by next five bytes
170
                                        case 0xC:
171
                                        //Arc defined by X-Y displacement and bulge
172
                                        case 0xD:
173
                                        //Multiple bulge-specified arcs
174
                                        case 0xE:
175
                                                //Process next command only if vertical text
NEW
176
                                                throw new NotImplementedException();
×
177
                                        default:
NEW
178
                                                byte b = data[index];
×
NEW
179
                                                double num2 = (b >> 4) & 0xF;
×
NEW
180
                                                XY vector2D = _vectors[b & 0xF];
×
NEW
181
                                                if (this.HasToStore())
×
NEW
182
                                                {
×
NEW
183
                                                        this.drawLine(num2 * vector2D.X, num2 * vector2D.Y);
×
NEW
184
                                                }
×
NEW
185
                                                return 1;
×
186
                                }
187
                        }
18✔
188

189
                        private void createNewLine()
190
                        {
2✔
191
                                if (!this._isLine)
2✔
192
                                {
1✔
193
                                        this._isLine = true;
1✔
194
                                        this.Polylines.Add(new List<XY>());
1✔
195
                                }
1✔
196
                        }
2✔
197

198
                        private void drawLine(double x, double y)
199
                        {
4✔
200
                                var point2D = new XY(
4✔
201
                                this.LastPt.X + this._current * x,
4✔
202
                                this.LastPt.Y + this._current * y);
4✔
203

204
                                if (this._drawModeOn)
4✔
205
                                {
2✔
206
                                        this.createNewLine();
2✔
207
                                        this.CurrentLine.Add(point2D);
2✔
208
                                }
2✔
209

210
                                this.LastPt = point2D;
4✔
211
                        }
4✔
212
                }
213
        }
214
}
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

© 2025 Coveralls, Inc