schematic-symbols 0.0.101 → 0.0.102
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +5 -1
- package/dist/index.js +1838 -63
- package/dist/index.js.map +1 -1
- package/drawing/arc.ts +1 -1
- package/drawing/cubicBezierCurveArc.ts +28 -0
- package/drawing/svgPathToPoints.ts +15 -5
- package/package.json +1 -1
- package/symbols/capacitor_polarized_down.ts +10 -0
- package/symbols/capacitor_polarized_left.ts +10 -0
- package/symbols/capacitor_polarized_right.ts +10 -0
- package/symbols/capacitor_polarized_up.ts +10 -0
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 =
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
@@ -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()
|