// Copyright 2018-2022 The MathJax Consortium
// SPDX-License-Identifier: Apache-2.0
// This file is a Go translation and modification of MathJax 3.2.2.
//
// Source: ts/output/svg/Notation.ts and
// ts/output/svg/Wrappers/menclose.ts.

package svg

import (
	
	

	
)

func ( *encloseLayout) (,  string) [4]float64 {
	 := .w.getBBox()
	, , ,  := .H, .D, .W, .thickness/2
	var  [4]float64
	switch  {
	case "top":
		 = [4]float64{0,  - , ,  - }
	case "right":
		 = [4]float64{ - , -,  - , }
	case "bottom":
		 = [4]float64{0,  - , ,  - }
	case "left":
		 = [4]float64{, -, , }
	case "vertical":
		 = [4]float64{ / 2, ,  / 2, -}
	case "horizontal":
		 = [4]float64{0, ( - ) / 2, , ( - ) / 2}
	case "up":
		 = [4]float64{,  - ,  - ,  - }
	case "down":
		 = [4]float64{,  - ,  - ,  - }
	}
	if  != "" {
		 := .getOffset()
		if  != 0 {
			if  == "X" {
				[0], [2] = [0]-, [2]-
			} else {
				[1], [3] = [1]-, [3]-
			}
		}
	}
	return 
}

func ( *encloseLayout) ( [4]float64) *Element {
	return NewElement("line").
		SetAttr("x1", fixed([0])).
		SetAttr("y1", fixed([1])).
		SetAttr("x2", fixed([2])).
		SetAttr("y2", fixed([3])).
		SetAttr("stroke-width", fixed(.thickness))
}

func ( *encloseLayout) ( float64) *Element {
	,  := .w.getBBox(), .thickness
	 := NewElement("rect").
		SetAttr("x", fixed(/2)).
		SetAttr("y", fixed(/2-.D)).
		SetAttr("width", fixed(.W-)).
		SetAttr("height", fixed(.H+.D-)).
		SetAttr("fill", "none").
		SetAttr("stroke-width", fixed())
	if  != 0 {
		.SetAttr("rx", fixed())
	}
	return 
}

func ( *encloseLayout) () *Element {
	,  := .w.getBBox(), .thickness
	return NewElement("ellipse").
		SetAttr("rx", fixed((.W-)/2)).
		SetAttr("ry", fixed((.H+.D-)/2)).
		SetAttr("cx", fixed(.W/2)).
		SetAttr("cy", fixed((.H-.D)/2)).
		SetAttr("fill", "none").
		SetAttr("stroke-width", fixed())
}

func ( *encloseLayout) () *Element {
	 := .w.getBBox()
	,  := encloseArgMod(1.75*.padding, .H+.D)
	 := .thickness / 2
	 := .H + .D
	 := math.Cos()
	return .path("mitre",
		"M", .W, -.D,
		"L", +*, -.D,
		"L", *+, -.D-,
	)
}

func ( *encloseLayout) () *Element {
	,  := .w.getBBox(), .thickness/2
	return .path("round",
		"M", , -.D,
		"a", .padding-/2, (.H+.D)/2-4*, 0, "0,1", 0, .H+.D-2*,
		"L", .W-, .H-,
	)
}

func ( *encloseLayout) ( string,  ...any) *Element {
	return NewElement("path").
		SetAttr("d", enclosePathData()).
		SetStyle("stroke-width", fixed(.thickness)).
		SetAttr("stroke-linecap", "round").
		SetAttr("stroke-linejoin", ).
		SetAttr("fill", "none")
}

func ( *encloseLayout) ( ...any) *Element {
	return NewElement("path").SetAttr("d", enclosePathData())
}

func enclosePathData( []any) string {
	 := make([]string, len())
	for ,  := range  {
		switch value := .(type) {
		case string:
			[] = 
		case float64:
			[] = fixed()
		case int:
			[] = fixed(float64())
		default:
			[] = fixed(encloseNumberValue())
		}
	}
	return strings.Join(, " ")
}

func ( *encloseLayout) (,  float64,  bool,  string,  float64) *Element {
	 := .w.getBBox()
	 := ( - .W) / 2
	 := (.H - .D) / 2
	,  := .thickness, .thickness/2
	, ,  := *.arrowX, *.arrowY, *.arrowDX
	var  *Element
	if  {
		 = .fill(
			"M", .W+, ,
			"l", -( + ), , "l", , -,
			"L", -, +,
			"l", , -, "l", -( + ), -,
			"l", +, -, "l", -, -,
			"L", .W+-, -,
			"l", -, -, "Z",
		)
	} else {
		 = .fill(
			"M", .W+, ,
			"l", -( + ), , "l", , -,
			"L", -, +, "l", 0, -,
			"L", .W+-, -,
			"l", -, -, "Z",
		)
	}
	 := make([]string, 0, 2)
	if  != 0 {
		if  == "X" {
			 = append(, "translate("+fixed(-)+" 0)")
		} else {
			 = append(, "translate(0 "+fixed()+")")
		}
	}
	if  != 0 {
		 := jscompat.Fixed(-*180/math.Pi, 3)
		 = append(, "rotate("++" "+fixed(.W/2)+" "+fixed()+")")
	}
	if len() != 0 {
		.SetAttr("transform", strings.Join(, " "))
	}
	return 
}