Skip to content

Commit 595f3df

Browse files
committed
Force some special joints to snap together.
1 parent 02e9db6 commit 595f3df

File tree

2 files changed

+127
-9
lines changed

2 files changed

+127
-9
lines changed

‎src/canvas.go‎

Lines changed: 105 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,81 @@ const (
264264
// possible orientations.
265265
func (c *Canvas) Lines() []Line {
266266

267+
horizontalMidlines := c.getLinesForSegment('-')
268+
267269
diagUpLines := c.getLinesForSegment('/')
270+
for i, l := range diagUpLines {
271+
// /_
272+
if c.runeAt(l.start.east()) == '_' {
273+
diagUpLines[i].needsTinyNudgingLeft = true
274+
}
275+
276+
// _
277+
// /
278+
if c.runeAt(l.stop.north()) == '_' {
279+
diagUpLines[i].needsTinyNudgingRight = true
280+
}
281+
282+
// _
283+
// /
284+
if !l.lonely && c.runeAt(l.stop.nEast()) == '_' {
285+
diagUpLines[i].needsTinyNudgingRight = true
286+
}
287+
288+
// _/
289+
if !l.lonely && c.runeAt(l.start.west()) == '_' {
290+
diagUpLines[i].needsTinyNudgingLeft = true
291+
}
292+
293+
// \
294+
// /
295+
if !l.lonely && c.runeAt(l.stop.north()) == '\\' {
296+
diagUpLines[i].needsTinyNudgingRight = true
297+
}
298+
299+
// /
300+
// \
301+
if !l.lonely && c.runeAt(l.start.south()) == '\\' {
302+
diagUpLines[i].needsTinyNudgingLeft = true
303+
}
304+
}
268305

269306
diagDownLines := c.getLinesForSegment('\\')
307+
for i, l := range diagDownLines {
308+
// _\
309+
if c.runeAt(l.stop.west()) == '_' {
310+
diagDownLines[i].needsTinyNudgingRight = true
311+
}
270312

271-
horizontalMidlines := c.getLinesForSegment('-')
313+
// _
314+
// \
315+
if c.runeAt(l.start.north()) == '_' {
316+
diagDownLines[i].needsTinyNudgingLeft = true
317+
}
318+
319+
// _
320+
// \
321+
if !l.lonely && c.runeAt(l.start.nWest()) == '_' {
322+
diagDownLines[i].needsTinyNudgingLeft = true
323+
}
324+
325+
// \_
326+
if !l.lonely && c.runeAt(l.stop.east()) == '_' {
327+
diagDownLines[i].needsTinyNudgingRight = true
328+
}
329+
330+
// \
331+
// /
332+
if !l.lonely && c.runeAt(l.stop.south()) == '/' {
333+
diagDownLines[i].needsTinyNudgingRight = true
334+
}
335+
336+
// /
337+
// \
338+
if !l.lonely && c.runeAt(l.start.north()) == '/' {
339+
diagDownLines[i].needsTinyNudgingLeft = true
340+
}
341+
}
272342

273343
horizontalBaselines := c.getLinesForSegment('_')
274344
for i, l := range horizontalBaselines {
@@ -298,6 +368,30 @@ func (c *Canvas) Lines() []Line {
298368
if c.runeAt(l.start.west()) == '\\' || c.runeAt(l.start.sWest()) == '/' {
299369
horizontalBaselines[i].needsTinyNudgingLeft = true
300370
}
371+
372+
// _\
373+
if c.runeAt(l.stop.east()) == '\\' {
374+
horizontalBaselines[i].needsNudgingRight = true
375+
horizontalBaselines[i].needsTinyNudgingRight = true
376+
}
377+
378+
//
379+
// /_
380+
if c.runeAt(l.start.west()) == '/' {
381+
horizontalBaselines[i].needsNudgingLeft = true
382+
horizontalBaselines[i].needsTinyNudgingLeft = true
383+
}
384+
// _
385+
// /
386+
if c.runeAt(l.stop.south()) == '/' {
387+
horizontalBaselines[i].needsTinyNudgingRight = true
388+
}
389+
390+
// _
391+
// \
392+
if c.runeAt(l.start.south()) == '\\' {
393+
horizontalBaselines[i].needsTinyNudgingLeft = true
394+
}
301395
}
302396

303397
verticalLines := c.getLinesForSegment('|')
@@ -578,35 +672,38 @@ func (c *Canvas) isRoundedCorner(i Index) Orientation {
578672
upperLeft := i.nWest()
579673
upperRight := i.nEast()
580674

675+
opensUp := r == '\'' || r == '+'
676+
opensDown := r == '.' || r == '+'
677+
581678
dashRight := c.runeAt(right) == '-' || c.runeAt(right) == '+' || c.runeAt(right) == '_' || c.runeAt(upperRight) == '_'
582679
dashLeft := c.runeAt(left) == '-' || c.runeAt(left) == '+' || c.runeAt(left) == '_' || c.runeAt(upperLeft) == '_'
583680

584681
isVerticalSegment := func(i Index) bool {
585682
r := c.runeAt(i)
586-
return r == '|' || r == '+' || r == ')' || r == '('
683+
return r == '|' || r == '+' || r == ')' || r == '(' || isDot(r)
587684
}
588685

589686
// .- or .-
590687
// | +
591-
if dashRight && isVerticalSegment(lowerLeft) {
688+
if opensDown && dashRight && isVerticalSegment(lowerLeft) {
592689
return NW
593690
}
594691

595-
// -. or -. or -. or _.
596-
// | + ) )
597-
if dashLeft && isVerticalSegment(lowerRight) {
692+
// -. or -. or -. or _. or -.
693+
// | + ) ) o
694+
if opensDown && dashLeft && isVerticalSegment(lowerRight) {
598695
return NE
599696
}
600697

601698
// | or + or | or + or + or_ )
602699
// -' -' +' +' ++ '
603-
if dashLeft && isVerticalSegment(upperRight) {
700+
if opensUp && dashLeft && isVerticalSegment(upperRight) {
604701
return SE
605702
}
606703

607704
// | or +
608705
// '- '-
609-
if dashRight && isVerticalSegment(upperLeft) {
706+
if opensUp && dashRight && isVerticalSegment(upperLeft) {
610707
return SW
611708
}
612709

‎src/svg.go‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (l Line) Draw(out io.Writer) {
8080
// _
8181
// \_
8282
//
83+
// TODO make this a method on Line to return accurate pixel
8384
if l.lonely {
8485
switch l.orientation {
8586
case NE:
@@ -107,25 +108,45 @@ func (l Line) Draw(out io.Writer) {
107108

108109
if l.needsNudgingDown {
109110
stop.y += 8
110-
if start.x != stop.x {
111+
if l.horizontal() {
111112
start.y += 8
112113
}
113114
}
114115

115116
if l.needsNudgingLeft {
116117
start.x -= 8
118+
//if l.orientation == NE {
119+
//start.y += 8
120+
//} else if l.orientation == SE {
121+
//start.y -= 8
122+
//}
117123
}
118124

119125
if l.needsNudgingRight {
120126
stop.x += 8
127+
//if l.orientation == NE {
128+
//stop.y -= 8
129+
//} else if l.orientation == SE {
130+
//stop.y += 8
131+
//}
121132
}
122133

123134
if l.needsTinyNudgingLeft {
124135
start.x -= 4
136+
if l.orientation == NE {
137+
start.y += 8
138+
} else if l.orientation == SE {
139+
start.y -= 8
140+
}
125141
}
126142

127143
if l.needsTinyNudgingRight {
128144
stop.x += 4
145+
if l.orientation == NE {
146+
stop.y -= 8
147+
} else if l.orientation == SE {
148+
stop.y += 8
149+
}
129150
}
130151

131152
writeBytes(&out,

0 commit comments

Comments
 (0)