From 53709d641a5408245506240dfc34990fb90a1733 Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Thu, 25 May 2023 14:45:19 -0700 Subject: [PATCH] export connection truncate decimals along route --- d2exporter/export.go | 10 +++++++++- lib/geo/point.go | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/d2exporter/export.go b/d2exporter/export.go index fc3557c37..eb163b1dc 100644 --- a/d2exporter/export.go +++ b/d2exporter/export.go @@ -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() diff --git a/lib/geo/point.go b/lib/geo/point.go index 18a4ba8c7..0b0a4ff51 100644 --- a/lib/geo/point.go +++ b/lib/geo/point.go @@ -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) +}