schematic-symbols 0.0.101 → 0.0.102

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/drawing/arc.ts CHANGED
@@ -12,7 +12,7 @@ export function approximateArc(
12
12
  ): Point[] {
13
13
  // This is a simplified approximation. For a more accurate representation,
14
14
  // you might want to use a dedicated SVG path library.
15
- const steps = 30
15
+ const steps = 40
16
16
  const points: Point[] = []
17
17
  for (let i = 1; i < steps; i++) {
18
18
  const t = i / steps
@@ -0,0 +1,28 @@
1
+ import type { Point } from "./types"
2
+
3
+ export function approximateBezier(
4
+ p0: Point,
5
+ p1: Point,
6
+ p2: Point,
7
+ p3: Point,
8
+ ): Point[] {
9
+ const points: Point[] = []
10
+ const steps = 30
11
+ for (let t = 0; t <= 1; t += 1 / steps) {
12
+ const x =
13
+ Math.pow(1 - t, 3) * p0.x +
14
+ 3 * Math.pow(1 - t, 2) * t * p1.x +
15
+ 3 * (1 - t) * Math.pow(t, 2) * p2.x +
16
+ Math.pow(t, 3) * p3.x
17
+
18
+ const y =
19
+ Math.pow(1 - t, 3) * p0.y +
20
+ 3 * Math.pow(1 - t, 2) * t * p1.y +
21
+ 3 * (1 - t) * Math.pow(t, 2) * p2.y +
22
+ Math.pow(t, 3) * p3.y
23
+
24
+ points.push({ x, y })
25
+ }
26
+
27
+ return points
28
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Point } from "./types"
2
2
  import { approximateArc } from "./arc"
3
+ import { approximateBezier } from "./cubicBezierCurveArc"
3
4
 
4
5
  export function svgPathToPoints(pathString: string): Point[] {
5
6
  const points: Point[] = []
@@ -35,12 +36,21 @@ export function svgPathToPoints(pathString: string): Point[] {
35
36
  case "V":
36
37
  addPoint(currentX, args[0])
37
38
  break
38
- case "C":
39
- // For C command, we add both control points and the end point
40
- points.push({ x: args[0], y: args[1] }) // First control point
41
- points.push({ x: args[2], y: args[3] }) // Second control point
42
- addPoint(args[4], args[5]) // End point
39
+ case "C": {
40
+ const [x1, y1, x2, y2, x, y] = args
41
+
42
+ // Approximate the cubic Bézier curve
43
+ const bezierPoints = approximateBezier(
44
+ { x: currentX, y: currentY }, // Start point
45
+ { x: x1, y: y1 }, // Control point 1
46
+ { x: x2, y: y2 }, // Control point 2
47
+ { x, y }, // End point
48
+ )
49
+
50
+ points.push(...bezierPoints)
51
+ addPoint(x, y) // Update the current position
43
52
  break
53
+ }
44
54
  case "Q":
45
55
  // For Q command, we add both the control point and the end point
46
56
  points.push({ x: args[0], y: args[1] }) // Control point
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "schematic-symbols",
3
3
  "main": "./dist/index.js",
4
- "version": "0.0.101",
4
+ "version": "0.0.102",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -0,0 +1,10 @@
1
+ import { modifySymbol } from "../drawing/modify-symbol/modify-symbol"
2
+ import svgJson from "./capacitor_polarized_right"
3
+
4
+ export default modifySymbol(svgJson)
5
+ .changeTextAnchor("{VAL}", "middle_top")
6
+ .rotateRightFacingSymbol("down")
7
+ .labelPort("left1", ["1"])
8
+ .labelPort("right1", ["2"])
9
+ .changeTextAnchor("{REF}", "middle_left")
10
+ .build()
@@ -0,0 +1,10 @@
1
+ import { modifySymbol } from "../drawing/modify-symbol/modify-symbol"
2
+ import svgJson from "./capacitor_polarized_right"
3
+
4
+ export default modifySymbol(svgJson)
5
+ .changeTextAnchor("{VAL}", "middle_top")
6
+ .rotateRightFacingSymbol("left")
7
+ .labelPort("left1", ["1"])
8
+ .labelPort("right1", ["2"])
9
+ .changeTextAnchor("{REF}", "middle_top")
10
+ .build()
@@ -0,0 +1,10 @@
1
+ import { modifySymbol } from "../drawing/modify-symbol/modify-symbol"
2
+ import svgJson from "assets/generated/capacitor_polarized.json"
3
+
4
+ export default modifySymbol(svgJson)
5
+ .changeTextAnchor("{VAL}", "middle_top")
6
+ .rotateRightFacingSymbol("right")
7
+ .labelPort("left1", ["1"])
8
+ .labelPort("right1", ["2"])
9
+ .changeTextAnchor("{REF}", "middle_bottom")
10
+ .build()
@@ -0,0 +1,10 @@
1
+ import { modifySymbol } from "../drawing/modify-symbol/modify-symbol"
2
+ import svgJson from "./capacitor_polarized_right"
3
+
4
+ export default modifySymbol(svgJson)
5
+ .changeTextAnchor("{VAL}", "middle_top")
6
+ .rotateRightFacingSymbol("up")
7
+ .labelPort("left1", ["1"])
8
+ .labelPort("right1", ["2"])
9
+ .changeTextAnchor("{REF}", "middle_right")
10
+ .build()