build-dxf 0.0.2 → 0.0.3

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.
package/README.md CHANGED
@@ -1 +1,16 @@
1
1
  # build-dxf
2
+
3
+ # 安装
4
+ ```
5
+ npm i build-dxf
6
+ ```
7
+
8
+ # 使用
9
+ ```typescript
10
+ import { DxfSystem } from "build-dxf"
11
+
12
+ const dxfSystem = new DxfSystem()
13
+ dxfSystem.Dxf.set(data)
14
+ dxfSystem.Dxf.lineOffset()
15
+ dxfSystem.Dxf.download("01.dxf")
16
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "build-dxf",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "线段构建双线墙壁的dxf版本",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
package/src/index.d.ts CHANGED
@@ -212,17 +212,17 @@ declare class Dxf extends Component<{
212
212
  /**
213
213
  * 将点云结构转换为string
214
214
  */
215
- toDxfString(): string;
215
+ toDxfString(unit?: Unit): string;
216
216
  /**
217
217
  * 将点云结构转换为DXF格式
218
218
  * @returns
219
219
  */
220
- toDxfBlob(): Blob;
220
+ toDxfBlob(unit?: Unit): Blob;
221
221
  /**
222
222
  * 下载
223
223
  * @param filename
224
224
  */
225
- download(filename: string, path?: string): Promise<void>;
225
+ download(filename: string, unit?: Unit): Promise<void>;
226
226
  /**
227
227
  * 计算原始数据的边界框
228
228
  * @description 计算所有线段的起点和终点的最小最大值,形成一个边界框
@@ -241,6 +241,10 @@ export declare class DxfSystem extends ComponentManager {
241
241
  Dxf: Dxf;
242
242
  Variable: Variable;
243
243
  wallWidth: number;
244
+ /** 构造函数
245
+ * @param wallWidth 输出墙壁厚度,该墙壁厚度不受缩放影响
246
+ * @param scale 原始数据缩放比例
247
+ */
244
248
  constructor(wallWidth?: number, scale?: number);
245
249
  usePlugin(plugin: (this: DxfSystem, dxfSystem: DxfSystem) => void): this;
246
250
  destroy(): void;
@@ -465,6 +469,8 @@ declare class Rectangle {
465
469
  static fromByLineSegment(line: LineSegment, width?: number, horizontal?: boolean, hScale?: number): Rectangle;
466
470
  }
467
471
 
472
+ declare type Unit = "Unitless" | "Inches" | "Feet" | "Miles" | "Millimeters" | "Centimeters" | "Meters" | "Kilometers" | "Microinches" | "Mils" | "Yards" | "Angstroms" | "Nanometers" | "Microns" | "Decimeters" | "Decameters" | "Hectometers" | "Gigameters" | "Astronomical units" | "Light years" | "Parsecs";
473
+
468
474
  declare class Variable extends Component<EventType> {
469
475
  originalLineVisible: boolean;
470
476
  dxfVisible: boolean;
package/src/index.js CHANGED
@@ -12956,6 +12956,50 @@ class Box2 {
12956
12956
  );
12957
12957
  }
12958
12958
  }
12959
+ const units = {
12960
+ Unitless: 1,
12961
+ // 无单位,1米 = 1(无单位)
12962
+ Inches: 39.37007874015748,
12963
+ // 英寸,1米 = 39.37007874015748英寸
12964
+ Feet: 3.280839895013123,
12965
+ // 英尺,1米 = 3.280839895013123英尺
12966
+ Miles: 6213711922373339e-19,
12967
+ // 英里,1米 = 0.0006213711922373339英里
12968
+ Millimeters: 1e3,
12969
+ // 毫米,1米 = 1000毫米
12970
+ Centimeters: 100,
12971
+ // 厘米,1米 = 100厘米
12972
+ Meters: 1,
12973
+ // 米,1米 = 1米
12974
+ Kilometers: 1e-3,
12975
+ // 千米,1米 = 0.001千米
12976
+ Microinches: 3937007874015748e-8,
12977
+ // 微英寸,1米 = 39370078.74015748微英寸
12978
+ Mils: 39370.07874015748,
12979
+ // 密耳,1米 = 39370.07874015748密耳
12980
+ Yards: 1.0936132983377078,
12981
+ // 码,1米 = 1.0936132983377078码
12982
+ Angstroms: 1e10,
12983
+ // 埃,1米 = 10^10埃
12984
+ Nanometers: 1e9,
12985
+ // 纳米,1米 = 10^9纳米
12986
+ Microns: 1e6,
12987
+ // 微米,1米 = 10^6微米
12988
+ Decimeters: 10,
12989
+ // 分米,1米 = 10分米
12990
+ Decameters: 0.1,
12991
+ // 十米,1米 = 0.1十米
12992
+ Hectometers: 0.01,
12993
+ // 百米,1米 = 0.01百米
12994
+ Gigameters: 1e-9,
12995
+ // 吉米,1米 = 10^-9吉米
12996
+ "Astronomical units": 6684587122268445e-27,
12997
+ // 天文单位,1米 = 0.000000000006684587122268445天文单位
12998
+ "Light years": 10570008340246154e-32,
12999
+ // 光年,1米 ≈ 0.00000000000000010570008340246154光年
13000
+ Parsecs: 3240779289666404e-32
13001
+ // 秒差距,1米 ≈ 0.00000000000000003240779289666404秒差距
13002
+ };
12959
13003
  class Dxf extends Component {
12960
13004
  width = 0.04;
12961
13005
  scale = 1;
@@ -13181,15 +13225,16 @@ class Dxf extends Component {
13181
13225
  /**
13182
13226
  * 将点云结构转换为string
13183
13227
  */
13184
- toDxfString() {
13228
+ toDxfString(unit = "Millimeters") {
13185
13229
  const d = new Drawing();
13186
13230
  d.setUnits("Millimeters");
13231
+ const s = units[unit];
13187
13232
  this.wallsGroup.forEach((points) => {
13188
13233
  for (let i = 0; i < points.length; i++) {
13189
13234
  const point1 = points[i];
13190
13235
  const nextIndex = i === points.length - 1 ? 0 : i + 1;
13191
13236
  const point2 = points[nextIndex];
13192
- d.drawLine(point1.X * 1e3, point1.Y * 1e3, point2.X * 1e3, point2.Y * 1e3);
13237
+ d.drawLine(point1.X * s, point1.Y * s, point2.X * s, point2.Y * s);
13193
13238
  }
13194
13239
  });
13195
13240
  return d.toDxfString();
@@ -13198,17 +13243,17 @@ class Dxf extends Component {
13198
13243
  * 将点云结构转换为DXF格式
13199
13244
  * @returns
13200
13245
  */
13201
- toDxfBlob() {
13202
- const blob = new Blob([this.toDxfString()]);
13246
+ toDxfBlob(unit = "Millimeters") {
13247
+ const blob = new Blob([this.toDxfString(unit)]);
13203
13248
  return blob;
13204
13249
  }
13205
13250
  /**
13206
13251
  * 下载
13207
13252
  * @param filename
13208
13253
  */
13209
- async download(filename, path = ".") {
13254
+ async download(filename, unit = "Millimeters") {
13210
13255
  if (typeof window !== "undefined") {
13211
- const blob = this.toDxfBlob();
13256
+ const blob = this.toDxfBlob(unit);
13212
13257
  const a = document.createElement("a");
13213
13258
  a.href = URL.createObjectURL(blob);
13214
13259
  a.download = filename + ".dxf";
@@ -13219,7 +13264,7 @@ class Dxf extends Component {
13219
13264
  /* @vite-ignore */
13220
13265
  packageName
13221
13266
  );
13222
- fs.writeFileSync(path + "/" + filename, this.toDxfString());
13267
+ fs.writeFileSync(filename, this.toDxfString(unit));
13223
13268
  }
13224
13269
  }
13225
13270
  /**
@@ -13863,6 +13908,10 @@ class DxfSystem extends ComponentManager {
13863
13908
  Dxf;
13864
13909
  Variable;
13865
13910
  wallWidth;
13911
+ /** 构造函数
13912
+ * @param wallWidth 输出墙壁厚度,该墙壁厚度不受缩放影响
13913
+ * @param scale 原始数据缩放比例
13914
+ */
13866
13915
  constructor(wallWidth = 0.1, scale = 1) {
13867
13916
  super();
13868
13917
  this.wallWidth = wallWidth;