...

Source file src/oss.terrastruct.com/d2/lib/shape/shape_real_square.go

Documentation: oss.terrastruct.com/d2/lib/shape

     1  package shape
     2  
     3  import (
     4  	"math"
     5  
     6  	"oss.terrastruct.com/d2/lib/geo"
     7  	"oss.terrastruct.com/util-go/go2"
     8  )
     9  
    10  type shapeRealSquare struct {
    11  	*baseShape
    12  }
    13  
    14  func NewRealSquare(box *geo.Box) Shape {
    15  	shape := shapeRealSquare{
    16  		baseShape: &baseShape{
    17  			Type: REAL_SQUARE_TYPE,
    18  			Box:  box,
    19  		},
    20  	}
    21  	shape.FullShape = go2.Pointer(Shape(shape))
    22  	return shape
    23  }
    24  
    25  func (s shapeRealSquare) AspectRatio1() bool {
    26  	return true
    27  }
    28  
    29  func (s shapeRealSquare) IsRectangular() bool {
    30  	return true
    31  }
    32  
    33  func (s shapeRealSquare) GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64) {
    34  	sideLength := math.Ceil(math.Max(width+paddingX, height+paddingY))
    35  	return sideLength, sideLength
    36  }
    37  

View as plain text