Skip to content

Commit 9358e46

Browse files
committed
minor cleanup
1 parent 7862455 commit 9358e46

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

src/features/shapes/FancyText.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import {
1919
import { connectMarkedVerticesAlongMachinePerimeter } from "@/features/machines/util"
2020
import { getFont, fontNames, getFontWeights } from "@/features/fonts/fontsSlice"
2121

22-
const MIN_SPACING_MULTIPLIER = 1.2
22+
const MIN_SPACING_MULTIPLIER = 1.2 // Minimum line height as multiple of letter "A" height
23+
const FONT_SIZE = 5 // OpenType rendering size; produces fluid curves at different scales
24+
const TOLERANCE = 0.01 // Proximity threshold for merging nearby vertices in graph
2325

2426
const options = {
2527
fancyText: {
@@ -261,7 +263,7 @@ export default class FancyText extends Shape {
261263

262264
// Use Array.from to properly handle Unicode (emoji are multi-byte)
263265
const chars = Array.from(word)
264-
const fSize = 5 // matches convertTextToPoints
266+
const fSize = FONT_SIZE
265267
const charCircuits = []
266268
let xOffset = 0
267269

@@ -368,7 +370,7 @@ export default class FancyText extends Shape {
368370

369371
const first = circuit[0]
370372
const last = circuit[circuit.length - 1]
371-
const isClosed = distance(first, last) < 0.01
373+
const isClosed = distance(first, last) < TOLERANCE
372374
const loop = isClosed ? circuit.slice(0, -1) : circuit
373375

374376
return { loop, isClosed }
@@ -471,7 +473,7 @@ export default class FancyText extends Shape {
471473
// these values produce fluid text curves at different sizes
472474
const tolerance = 0.001
473475
const distance = 0.001
474-
const fSize = 5
476+
const fSize = FONT_SIZE
475477
const x = 0
476478
const y = 0
477479

@@ -486,7 +488,7 @@ export default class FancyText extends Shape {
486488
}
487489

488490
// Nodes within tolerance share the same key for graph merging
489-
proximityNode(x, y, tolerance = 0.01) {
491+
proximityNode(x, y, tolerance = TOLERANCE) {
490492
const sx = Math.round(x / tolerance) * tolerance
491493
const sy = Math.round(y / tolerance) * tolerance
492494
const key = `${sx.toFixed(4)},${sy.toFixed(4)}`
@@ -495,7 +497,7 @@ export default class FancyText extends Shape {
495497
}
496498

497499
// Build graph from all letter paths for Chinese Postman traversal
498-
buildPathGraph(paths, tolerance = 0.01) {
500+
buildPathGraph(paths, tolerance = TOLERANCE) {
499501
const graph = new Graph()
500502

501503
for (const path of paths) {
@@ -529,8 +531,7 @@ export default class FancyText extends Shape {
529531
return paths[0].map((v) => cloneVertex(v))
530532
}
531533

532-
const tolerance = 0.01
533-
const graph = this.buildPathGraph(paths, tolerance)
534+
const graph = this.buildPathGraph(paths, TOLERANCE)
534535

535536
// Connect disconnected components with minimal bridges
536537
graph.connectComponents()
@@ -560,7 +561,7 @@ export default class FancyText extends Shape {
560561
const last = vertices[vertices.length - 1]
561562
const dist = distance(node, last)
562563

563-
if (dist < tolerance) continue
564+
if (dist < TOLERANCE) continue
564565
}
565566
vertices.push(cloneVertex(node))
566567
}

0 commit comments

Comments
 (0)