update tracing to label box

This commit is contained in:
Gavin Nishizawa 2023-07-14 13:24:00 -07:00
parent 5d7b0af127
commit b1cb08027e
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 16 additions and 0 deletions

View file

@ -336,6 +336,12 @@ func (edge *Edge) TraceToShape(points []*geo.Point, startIndex, endIndex int) (n
// add left/right padding to box // add left/right padding to box
labelBox.TopLeft.X -= label.PADDING labelBox.TopLeft.X -= label.PADDING
labelBox.Width += 2 * label.PADDING labelBox.Width += 2 * label.PADDING
for labelBox.Contains(startingSegment.End) && startIndex+1 > endIndex {
startingSegment.Start = startingSegment.End
startingSegment.End = points[startIndex+2]
startIndex++
}
if intersections := labelBox.Intersections(startingSegment); len(intersections) > 0 { if intersections := labelBox.Intersections(startingSegment); len(intersections) > 0 {
overlapsOutsideLabel = true overlapsOutsideLabel = true
p := intersections[0] p := intersections[0]
@ -381,6 +387,11 @@ func (edge *Edge) TraceToShape(points []*geo.Point, startIndex, endIndex int) (n
// add left/right padding to box // add left/right padding to box
labelBox.TopLeft.X -= label.PADDING labelBox.TopLeft.X -= label.PADDING
labelBox.Width += 2 * label.PADDING labelBox.Width += 2 * label.PADDING
for labelBox.Contains(endingSegment.Start) && endIndex-1 > startIndex {
endingSegment.End = endingSegment.Start
endingSegment.Start = points[endIndex-2]
endIndex--
}
if intersections := labelBox.Intersections(endingSegment); len(intersections) > 0 { if intersections := labelBox.Intersections(endingSegment); len(intersections) > 0 {
overlapsOutsideLabel = true overlapsOutsideLabel = true
p := intersections[0] p := intersections[0]

View file

@ -78,3 +78,8 @@ func (b *Box) ToString() string {
} }
return fmt.Sprintf("{TopLeft: %s, Width: %.0f, Height: %.0f}", b.TopLeft.ToString(), b.Width, b.Height) return fmt.Sprintf("{TopLeft: %s, Width: %.0f, Height: %.0f}", b.TopLeft.ToString(), b.Width, b.Height)
} }
func (b *Box) Contains(p *Point) bool {
return !(p.X < b.TopLeft.X || b.TopLeft.X+b.Width < p.X ||
p.Y < b.TopLeft.Y || b.TopLeft.Y+b.Height < p.Y)
}