ceil dimensions to fit
This commit is contained in:
parent
e367a007e5
commit
fed4bd2b9f
14 changed files with 34 additions and 14 deletions
|
|
@ -93,7 +93,7 @@ func (s baseShape) GetInsidePlacement(_, _, padding float64) geo.Point {
|
||||||
// return the minimum shape dimensions needed to fit content (width x height)
|
// return the minimum shape dimensions needed to fit content (width x height)
|
||||||
// in the shape's innerBox with padding
|
// in the shape's innerBox with padding
|
||||||
func (s baseShape) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
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) {
|
func (s baseShape) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"oss.terrastruct.com/d2/lib/svg"
|
||||||
)
|
)
|
||||||
|
|
@ -80,7 +82,7 @@ func (s shapeCallout) GetDimensionsToFit(width, height, paddingX, paddingY float
|
||||||
} else {
|
} else {
|
||||||
baseHeight += defaultTipHeight
|
baseHeight += defaultTipHeight
|
||||||
}
|
}
|
||||||
return width + paddingX, baseHeight
|
return math.Ceil(width + paddingX), math.Ceil(baseHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeCallout) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapeCallout) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeCylinder) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
// 2 arcs top, height + padding, 1 arc bottom
|
// 2 arcs top, height + padding, 1 arc bottom
|
||||||
totalHeight := height + paddingY + 3*defaultArcDepth
|
totalHeight := height + paddingY + 3*defaultArcDepth
|
||||||
return width + paddingX, totalHeight
|
return math.Ceil(width + paddingX), math.Ceil(totalHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeCylinder) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapeCylinder) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeDiamond) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
totalWidth := 2 * (width + paddingX)
|
totalWidth := 2 * (width + paddingX)
|
||||||
totalHeight := 2 * (height + paddingY)
|
totalHeight := 2 * (height + paddingY)
|
||||||
return totalWidth, totalHeight
|
return math.Ceil(totalWidth), math.Ceil(totalHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeDiamond) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapeDiamond) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeDocument) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
baseHeight := (height + paddingY) * docPathHeight / docPathInnerBottom
|
baseHeight := (height + paddingY) * docPathHeight / docPathInnerBottom
|
||||||
return width + paddingX, baseHeight
|
return math.Ceil(width + paddingX), math.Ceil(baseHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeDocument) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapeDocument) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeHexagon) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
totalWidth := 2 * (width + paddingX)
|
totalWidth := 2 * (width + paddingX)
|
||||||
return totalWidth, height + paddingY
|
return math.Ceil(totalWidth), math.Ceil(height + paddingY)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeHexagon) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapeHexagon) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ func (s shapePackage) GetDimensionsToFit(width, height, paddingX, paddingY float
|
||||||
topHeight := innerHeight * packageVerticalScalar / (1. - packageVerticalScalar)
|
topHeight := innerHeight * packageVerticalScalar / (1. - packageVerticalScalar)
|
||||||
totalHeight := innerHeight + math.Min(topHeight, packageTopMaxHeight)
|
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) {
|
func (s shapePackage) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func (s shapePage) GetDimensionsToFit(width, height, paddingX, paddingY float64)
|
||||||
}
|
}
|
||||||
totalWidth = math.Max(totalWidth, 2*pageCornerWidth)
|
totalWidth = math.Max(totalWidth, 2*pageCornerWidth)
|
||||||
totalHeight = math.Max(totalHeight, pageCornerHeight)
|
totalHeight = math.Max(totalHeight, pageCornerHeight)
|
||||||
return totalWidth, totalHeight
|
return math.Ceil(totalWidth), math.Ceil(totalHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapePage) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapePage) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeParallelogram) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
totalWidth := width + paddingX + parallelWedgeWidth*2
|
totalWidth := width + paddingX + parallelWedgeWidth*2
|
||||||
return totalWidth, height + paddingY
|
return math.Ceil(totalWidth), math.Ceil(height + paddingY)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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 {
|
} else if totalHeight > 1.5*totalWidth {
|
||||||
totalWidth = totalHeight / 1.5
|
totalWidth = totalHeight / 1.5
|
||||||
}
|
}
|
||||||
return totalWidth, totalHeight
|
return math.Ceil(totalWidth), math.Ceil(totalHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapePerson) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapePerson) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeQueue) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
// 1 arc left, width+ padding, 2 arcs right
|
// 1 arc left, width+ padding, 2 arcs right
|
||||||
totalWidth := 3*defaultArcDepth + width + paddingX
|
totalWidth := 3*defaultArcDepth + width + paddingX
|
||||||
return totalWidth, height + paddingY
|
return math.Ceil(totalWidth), math.Ceil(height + paddingY)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeQueue) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapeQueue) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,6 @@ func (s shapeRealSquare) IsRectangular() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeRealSquare) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
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
|
return sideLength, sideLength
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeStep) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
totalWidth := width + paddingX + 2*STEP_WEDGE_WIDTH
|
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) {
|
func (s shapeStep) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package shape
|
package shape
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"oss.terrastruct.com/d2/lib/geo"
|
"oss.terrastruct.com/d2/lib/geo"
|
||||||
"oss.terrastruct.com/d2/lib/svg"
|
"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) {
|
func (s shapeStoredData) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
|
||||||
totalWidth := width + paddingX + 2*storedDataWedgeWidth
|
totalWidth := width + paddingX + 2*storedDataWedgeWidth
|
||||||
return totalWidth, height + paddingY
|
return math.Ceil(totalWidth), math.Ceil(height + paddingY)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s shapeStoredData) GetDefaultPadding() (paddingX, paddingY float64) {
|
func (s shapeStoredData) GetDefaultPadding() (paddingX, paddingY float64) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue