From d91ace98ece209b26d2479820cd628fe2e7e3fd2 Mon Sep 17 00:00:00 2001 From: OneRain2333 Date: Fri, 30 Dec 2022 20:11:22 +0800 Subject: [PATCH] Fix ascii diagram and remove unused code --- lib/shape/shape.go | 9 ++++----- lib/shape/shape_double_circle.go | 28 ++++++++++++++-------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/shape/shape.go b/lib/shape/shape.go index 33db84af7..edfc5e6f3 100644 --- a/lib/shape/shape.go +++ b/lib/shape/shape.go @@ -167,11 +167,10 @@ func NewShape(shapeType string, box *geo.Box) Shape { // p is the prev point (used to calculate slope) // s is the point on the actual shape border that'll be returned // -// p -// │ -// │ -// ▼ -// +// p +// │ +// │ +// ▼ // ┌────r─────────────────────────┐ // │ │ // │ │ │ diff --git a/lib/shape/shape_double_circle.go b/lib/shape/shape_double_circle.go index d99cbbaa8..f67e18b09 100644 --- a/lib/shape/shape_double_circle.go +++ b/lib/shape/shape_double_circle.go @@ -1,8 +1,9 @@ package shape import ( + "math" + "oss.terrastruct.com/d2/lib/geo" - "oss.terrastruct.com/d2/lib/svg" ) type shapeDoubleCircle struct { @@ -18,20 +19,19 @@ func NewDoubleCircle(box *geo.Box) Shape { } } -func doubleCirclePath(box *geo.Box) *svg.SvgPathContext { - // halfYFactor := 43.6 / 87.3 - pc := svg.NewSVGPathContext(box.TopLeft, box.Width, box.Height) - pc.StartAt(pc.Absolute(0.25, 0)) - // pc - return pc +func (s shapeDoubleCircle) AspectRatio1() bool { + return true +} + +func (s shapeDoubleCircle) GetDimensionsToFit(width, height, padding float64) (float64, float64) { + radius := math.Ceil(math.Sqrt(math.Pow(width/2, 2)+math.Pow(height/2, 2))) + padding + return radius * 2, radius * 2 +} + +func (s shapeDoubleCircle) GetInsidePlacement(width, height, padding float64) geo.Point { + return *geo.NewPoint(s.Box.TopLeft.X+math.Ceil(s.Box.Width/2-width/2), s.Box.TopLeft.Y+math.Ceil(s.Box.Height/2-height/2)) } func (s shapeDoubleCircle) Perimeter() []geo.Intersectable { - return doubleCirclePath(s.Box).Path -} - -func (s shapeDoubleCircle) GetSVGPathData() []string { - return []string{ - doubleCirclePath(s.Box).PathData(), - } + return []geo.Intersectable{geo.NewEllipse(s.Box.Center(), s.Box.Width/2, s.Box.Height/2)} }