diff --git a/lib/shape/shape.go b/lib/shape/shape.go index 484719d99..ae4a30f73 100644 --- a/lib/shape/shape.go +++ b/lib/shape/shape.go @@ -93,7 +93,7 @@ func (s baseShape) GetInsidePlacement(_, _, padding float64) geo.Point { // return the minimum shape dimensions needed to fit content (width x height) // in the shape's innerBox with padding func (s baseShape) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { - return width + paddingX, height + paddingY + return math.Ceil(width + paddingX), math.Ceil(height + paddingY) } func (s baseShape) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_callout.go b/lib/shape/shape_callout.go index 6c91d2e2c..36cd23779 100644 --- a/lib/shape/shape_callout.go +++ b/lib/shape/shape_callout.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -80,7 +82,7 @@ func (s shapeCallout) GetDimensionsToFit(width, height, paddingX, paddingY float } else { baseHeight += defaultTipHeight } - return width + paddingX, baseHeight + return math.Ceil(width + paddingX), math.Ceil(baseHeight) } func (s shapeCallout) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_cylinder.go b/lib/shape/shape_cylinder.go index 79cc06e72..c0dcc6b9a 100644 --- a/lib/shape/shape_cylinder.go +++ b/lib/shape/shape_cylinder.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -80,7 +82,7 @@ func (s shapeCylinder) GetSVGPathData() []string { func (s shapeCylinder) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { // 2 arcs top, height + padding, 1 arc bottom totalHeight := height + paddingY + 3*defaultArcDepth - return width + paddingX, totalHeight + return math.Ceil(width + paddingX), math.Ceil(totalHeight) } func (s shapeCylinder) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_diamond.go b/lib/shape/shape_diamond.go index b6f95f7a8..a0a456cb6 100644 --- a/lib/shape/shape_diamond.go +++ b/lib/shape/shape_diamond.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -58,7 +60,7 @@ func (s shapeDiamond) GetSVGPathData() []string { func (s shapeDiamond) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { totalWidth := 2 * (width + paddingX) totalHeight := 2 * (height + paddingY) - return totalWidth, totalHeight + return math.Ceil(totalWidth), math.Ceil(totalHeight) } func (s shapeDiamond) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_document.go b/lib/shape/shape_document.go index 3ee710a28..e3238ea3c 100644 --- a/lib/shape/shape_document.go +++ b/lib/shape/shape_document.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -54,7 +56,7 @@ func (s shapeDocument) GetSVGPathData() []string { func (s shapeDocument) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { baseHeight := (height + paddingY) * docPathHeight / docPathInnerBottom - return width + paddingX, baseHeight + return math.Ceil(width + paddingX), math.Ceil(baseHeight) } func (s shapeDocument) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_hexagon.go b/lib/shape/shape_hexagon.go index ed6bbcb83..8fef2ffc7 100644 --- a/lib/shape/shape_hexagon.go +++ b/lib/shape/shape_hexagon.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -51,7 +53,7 @@ func (s shapeHexagon) GetSVGPathData() []string { func (s shapeHexagon) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { totalWidth := 2 * (width + paddingX) - return totalWidth, height + paddingY + return math.Ceil(totalWidth), math.Ceil(height + paddingY) } func (s shapeHexagon) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_package.go b/lib/shape/shape_package.go index 80219fa79..39da973c8 100644 --- a/lib/shape/shape_package.go +++ b/lib/shape/shape_package.go @@ -80,7 +80,7 @@ func (s shapePackage) GetDimensionsToFit(width, height, paddingX, paddingY float topHeight := innerHeight * packageVerticalScalar / (1. - packageVerticalScalar) totalHeight := innerHeight + math.Min(topHeight, packageTopMaxHeight) - return width + paddingX, totalHeight + return math.Ceil(width + paddingX), math.Ceil(totalHeight) } func (s shapePackage) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_page.go b/lib/shape/shape_page.go index 75717c8f2..5a836c4ab 100644 --- a/lib/shape/shape_page.go +++ b/lib/shape/shape_page.go @@ -95,7 +95,7 @@ func (s shapePage) GetDimensionsToFit(width, height, paddingX, paddingY float64) } totalWidth = math.Max(totalWidth, 2*pageCornerWidth) totalHeight = math.Max(totalHeight, pageCornerHeight) - return totalWidth, totalHeight + return math.Ceil(totalWidth), math.Ceil(totalHeight) } func (s shapePage) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_parallelogram.go b/lib/shape/shape_parallelogram.go index 4666853f6..90c1dc41f 100644 --- a/lib/shape/shape_parallelogram.go +++ b/lib/shape/shape_parallelogram.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -56,5 +58,5 @@ func (s shapeParallelogram) GetSVGPathData() []string { func (s shapeParallelogram) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { totalWidth := width + paddingX + parallelWedgeWidth*2 - return totalWidth, height + paddingY + return math.Ceil(totalWidth), math.Ceil(height + paddingY) } diff --git a/lib/shape/shape_person.go b/lib/shape/shape_person.go index e177135c8..415e0e2af 100644 --- a/lib/shape/shape_person.go +++ b/lib/shape/shape_person.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -79,7 +81,7 @@ func (s shapePerson) GetDimensionsToFit(width, height, paddingX, paddingY float6 } else if totalHeight > 1.5*totalWidth { totalWidth = totalHeight / 1.5 } - return totalWidth, totalHeight + return math.Ceil(totalWidth), math.Ceil(totalHeight) } func (s shapePerson) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_queue.go b/lib/shape/shape_queue.go index 5a0a9d32f..10a21ff0d 100644 --- a/lib/shape/shape_queue.go +++ b/lib/shape/shape_queue.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -76,7 +78,7 @@ func (s shapeQueue) GetSVGPathData() []string { func (s shapeQueue) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { // 1 arc left, width+ padding, 2 arcs right totalWidth := 3*defaultArcDepth + width + paddingX - return totalWidth, height + paddingY + return math.Ceil(totalWidth), math.Ceil(height + paddingY) } func (s shapeQueue) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_real_square.go b/lib/shape/shape_real_square.go index 76f3ccbde..3948d7d7a 100644 --- a/lib/shape/shape_real_square.go +++ b/lib/shape/shape_real_square.go @@ -28,6 +28,6 @@ func (s shapeRealSquare) IsRectangular() bool { } func (s shapeRealSquare) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { - sideLength := math.Max(width+paddingX, height+paddingY) + sideLength := math.Ceil(math.Max(width+paddingX, height+paddingY)) return sideLength, sideLength } diff --git a/lib/shape/shape_step.go b/lib/shape/shape_step.go index 8951e866a..c7b9dc0e0 100644 --- a/lib/shape/shape_step.go +++ b/lib/shape/shape_step.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -56,7 +58,7 @@ func (s shapeStep) GetSVGPathData() []string { func (s shapeStep) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { totalWidth := width + paddingX + 2*STEP_WEDGE_WIDTH - return totalWidth, height + paddingY + return math.Ceil(totalWidth), math.Ceil(height + paddingY) } func (s shapeStep) GetDefaultPadding() (paddingX, paddingY float64) { diff --git a/lib/shape/shape_stored_data.go b/lib/shape/shape_stored_data.go index f952c3fd0..69e127e7e 100644 --- a/lib/shape/shape_stored_data.go +++ b/lib/shape/shape_stored_data.go @@ -1,6 +1,8 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" "oss.terrastruct.com/d2/lib/svg" ) @@ -58,7 +60,7 @@ func (s shapeStoredData) GetSVGPathData() []string { func (s shapeStoredData) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) { totalWidth := width + paddingX + 2*storedDataWedgeWidth - return totalWidth, height + paddingY + return math.Ceil(totalWidth), math.Ceil(height + paddingY) } func (s shapeStoredData) GetDefaultPadding() (paddingX, paddingY float64) {