summaryrefslogtreecommitdiff
path: root/internal/render/instructions.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/render/instructions.go')
-rw-r--r--internal/render/instructions.go62
1 files changed, 31 insertions, 31 deletions
diff --git a/internal/render/instructions.go b/internal/render/instructions.go
index 685f3f8..b4823f2 100644
--- a/internal/render/instructions.go
+++ b/internal/render/instructions.go
@@ -12,13 +12,13 @@ type (
)
const (
- ToLeft trimDir = iota
- ToRight
- None overlapType = iota
- Covers
- Within
- Left
- Right
+ TrimLeft trimDir = iota
+ TrimRight
+ CoverNone overlapType = iota
+ CoverTotal
+ CoverWithin
+ CoverLeft
+ CoverRight
)
type Instruction interface {
@@ -28,7 +28,7 @@ type Instruction interface {
Pos() (int, int)
// Len returns the length of the instructions content.
Len() int
- // Trim removes n characters from one side of the instruction.
+ // Trim removes n characters FROM one side of the instruction.
Trim(n int, d trimDir) Instruction
// Copy creates a new instruction with the same content and position.
Copy() Instruction
@@ -41,31 +41,31 @@ func overlap(over, under Instruction) overlapType {
// wrong row:
if oy != uy {
- return None
+ return CoverNone
}
// totally covers it
if ox <= ux && ox+os >= ux+us {
- return Covers
+ return CoverTotal
}
// Overlap on the left:
if ox <= ux && ox+os > ux {
- return Left
+ return CoverLeft
}
// Overlap on the right:
if ox < ux+us && ox+os >= ux+us {
- return Right
+ return CoverRight
}
// centered inside:
if ox > ux && ox+os < ux+us {
- return Within
+ return CoverWithin
}
// Only other option is not touching
- return None
+ return CoverNone
}
// Squash creates new instruction from overlapping instructions.
@@ -82,22 +82,22 @@ func squash(over Instruction, under Instruction, ot overlapType) []Instruction {
ux, _ := under.Pos()
os, us := over.Len(), under.Len()
switch ot {
- case Covers:
+ case CoverTotal:
return []Instruction{}
- case Left:
+ case CoverLeft:
overlap := ox + os - ux
- under.Trim(overlap, ToLeft)
+ under = under.Trim(overlap, TrimLeft)
return []Instruction{under}
- case Right:
+ case CoverRight:
overlap := ux + us - ox
- under.Trim(overlap, ToRight)
+ under = under.Trim(overlap, TrimRight)
return []Instruction{under}
- case Within:
- overlapL := ox - ux
- overlapR := ux + us - (ox + os)
- left := under.Copy().Trim(overlapL, ToLeft)
- under.Trim(overlapR, ToRight)
- return []Instruction{left, under}
+ case CoverWithin:
+ overlapR := ox - ux + os
+ overlapL := ux + us - ox
+ right := under.Copy().Trim(overlapR, TrimLeft)
+ left := under.Trim(overlapL, TrimRight)
+ return []Instruction{left, right}
default:
return []Instruction{under}
}
@@ -143,13 +143,13 @@ func (d DrawInstruction) Trim(n int, from trimDir) Instruction {
return nil
}
switch from {
- case ToLeft:
+ case TrimLeft:
d.Content = d.Content[n:]
d.X += n
- case ToRight:
+ case TrimRight:
d.Content = d.Content[:len(d.Content)-n]
}
- return &d
+ return d
}
func (d DrawInstruction) Copy() Instruction {
@@ -200,13 +200,13 @@ func (c ClearInstruction) Trim(n int, from trimDir) Instruction {
return nil
}
switch from {
- case ToLeft:
+ case TrimLeft:
c.Size -= n
c.X += n
- case ToRight:
+ case TrimRight:
c.Size -= n
}
- return &c
+ return c
}
func (c ClearInstruction) Copy() Instruction {