@mlightcad/data-model 1.5.3 → 1.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,14 @@
1
+ var __values = (this && this.__values) || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function () {
6
+ if (o && i >= o.length) o = void 0;
7
+ return { value: o && o[i++], done: !o };
8
+ }
9
+ };
10
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
+ };
1
12
  /**
2
13
  * Enumeration of object snap modes used in AutoCAD.
3
14
  *
@@ -49,4 +60,155 @@ export var AcDbOsnapMode;
49
60
  */
50
61
  AcDbOsnapMode[AcDbOsnapMode["Centroid"] = 11] = "Centroid";
51
62
  })(AcDbOsnapMode || (AcDbOsnapMode = {}));
63
+ /**
64
+ * Converts an array of {@link AcDbOsnapMode} values into a single integer bitmask.
65
+ *
66
+ * ⚠️ Important:
67
+ * {@link AcDbOsnapMode} values are **ordinal identifiers**, not bit flags.
68
+ * Each mode is mapped to a bit position using the rule:
69
+ *
70
+ * `bit = (mode - 1)`
71
+ *
72
+ * This allows multiple object snap modes to be stored efficiently
73
+ * in a single integer using bitwise operations.
74
+ *
75
+ * @param modes - Array of object snap modes to enable
76
+ * @returns Integer bitmask representing the enabled object snap modes
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * const mask = acDbOsnapModesToMask([
81
+ * AcDbOsnapMode.EndPoint,
82
+ * AcDbOsnapMode.MidPoint,
83
+ * AcDbOsnapMode.Perpendicular
84
+ * ])
85
+ * // mask === 131
86
+ * ```
87
+ */
88
+ export function acdbOsnapModesToMask(modes) {
89
+ var e_1, _a;
90
+ var mask = 0;
91
+ try {
92
+ for (var modes_1 = __values(modes), modes_1_1 = modes_1.next(); !modes_1_1.done; modes_1_1 = modes_1.next()) {
93
+ var mode = modes_1_1.value;
94
+ mask |= 1 << (mode - 1);
95
+ }
96
+ }
97
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
98
+ finally {
99
+ try {
100
+ if (modes_1_1 && !modes_1_1.done && (_a = modes_1.return)) _a.call(modes_1);
101
+ }
102
+ finally { if (e_1) throw e_1.error; }
103
+ }
104
+ return mask;
105
+ }
106
+ /**
107
+ * Converts an integer bitmask into an array of {@link AcDbOsnapMode} values.
108
+ *
109
+ * The function iterates over all {@link AcDbOsnapMode} enum values and
110
+ * checks whether the corresponding bit (computed as `1 << (mode - 1)`)
111
+ * is set in the provided mask.
112
+ *
113
+ * @param mask - Integer bitmask containing object snap mode flags
114
+ * @returns Array of enabled {@link AcDbOsnapMode} values
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const modes = acDbMaskToOsnapModes(131)
119
+ * // [
120
+ * // AcDbOsnapMode.EndPoint,
121
+ * // AcDbOsnapMode.MidPoint,
122
+ * // AcDbOsnapMode.Perpendicular
123
+ * // ]
124
+ * ```
125
+ */
126
+ export function acdbMaskToOsnapModes(mask) {
127
+ var e_2, _a;
128
+ var modes = [];
129
+ try {
130
+ for (var _b = __values(Object.values(AcDbOsnapMode)), _c = _b.next(); !_c.done; _c = _b.next()) {
131
+ var value = _c.value;
132
+ if (typeof value !== 'number')
133
+ continue;
134
+ var bit = 1 << (value - 1);
135
+ if ((mask & bit) !== 0) {
136
+ modes.push(value);
137
+ }
138
+ }
139
+ }
140
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
141
+ finally {
142
+ try {
143
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
144
+ }
145
+ finally { if (e_2) throw e_2.error; }
146
+ }
147
+ return modes;
148
+ }
149
+ /**
150
+ * Toggles a specific {@link AcDbOsnapMode} in an object snap bitmask.
151
+ *
152
+ * If the mode is currently enabled, it will be disabled.
153
+ * If the mode is disabled, it will be enabled.
154
+ *
155
+ * @param mask - Current object snap mode bitmask
156
+ * @param mode - Object snap mode to toggle
157
+ * @returns Updated bitmask with the specified mode toggled
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * mask = acdbToggleOsnapMode(mask, AcDbOsnapMode.MidPoint)
162
+ * ```
163
+ */
164
+ export function acdbToggleOsnapMode(mask, mode) {
165
+ return mask ^ (1 << (mode - 1));
166
+ }
167
+ /**
168
+ * Checks whether a specific {@link AcDbOsnapMode} is enabled in the bitmask.
169
+ *
170
+ * @param mask - Object snap mode bitmask
171
+ * @param mode - Object snap mode to test
172
+ * @returns `true` if the mode is enabled; otherwise `false`
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * if (acdbHasOsnapMode(mask, AcDbOsnapMode.EndPoint)) {
177
+ * // EndPoint snapping is enabled
178
+ * }
179
+ * ```
180
+ */
181
+ export function acdbHasOsnapMode(mask, mode) {
182
+ return (mask & (1 << (mode - 1))) !== 0;
183
+ }
184
+ /**
185
+ * Enables a specific {@link AcDbOsnapMode} in the object snap bitmask.
186
+ *
187
+ * @param mask - Current object snap mode bitmask
188
+ * @param mode - Object snap mode to enable
189
+ * @returns Updated bitmask with the mode enabled
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * mask = acdbEnableOsnapMode(mask, AcDbOsnapMode.Tangent)
194
+ * ```
195
+ */
196
+ export function acdbEnableOsnapMode(mask, mode) {
197
+ return mask | (1 << (mode - 1));
198
+ }
199
+ /**
200
+ * Disables a specific {@link AcDbOsnapMode} in the object snap bitmask.
201
+ *
202
+ * @param mask - Current object snap mode bitmask
203
+ * @param mode - Object snap mode to disable
204
+ * @returns Updated bitmask with the mode disabled
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * mask = acdbDisableOsnapMode(mask, AcDbOsnapMode.Nearest)
209
+ * ```
210
+ */
211
+ export function acdbDisableOsnapMode(mask, mode) {
212
+ return mask & ~(1 << (mode - 1));
213
+ }
52
214
  //# sourceMappingURL=AcDbOsnapMode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AcDbOsnapMode.js","sourceRoot":"","sources":["../../src/misc/AcDbOsnapMode.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,aA0CX;AA1CD,WAAY,aAAa;IACvB;;OAEG;IACH,yDAAY,CAAA;IACZ;;OAEG;IACH,yDAAY,CAAA;IACZ;;OAEG;IACH,qDAAU,CAAA;IACV;;OAEG;IACH,iDAAQ,CAAA;IACR;;;OAGG;IACH,yDAAY,CAAA;IACZ;;OAEG;IACH,2DAAa,CAAA;IACb;;OAEG;IACH,mEAAiB,CAAA;IACjB;;OAEG;IACH,uDAAW,CAAA;IACX;;OAEG;IACH,wDAAY,CAAA;IACZ;;OAEG;IACH,0DAAa,CAAA;AACf,CAAC,EA1CW,aAAa,KAAb,aAAa,QA0CxB"}
1
+ {"version":3,"file":"AcDbOsnapMode.js","sourceRoot":"","sources":["../../src/misc/AcDbOsnapMode.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;;;;GAMG;AACH,MAAM,CAAN,IAAY,aA0CX;AA1CD,WAAY,aAAa;IACvB;;OAEG;IACH,yDAAY,CAAA;IACZ;;OAEG;IACH,yDAAY,CAAA;IACZ;;OAEG;IACH,qDAAU,CAAA;IACV;;OAEG;IACH,iDAAQ,CAAA;IACR;;;OAGG;IACH,yDAAY,CAAA;IACZ;;OAEG;IACH,2DAAa,CAAA;IACb;;OAEG;IACH,mEAAiB,CAAA;IACjB;;OAEG;IACH,uDAAW,CAAA;IACX;;OAEG;IACH,wDAAY,CAAA;IACZ;;OAEG;IACH,0DAAa,CAAA;AACf,CAAC,EA1CW,aAAa,KAAb,aAAa,QA0CxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAsB;;IAEtB,IAAI,IAAI,GAAG,CAAC,CAAA;;QAEZ,KAAmB,IAAA,UAAA,SAAA,KAAK,CAAA,4BAAA,+CAAE,CAAC;YAAtB,IAAM,IAAI,kBAAA;YACb,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,GAA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IAEnB,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAA;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlightcad/data-model",
3
- "version": "1.5.3",
3
+ "version": "1.5.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {