export connection truncate decimals along route

This commit is contained in:
Gavin Nishizawa 2023-05-25 14:45:19 -07:00
parent 6fc9ffa04d
commit 53709d641a
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
2 changed files with 19 additions and 1 deletions

View file

@ -11,6 +11,7 @@ import (
"oss.terrastruct.com/d2/d2target"
"oss.terrastruct.com/d2/d2themes"
"oss.terrastruct.com/d2/lib/color"
"oss.terrastruct.com/d2/lib/geo"
)
func Export(ctx context.Context, g *d2graph.Graph, fontFamily *d2fonts.FontFamily) (*d2target.Diagram, error) {
@ -297,7 +298,14 @@ func toConnection(edge *d2graph.Edge, theme *d2themes.Theme) d2target.Connection
if edge.LabelPercentage != nil {
connection.LabelPercentage = *edge.LabelPercentage
}
connection.Route = edge.Route
connection.Route = make([]*geo.Point, 0, len(edge.Route))
for i := range edge.Route {
p := edge.Route[i].Copy()
p.TruncateDecimals()
p.TruncateFloat32()
connection.Route = append(connection.Route, p)
}
connection.IsCurve = edge.IsCurve
connection.Src = edge.Src.AbsID()

View file

@ -295,3 +295,13 @@ func (a *Point) Interpolate(b *Point, t float64) *Point {
a.Y*(1.0-t)+b.Y*t,
)
}
func (p *Point) TruncateFloat32() {
p.X = float64(float32(p.X))
p.Y = float64(float32(p.Y))
}
func (p *Point) TruncateDecimals() {
p.X = TruncateDecimals(p.X)
p.Y = TruncateDecimals(p.Y)
}