brandspec 0.1.0__py3-none-any.whl
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.
- brandspec/__init__.py +3 -0
- brandspec/cli.py +139 -0
- brandspec/core/__init__.py +1 -0
- brandspec/core/grid.py +112 -0
- brandspec/core/paths.py +253 -0
- brandspec/engines/__init__.py +1 -0
- brandspec/engines/mark/__init__.py +1 -0
- brandspec/engines/mark/archetypes/iso-impossible.json +36 -0
- brandspec/engines/mark/archetypes/line-screen-disc.json +55 -0
- brandspec/engines/mark/archetypes/radial-vortex.json +48 -0
- brandspec/engines/mark/archetypes/ribbon-weave.json +63 -0
- brandspec/engines/mark/archetypes/stencil-monogram.json +60 -0
- brandspec/engines/mark/compiler.py +186 -0
- brandspec/engines/mark/fields.py +181 -0
- brandspec/engines/mark/geometry.py +157 -0
- brandspec/engines/mark/schema.py +157 -0
- brandspec/inspect/__init__.py +5 -0
- brandspec/inspect/sheet.py +190 -0
- brandspec-0.1.0.dist-info/METADATA +171 -0
- brandspec-0.1.0.dist-info/RECORD +23 -0
- brandspec-0.1.0.dist-info/WHEEL +4 -0
- brandspec-0.1.0.dist-info/entry_points.txt +2 -0
- brandspec-0.1.0.dist-info/licenses/LICENSE +674 -0
brandspec/__init__.py
ADDED
brandspec/cli.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""CLI entrypoint for brandspec."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
from importlib import resources
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from pydantic import ValidationError
|
|
12
|
+
|
|
13
|
+
from .engines.mark.compiler import compile_spec
|
|
14
|
+
from .engines.mark.schema import MarkSpec
|
|
15
|
+
from .inspect import analyze_compiled, render_inspection_sheet
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _find_archetypes_dir() -> Path:
|
|
19
|
+
pkg_dir = Path(str(resources.files("brandspec").joinpath("engines/mark/archetypes")))
|
|
20
|
+
if pkg_dir.is_dir():
|
|
21
|
+
return pkg_dir
|
|
22
|
+
raise FileNotFoundError("Could not locate bundled mark archetypes directory.")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def cmd_archetypes(_args: argparse.Namespace) -> int:
|
|
26
|
+
arch_dir = _find_archetypes_dir()
|
|
27
|
+
files = sorted(arch_dir.glob("*.json"))
|
|
28
|
+
for f in files:
|
|
29
|
+
data = json.loads(f.read_text(encoding="utf-8"))
|
|
30
|
+
print(f"{f.stem:20s} [{data.get('category', 'geometric'):9s}] {data.get('concept', '')}")
|
|
31
|
+
return 0
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def cmd_init(args: argparse.Namespace) -> int:
|
|
35
|
+
arch_dir = _find_archetypes_dir()
|
|
36
|
+
src = arch_dir / f"{args.archetype}.json"
|
|
37
|
+
if not src.is_file():
|
|
38
|
+
available = ", ".join(p.stem for p in sorted(arch_dir.glob("*.json")))
|
|
39
|
+
print(f"Unknown archetype '{args.archetype}'. Available: {available}", file=sys.stderr)
|
|
40
|
+
return 1
|
|
41
|
+
out_path = Path(args.out)
|
|
42
|
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
43
|
+
out_path.write_text(src.read_text(encoding="utf-8"), encoding="utf-8")
|
|
44
|
+
print(f"Wrote {out_path}")
|
|
45
|
+
return 0
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _load_spec(spec_path: Path) -> MarkSpec:
|
|
49
|
+
raw = json.loads(spec_path.read_text(encoding="utf-8"))
|
|
50
|
+
return MarkSpec.model_validate(raw)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def cmd_build(args: argparse.Namespace) -> int:
|
|
54
|
+
spec_path = Path(args.spec)
|
|
55
|
+
try:
|
|
56
|
+
spec = _load_spec(spec_path)
|
|
57
|
+
except (OSError, json.JSONDecodeError, ValidationError) as exc:
|
|
58
|
+
print(f"Spec error: {exc}", file=sys.stderr)
|
|
59
|
+
return 1
|
|
60
|
+
|
|
61
|
+
compiled = compile_spec(spec)
|
|
62
|
+
metrics = analyze_compiled(compiled)
|
|
63
|
+
sheet = render_inspection_sheet(compiled)
|
|
64
|
+
|
|
65
|
+
out_dir = Path(args.out_dir) if args.out_dir else spec_path.parent / "out" / spec_path.stem
|
|
66
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
67
|
+
|
|
68
|
+
svg_file = out_dir / "logo.svg"
|
|
69
|
+
sheet_file = out_dir / "sheet.png"
|
|
70
|
+
metrics_file = out_dir / "metrics.json"
|
|
71
|
+
locked_spec = out_dir / "spec.json"
|
|
72
|
+
|
|
73
|
+
svg_file.write_text(compiled.svg_markup, encoding="utf-8")
|
|
74
|
+
sheet.save(sheet_file, format="PNG")
|
|
75
|
+
metrics_file.write_text(json.dumps(metrics.to_dict(), indent=2) + "\n", encoding="utf-8")
|
|
76
|
+
locked_spec.write_text(
|
|
77
|
+
json.dumps(spec.model_dump(mode="json", exclude_none=True), indent=2) + "\n",
|
|
78
|
+
encoding="utf-8",
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
print(
|
|
82
|
+
json.dumps(
|
|
83
|
+
{
|
|
84
|
+
"svg": str(svg_file),
|
|
85
|
+
"sheet": str(sheet_file),
|
|
86
|
+
"metrics": str(metrics_file),
|
|
87
|
+
**metrics.to_dict(),
|
|
88
|
+
},
|
|
89
|
+
indent=2,
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
return 0 if (metrics.passed or not args.strict) else 2
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def cmd_check(args: argparse.Namespace) -> int:
|
|
96
|
+
spec_path = Path(args.spec)
|
|
97
|
+
try:
|
|
98
|
+
spec = _load_spec(spec_path)
|
|
99
|
+
except (OSError, json.JSONDecodeError, ValidationError) as exc:
|
|
100
|
+
print(f"Spec error: {exc}", file=sys.stderr)
|
|
101
|
+
return 1
|
|
102
|
+
|
|
103
|
+
compiled = compile_spec(spec)
|
|
104
|
+
metrics = analyze_compiled(compiled)
|
|
105
|
+
print(json.dumps(metrics.to_dict(), indent=2))
|
|
106
|
+
return 0 if metrics.passed else 2
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def main(argv: list[str] | None = None) -> int:
|
|
110
|
+
parser = argparse.ArgumentParser(
|
|
111
|
+
prog="brandspec",
|
|
112
|
+
description="Deterministic brand specification compiler and visual audit CLI.",
|
|
113
|
+
)
|
|
114
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
115
|
+
|
|
116
|
+
p_arch = sub.add_parser("archetypes", help="List bundled mark starter archetypes")
|
|
117
|
+
p_arch.set_defaults(func=cmd_archetypes)
|
|
118
|
+
|
|
119
|
+
p_init = sub.add_parser("init", help="Copy an archetype spec to a working spec.json")
|
|
120
|
+
p_init.add_argument("archetype", help="Archetype name")
|
|
121
|
+
p_init.add_argument("--out", default="spec.json", help="Destination JSON path")
|
|
122
|
+
p_init.set_defaults(func=cmd_init)
|
|
123
|
+
|
|
124
|
+
p_build = sub.add_parser("build", help="Compile spec.json into SVG, inspection sheet, and metrics")
|
|
125
|
+
p_build.add_argument("spec", help="Path to spec.json")
|
|
126
|
+
p_build.add_argument("--out-dir", help="Output directory")
|
|
127
|
+
p_build.add_argument("--strict", action="store_true", help="Exit non-zero if quality metrics warn")
|
|
128
|
+
p_build.set_defaults(func=cmd_build)
|
|
129
|
+
|
|
130
|
+
p_check = sub.add_parser("check", help="Validate schema and quality metrics without writing files")
|
|
131
|
+
p_check.add_argument("spec", help="Path to spec.json")
|
|
132
|
+
p_check.set_defaults(func=cmd_check)
|
|
133
|
+
|
|
134
|
+
args = parser.parse_args(argv)
|
|
135
|
+
return args.func(args)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == "__main__":
|
|
139
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Shared core geometry, grids, paths, and normalization primitives."""
|
brandspec/core/grid.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""Coordinate system mappings and construction grid overlay generation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
Point2D = tuple[float, float]
|
|
11
|
+
COS_30 = math.cos(math.pi / 6.0)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GridSpec(BaseModel):
|
|
15
|
+
type: Literal["square", "isometric", "polar"] = "square"
|
|
16
|
+
divisions: int = Field(default=8, ge=2, le=32)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def grid_to_xy(pt: Point2D, grid: GridSpec, unit: float) -> Point2D:
|
|
20
|
+
"""Convert grid coordinates into centered design-space XY coordinates."""
|
|
21
|
+
a, b = pt
|
|
22
|
+
if grid.type == "square":
|
|
23
|
+
return (a * unit, b * unit)
|
|
24
|
+
if grid.type == "isometric":
|
|
25
|
+
x = a * unit * COS_30
|
|
26
|
+
y = (b + 0.5 * a) * unit
|
|
27
|
+
return (x, y)
|
|
28
|
+
if grid.type == "polar":
|
|
29
|
+
radius = a * unit
|
|
30
|
+
rad = math.radians(b)
|
|
31
|
+
return (radius * math.sin(rad), -radius * math.cos(rad))
|
|
32
|
+
raise ValueError(f"Unsupported grid type: {grid.type}")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def grid_overlay_svg(
|
|
36
|
+
grid: GridSpec,
|
|
37
|
+
unit: float,
|
|
38
|
+
affine: tuple[float, float, float, float, float, float],
|
|
39
|
+
canvas_size: int,
|
|
40
|
+
) -> str:
|
|
41
|
+
"""Render faint construction grid lines transformed into final canvas coordinates."""
|
|
42
|
+
sx, _, _, sy, tx, ty = affine
|
|
43
|
+
half = grid.divisions // 2 + 1
|
|
44
|
+
lines: list[str] = []
|
|
45
|
+
|
|
46
|
+
def to_canvas(x: float, y: float) -> Point2D:
|
|
47
|
+
return (x * sx + tx, y * sy + ty)
|
|
48
|
+
|
|
49
|
+
if grid.type == "square":
|
|
50
|
+
span = half * unit
|
|
51
|
+
for i in range(-half, half + 1):
|
|
52
|
+
offset = i * unit
|
|
53
|
+
stroke = "#4b8bf4" if i == 0 else "#c8d6e5"
|
|
54
|
+
width = "1.2" if i == 0 else "0.8"
|
|
55
|
+
x1, y1 = to_canvas(-span, offset)
|
|
56
|
+
x2, y2 = to_canvas(span, offset)
|
|
57
|
+
lines.append(
|
|
58
|
+
f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" '
|
|
59
|
+
f'stroke="{stroke}" stroke-width="{width}"/>'
|
|
60
|
+
)
|
|
61
|
+
x3, y3 = to_canvas(offset, -span)
|
|
62
|
+
x4, y4 = to_canvas(offset, span)
|
|
63
|
+
lines.append(
|
|
64
|
+
f'<line x1="{x3:.1f}" y1="{y3:.1f}" x2="{x4:.1f}" y2="{y4:.1f}" '
|
|
65
|
+
f'stroke="{stroke}" stroke-width="{width}"/>'
|
|
66
|
+
)
|
|
67
|
+
elif grid.type == "isometric":
|
|
68
|
+
span = half + 2
|
|
69
|
+
for i in range(-span, span + 1):
|
|
70
|
+
p1 = to_canvas(*grid_to_xy((i, -span), grid, unit))
|
|
71
|
+
p2 = to_canvas(*grid_to_xy((i, span), grid, unit))
|
|
72
|
+
p3 = to_canvas(*grid_to_xy((-span, i), grid, unit))
|
|
73
|
+
p4 = to_canvas(*grid_to_xy((span, i), grid, unit))
|
|
74
|
+
p5 = to_canvas(*grid_to_xy((-span, i + span), grid, unit))
|
|
75
|
+
p6 = to_canvas(*grid_to_xy((span, i - span), grid, unit))
|
|
76
|
+
stroke = "#4b8bf4" if i == 0 else "#c8d6e5"
|
|
77
|
+
for (ax, ay), (bx, by) in ((p1, p2), (p3, p4), (p5, p6)):
|
|
78
|
+
lines.append(
|
|
79
|
+
f'<line x1="{ax:.1f}" y1="{ay:.1f}" x2="{bx:.1f}" y2="{by:.1f}" '
|
|
80
|
+
f'stroke="{stroke}" stroke-width="0.8"/>'
|
|
81
|
+
)
|
|
82
|
+
elif grid.type == "polar":
|
|
83
|
+
cx, cy = to_canvas(0.0, 0.0)
|
|
84
|
+
scale = abs(sx)
|
|
85
|
+
for r_idx in range(1, half + 1):
|
|
86
|
+
r = r_idx * unit * scale
|
|
87
|
+
lines.append(
|
|
88
|
+
f'<circle cx="{cx:.1f}" cy="{cy:.1f}" r="{r:.1f}" '
|
|
89
|
+
f'fill="none" stroke="#c8d6e5" stroke-width="0.8"/>'
|
|
90
|
+
)
|
|
91
|
+
max_r = half * unit
|
|
92
|
+
spokes = max(8, grid.divisions)
|
|
93
|
+
for k in range(spokes):
|
|
94
|
+
deg = k * (360.0 / spokes)
|
|
95
|
+
rad = math.radians(deg)
|
|
96
|
+
x2, y2 = to_canvas(max_r * math.sin(rad), -max_r * math.cos(rad))
|
|
97
|
+
stroke = "#4b8bf4" if k % (spokes // 4 or 1) == 0 else "#c8d6e5"
|
|
98
|
+
lines.append(
|
|
99
|
+
f'<line x1="{cx:.1f}" y1="{cy:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" '
|
|
100
|
+
f'stroke="{stroke}" stroke-width="0.8"/>'
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
cx, cy = to_canvas(0.0, 0.0)
|
|
104
|
+
lines.append(
|
|
105
|
+
f'<circle cx="{cx:.1f}" cy="{cy:.1f}" r="3.5" fill="#e74c3c" opacity="0.7"/>'
|
|
106
|
+
)
|
|
107
|
+
return (
|
|
108
|
+
f'<g id="construction-grid" clip-path="url(#canvas-clip)">'
|
|
109
|
+
f'<defs><clipPath id="canvas-clip"><rect width="{canvas_size}" height="{canvas_size}"/></clipPath></defs>'
|
|
110
|
+
+ "".join(lines)
|
|
111
|
+
+ "</g>"
|
|
112
|
+
)
|
brandspec/core/paths.py
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""Shared Skia path builders, corner fillets, halo dilation, symmetry, and SVG serialization."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
import pathops
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
|
+
|
|
11
|
+
from .grid import Point2D
|
|
12
|
+
|
|
13
|
+
KAPPA = 0.5522847498307936
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class SymmetrySpec(BaseModel):
|
|
17
|
+
type: Literal[
|
|
18
|
+
"none",
|
|
19
|
+
"mirror_x",
|
|
20
|
+
"mirror_y",
|
|
21
|
+
"mirror_xy",
|
|
22
|
+
"rotate",
|
|
23
|
+
"glide_x",
|
|
24
|
+
] = "none"
|
|
25
|
+
count: int = Field(default=4, ge=2, le=36)
|
|
26
|
+
step_deg: float | None = None
|
|
27
|
+
scale_step: float = Field(default=1.0, gt=0.1, le=2.0)
|
|
28
|
+
offset: float = 0.0
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class PostProcessSpec(BaseModel):
|
|
32
|
+
canvas_size: int = Field(default=1000, ge=256, le=4096)
|
|
33
|
+
padding: float = Field(default=100.0, ge=0.0)
|
|
34
|
+
optical_center: bool = True
|
|
35
|
+
invert: bool = False
|
|
36
|
+
precision: int = Field(default=2, ge=0, le=5)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def circle_path(cx: float, cy: float, radius: float) -> pathops.Path:
|
|
40
|
+
"""Create an exact 4-cubic circle path."""
|
|
41
|
+
k = radius * KAPPA
|
|
42
|
+
p = pathops.Path()
|
|
43
|
+
p.moveTo(cx, cy - radius)
|
|
44
|
+
p.cubicTo(cx + k, cy - radius, cx + radius, cy - k, cx + radius, cy)
|
|
45
|
+
p.cubicTo(cx + radius, cy + k, cx + k, cy + radius, cx, cy + radius)
|
|
46
|
+
p.cubicTo(cx - k, cy + radius, cx - radius, cy + k, cx - radius, cy)
|
|
47
|
+
p.cubicTo(cx - radius, cy - k, cx - k, cy - radius, cx, cy - radius)
|
|
48
|
+
p.close()
|
|
49
|
+
return p
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def add_rounded_polygon(
|
|
53
|
+
pts: list[Point2D],
|
|
54
|
+
closed: bool,
|
|
55
|
+
corner_radius: float,
|
|
56
|
+
) -> pathops.Path:
|
|
57
|
+
"""Trace a polyline or polygon with exact cubic Bezier corner fillets."""
|
|
58
|
+
p = pathops.Path()
|
|
59
|
+
n = len(pts)
|
|
60
|
+
if n < 2:
|
|
61
|
+
return p
|
|
62
|
+
|
|
63
|
+
if corner_radius <= 1e-6 or n < 3:
|
|
64
|
+
p.moveTo(*pts[0])
|
|
65
|
+
for x, y in pts[1:]:
|
|
66
|
+
p.lineTo(x, y)
|
|
67
|
+
if closed:
|
|
68
|
+
p.close()
|
|
69
|
+
return p
|
|
70
|
+
|
|
71
|
+
def seg_unit(a: Point2D, b: Point2D) -> tuple[float, float, float]:
|
|
72
|
+
dx, dy = b[0] - a[0], b[1] - a[1]
|
|
73
|
+
d = math.hypot(dx, dy)
|
|
74
|
+
return (dx / d, dy / d, d) if d > 1e-9 else (0.0, 0.0, 0.0)
|
|
75
|
+
|
|
76
|
+
fillets: dict[int, tuple[Point2D, Point2D, Point2D, Point2D]] = {}
|
|
77
|
+
indices = range(n) if closed else range(1, n - 1)
|
|
78
|
+
for i in indices:
|
|
79
|
+
prev_pt = pts[(i - 1) % n]
|
|
80
|
+
curr_pt = pts[i]
|
|
81
|
+
next_pt = pts[(i + 1) % n]
|
|
82
|
+
ux1, uy1, d1 = seg_unit(curr_pt, prev_pt)
|
|
83
|
+
ux2, uy2, d2 = seg_unit(curr_pt, next_pt)
|
|
84
|
+
if d1 < 1e-6 or d2 < 1e-6:
|
|
85
|
+
continue
|
|
86
|
+
dot = max(-1.0, min(1.0, ux1 * ux2 + uy1 * uy2))
|
|
87
|
+
angle = math.acos(dot)
|
|
88
|
+
if angle < 1e-4 or abs(angle - math.pi) < 1e-4:
|
|
89
|
+
continue
|
|
90
|
+
half_tan = math.tan(angle / 2.0)
|
|
91
|
+
trim = min(corner_radius / half_tan, d1 * 0.45, d2 * 0.45)
|
|
92
|
+
r_actual = trim * half_tan
|
|
93
|
+
phi = math.pi - angle
|
|
94
|
+
handle = r_actual * (4.0 / 3.0) * math.tan(phi / 4.0)
|
|
95
|
+
p_in = (curr_pt[0] + ux1 * trim, curr_pt[1] + uy1 * trim)
|
|
96
|
+
p_out = (curr_pt[0] + ux2 * trim, curr_pt[1] + uy2 * trim)
|
|
97
|
+
c1 = (p_in[0] - ux1 * handle, p_in[1] - uy1 * handle)
|
|
98
|
+
c2 = (p_out[0] - ux2 * handle, p_out[1] - uy2 * handle)
|
|
99
|
+
fillets[i] = (p_in, c1, c2, p_out)
|
|
100
|
+
|
|
101
|
+
if closed:
|
|
102
|
+
start_pt = fillets[0][3] if 0 in fillets else pts[0]
|
|
103
|
+
p.moveTo(*start_pt)
|
|
104
|
+
for i in range(1, n + 1):
|
|
105
|
+
idx = i % n
|
|
106
|
+
if idx in fillets:
|
|
107
|
+
p_in, c1, c2, p_out = fillets[idx]
|
|
108
|
+
p.lineTo(*p_in)
|
|
109
|
+
p.cubicTo(*c1, *c2, *p_out)
|
|
110
|
+
else:
|
|
111
|
+
p.lineTo(*pts[idx])
|
|
112
|
+
p.close()
|
|
113
|
+
else:
|
|
114
|
+
p.moveTo(*pts[0])
|
|
115
|
+
for i in range(1, n - 1):
|
|
116
|
+
if i in fillets:
|
|
117
|
+
p_in, c1, c2, p_out = fillets[i]
|
|
118
|
+
p.lineTo(*p_in)
|
|
119
|
+
p.cubicTo(*c1, *c2, *p_out)
|
|
120
|
+
else:
|
|
121
|
+
p.lineTo(*pts[i])
|
|
122
|
+
p.lineTo(*pts[-1])
|
|
123
|
+
|
|
124
|
+
return p
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def dilate_path(path: pathops.Path, halo_radius: float) -> pathops.Path:
|
|
128
|
+
"""Expand a closed path outward by halo_radius for clean negative-space carving."""
|
|
129
|
+
if halo_radius <= 1e-6:
|
|
130
|
+
return path
|
|
131
|
+
ring = pathops.Path()
|
|
132
|
+
ring.addPath(path)
|
|
133
|
+
ring.stroke(
|
|
134
|
+
2.0 * halo_radius,
|
|
135
|
+
pathops.LineCap.ROUND_CAP,
|
|
136
|
+
pathops.LineJoin.ROUND_JOIN,
|
|
137
|
+
4.0,
|
|
138
|
+
)
|
|
139
|
+
ring.convertConicsToQuads(0.05)
|
|
140
|
+
ring = pathops.simplify(ring, fix_winding=True)
|
|
141
|
+
return pathops.op(path, ring, pathops.PathOp.UNION)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def apply_symmetry(path: pathops.Path, sym: SymmetrySpec | None, unit: float) -> pathops.Path:
|
|
145
|
+
"""Apply geometric symmetry transformation to a compiled path."""
|
|
146
|
+
if sym is None or sym.type == "none":
|
|
147
|
+
return path
|
|
148
|
+
|
|
149
|
+
builder = pathops.OpBuilder()
|
|
150
|
+
if sym.type == "mirror_x":
|
|
151
|
+
dx = sym.offset * unit
|
|
152
|
+
builder.add(path, pathops.PathOp.UNION)
|
|
153
|
+
builder.add(path.transform(-1, 0, 0, 1, dx, 0), pathops.PathOp.UNION)
|
|
154
|
+
elif sym.type == "mirror_y":
|
|
155
|
+
dy = sym.offset * unit
|
|
156
|
+
builder.add(path, pathops.PathOp.UNION)
|
|
157
|
+
builder.add(path.transform(1, 0, 0, -1, 0, dy), pathops.PathOp.UNION)
|
|
158
|
+
elif sym.type == "mirror_xy":
|
|
159
|
+
builder.add(path, pathops.PathOp.UNION)
|
|
160
|
+
builder.add(path.transform(-1, 0, 0, 1, 0, 0), pathops.PathOp.UNION)
|
|
161
|
+
builder.add(path.transform(1, 0, 0, -1, 0, 0), pathops.PathOp.UNION)
|
|
162
|
+
builder.add(path.transform(-1, 0, 0, -1, 0, 0), pathops.PathOp.UNION)
|
|
163
|
+
elif sym.type == "rotate":
|
|
164
|
+
step = sym.step_deg if sym.step_deg is not None else (360.0 / sym.count)
|
|
165
|
+
for k in range(sym.count):
|
|
166
|
+
rad = math.radians(k * step)
|
|
167
|
+
scale = sym.scale_step**k
|
|
168
|
+
ca = math.cos(rad) * scale
|
|
169
|
+
sa = math.sin(rad) * scale
|
|
170
|
+
builder.add(path.transform(ca, sa, -sa, ca, 0, 0), pathops.PathOp.UNION)
|
|
171
|
+
elif sym.type == "glide_x":
|
|
172
|
+
dx = (sym.offset if abs(sym.offset) > 1e-6 else 2.0) * unit
|
|
173
|
+
for k in range(sym.count):
|
|
174
|
+
sy = -1.0 if k % 2 == 1 else 1.0
|
|
175
|
+
builder.add(path.transform(1, 0, 0, sy, k * dx, 0), pathops.PathOp.UNION)
|
|
176
|
+
|
|
177
|
+
out = builder.resolve()
|
|
178
|
+
out.convertConicsToQuads(0.05)
|
|
179
|
+
return pathops.simplify(out, fix_winding=True)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _fmt(value: float, precision: int) -> str:
|
|
183
|
+
rounded = round(value, precision)
|
|
184
|
+
if abs(rounded) < 10 ** (-precision):
|
|
185
|
+
rounded = 0.0
|
|
186
|
+
text = f"{rounded:.{precision}f}"
|
|
187
|
+
if "." in text:
|
|
188
|
+
text = text.rstrip("0").rstrip(".")
|
|
189
|
+
return "0" if text == "-0" else text
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def path_to_svg_d(path: pathops.Path, precision: int = 2) -> str:
|
|
193
|
+
"""Serialize a pathops.Path to a canonical SVG path d string."""
|
|
194
|
+
parts: list[str] = []
|
|
195
|
+
for verb, pts in path.segments:
|
|
196
|
+
if verb == "moveTo":
|
|
197
|
+
x, y = pts[0]
|
|
198
|
+
parts.append(f"M {_fmt(x, precision)} {_fmt(y, precision)}")
|
|
199
|
+
elif verb == "lineTo":
|
|
200
|
+
x, y = pts[0]
|
|
201
|
+
parts.append(f"L {_fmt(x, precision)} {_fmt(y, precision)}")
|
|
202
|
+
elif verb == "qCurveTo":
|
|
203
|
+
if len(pts) == 2:
|
|
204
|
+
(x1, y1), (x2, y2) = pts
|
|
205
|
+
parts.append(
|
|
206
|
+
f"Q {_fmt(x1, precision)} {_fmt(y1, precision)} "
|
|
207
|
+
f"{_fmt(x2, precision)} {_fmt(y2, precision)}"
|
|
208
|
+
)
|
|
209
|
+
elif len(pts) > 2:
|
|
210
|
+
for i in range(len(pts) - 2):
|
|
211
|
+
cx, cy = pts[i]
|
|
212
|
+
nx, ny = pts[i + 1]
|
|
213
|
+
mx, my = 0.5 * (cx + nx), 0.5 * (cy + ny)
|
|
214
|
+
parts.append(
|
|
215
|
+
f"Q {_fmt(cx, precision)} {_fmt(cy, precision)} "
|
|
216
|
+
f"{_fmt(mx, precision)} {_fmt(my, precision)}"
|
|
217
|
+
)
|
|
218
|
+
(x1, y1), (x2, y2) = pts[-2], pts[-1]
|
|
219
|
+
parts.append(
|
|
220
|
+
f"Q {_fmt(x1, precision)} {_fmt(y1, precision)} "
|
|
221
|
+
f"{_fmt(x2, precision)} {_fmt(y2, precision)}"
|
|
222
|
+
)
|
|
223
|
+
elif verb == "curveTo":
|
|
224
|
+
(x1, y1), (x2, y2), (x3, y3) = pts
|
|
225
|
+
parts.append(
|
|
226
|
+
f"C {_fmt(x1, precision)} {_fmt(y1, precision)} "
|
|
227
|
+
f"{_fmt(x2, precision)} {_fmt(y2, precision)} "
|
|
228
|
+
f"{_fmt(x3, precision)} {_fmt(y3, precision)}"
|
|
229
|
+
)
|
|
230
|
+
elif verb == "closePath":
|
|
231
|
+
parts.append("Z")
|
|
232
|
+
return " ".join(parts)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def render_svg_doc(
|
|
236
|
+
svg_d: str,
|
|
237
|
+
canvas_size: int,
|
|
238
|
+
fill: str = "#000000",
|
|
239
|
+
background: str | None = None,
|
|
240
|
+
extra_before: str = "",
|
|
241
|
+
title: str = "",
|
|
242
|
+
) -> str:
|
|
243
|
+
"""Wrap an SVG path string into a standalone SVG document."""
|
|
244
|
+
bg = f'<rect width="{canvas_size}" height="{canvas_size}" fill="{background}"/>' if background else ""
|
|
245
|
+
title_el = f"<title>{title}</title>" if title else ""
|
|
246
|
+
return (
|
|
247
|
+
f'<svg xmlns="http://www.w3.org/2000/svg" '
|
|
248
|
+
f'viewBox="0 0 {canvas_size} {canvas_size}" '
|
|
249
|
+
f'width="{canvas_size}" height="{canvas_size}">'
|
|
250
|
+
f"{title_el}{bg}{extra_before}"
|
|
251
|
+
f'<path d="{svg_d}" fill="{fill}" fill-rule="nonzero"/>'
|
|
252
|
+
f"</svg>"
|
|
253
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Modular asset engines (mark, and future wordmark, lockup, icons, kit)."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Geometric and optical mark compiler engine."""
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "Iso Impossible",
|
|
4
|
+
"concept": "Three-fold isometric folded ribbon hexagon with exact rotational negative space",
|
|
5
|
+
"category": "geometric",
|
|
6
|
+
"unit": 40,
|
|
7
|
+
"grid": {
|
|
8
|
+
"type": "isometric",
|
|
9
|
+
"divisions": 8
|
|
10
|
+
},
|
|
11
|
+
"layers": [
|
|
12
|
+
{
|
|
13
|
+
"id": "folded-arm",
|
|
14
|
+
"op": "unite",
|
|
15
|
+
"shapes": [
|
|
16
|
+
{
|
|
17
|
+
"type": "grid_path",
|
|
18
|
+
"points": [[-1.5, -0.5], [0, -2], [1.45, -2], [0.25, -0.8]],
|
|
19
|
+
"width": 0.92,
|
|
20
|
+
"cap": "butt",
|
|
21
|
+
"join": "miter"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"symmetry": {
|
|
27
|
+
"type": "rotate",
|
|
28
|
+
"count": 3
|
|
29
|
+
},
|
|
30
|
+
"post": {
|
|
31
|
+
"canvas_size": 1000,
|
|
32
|
+
"padding": 110,
|
|
33
|
+
"optical_center": true,
|
|
34
|
+
"precision": 2
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "Line Screen Disc",
|
|
4
|
+
"concept": "Progressive optical line modulation clipped to a modernist sphere with diagonal slice",
|
|
5
|
+
"category": "effect",
|
|
6
|
+
"unit": 40,
|
|
7
|
+
"grid": {
|
|
8
|
+
"type": "square",
|
|
9
|
+
"divisions": 8
|
|
10
|
+
},
|
|
11
|
+
"layers": [
|
|
12
|
+
{
|
|
13
|
+
"id": "modulated-disc",
|
|
14
|
+
"op": "unite",
|
|
15
|
+
"shapes": [
|
|
16
|
+
{
|
|
17
|
+
"type": "line_screen",
|
|
18
|
+
"center": [0, 0],
|
|
19
|
+
"angle_deg": 0,
|
|
20
|
+
"count": 13,
|
|
21
|
+
"pitch": 0.62,
|
|
22
|
+
"length": 9.0,
|
|
23
|
+
"min_width": 0.14,
|
|
24
|
+
"max_width": 0.50,
|
|
25
|
+
"profile": "linear"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"clip_to": [
|
|
29
|
+
{
|
|
30
|
+
"type": "circle",
|
|
31
|
+
"center": [0, 0],
|
|
32
|
+
"radius": 3.8
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "horizon-cut",
|
|
38
|
+
"op": "subtract",
|
|
39
|
+
"shapes": [
|
|
40
|
+
{
|
|
41
|
+
"type": "grid_path",
|
|
42
|
+
"points": [[-4.5, 1.5], [4.5, -1.5]],
|
|
43
|
+
"width": 0.55,
|
|
44
|
+
"cap": "butt"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"post": {
|
|
50
|
+
"canvas_size": 1000,
|
|
51
|
+
"padding": 110,
|
|
52
|
+
"optical_center": true,
|
|
53
|
+
"precision": 2
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"name": "Radial Vortex",
|
|
4
|
+
"concept": "Six-fold twisted rotational blades forming an optical aperture",
|
|
5
|
+
"category": "effect",
|
|
6
|
+
"unit": 40,
|
|
7
|
+
"grid": {
|
|
8
|
+
"type": "polar",
|
|
9
|
+
"divisions": 12
|
|
10
|
+
},
|
|
11
|
+
"layers": [
|
|
12
|
+
{
|
|
13
|
+
"id": "outer-ring",
|
|
14
|
+
"op": "unite",
|
|
15
|
+
"shapes": [
|
|
16
|
+
{
|
|
17
|
+
"type": "radial_blades",
|
|
18
|
+
"center": [0, 0],
|
|
19
|
+
"count": 6,
|
|
20
|
+
"inner_radius": 0.95,
|
|
21
|
+
"outer_radius": 4.0,
|
|
22
|
+
"angle_deg": 0,
|
|
23
|
+
"twist_deg": 42,
|
|
24
|
+
"inner_width_deg": 34,
|
|
25
|
+
"outer_width_deg": 24,
|
|
26
|
+
"curve_bias": 0.55
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "core-void",
|
|
32
|
+
"op": "subtract",
|
|
33
|
+
"shapes": [
|
|
34
|
+
{
|
|
35
|
+
"type": "circle",
|
|
36
|
+
"center": [0, 0],
|
|
37
|
+
"radius": 1.1
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
"post": {
|
|
43
|
+
"canvas_size": 1000,
|
|
44
|
+
"padding": 110,
|
|
45
|
+
"optical_center": true,
|
|
46
|
+
"precision": 2
|
|
47
|
+
}
|
|
48
|
+
}
|