// SVG writes the board SVG representation into the writer.
// An error is returned if there is there is an error writing data.
// SVG also takes options which can customize the image output.
543010
func SVG(w io.Writer, b *chess.Board, opts ...func(*encoder)) error {
	e := new(w, opts)
	return e.EncodeSVG(b)
}
189597
func Geometry(box orb.Bound, g orb.Geometry, o orb.Orientation) orb.Geometry {
	if g == nil {
		return nil
	}

	if g.Dimensions() != 2 {
		return clip.Geometry(box, g)
	}

	var mp orb.MultiPolygon
	switch g := g.(type) {
	case orb.Ring:
		mp = Ring(box, g, o)
	case orb.Polygon:
		mp = Polygon(box, g, o)
	case orb.MultiPolygon:
		mp = MultiPolygon(box, g, o)
	case orb.Bound:
		return clip.Geometry(box, g)
	case orb.Collection:
		var result orb.Collection
		for _, c := range g {
			c := Geometry(box, c, o)
			if c != nil {
				result = append(result, c)
			}
		}

		if len(result) == 1 {
			return result[0]
		}

		return result
	default:
		panic(fmt.Sprintf("geometry type not supported: %T", g))
	}

	if mp == nil {
		return nil
	}

	if len(mp) == 1 {
		return mp[0]
	}

	return mp
}
919813
func AsSVG(c aspect.ColumnElem) aspect.ColumnElem {
	return c.SetInner(
		aspect.FuncClause{Inner: c.Inner(), F: "ST_AsSVG"},
	)
}
435233
func (s *SVG) Rect(x, y, w, h interface{}, args map[string]interface{}) {
	rectStr := fmt.Sprintf("<rect x='%v' y='%v' width='%v' height='%v' %s />", x, y, w, h, s.WriteArgs(args))
	s.svgString += rectStr
}
60572
func ToRGBA(c color.Color) RGBA {
	if c, ok := c.(RGBA); ok {
		return c
	}
	r, g, b, a := c.RGBA()
	return RGBA{
		float64(r) / 0xffff,
		float64(g) / 0xffff,
		float64(b) / 0xffff,
		float64(a) / 0xffff,
	}
}
949282
func doline(canvas *svg.SVG, x1, y1, x2, y2 int, style, direction, label string) {
	var labelstyle string
	var upflag bool

	tadjust := 6
	mx := (x2 - x1) / 2
	my := (y2 - y1) / 2
	lx := x1 + mx
	ly := y1 + my
	m, _ := sloper(x1, y1, x2, y2)
	hline := m == 0
	vline := m == math.Inf(-1) || m == math.Inf(1)
	straight := hline || vline

	switch {
	case m < 0: // upwards line
		upflag = true
		labelstyle += "text-anchor:end;"
		lx -= tadjust
	case hline: // horizontal line
		labelstyle += "text-anchor:middle;baseline-shift:20%;"
		ly -= tadjust
	case m > 0: // downwards line
		upflag = false
		labelstyle += "text-anchor:start;"
		lx += tadjust
	}
	if !straight && direction != "straight" {
		cx, cy := x1, y2 // initial control points
		// fmt.Fprintf(os.Stderr, "%s slope = %.3f\n", label, m)
		if upflag {
			if direction == "ccw" {
				cx, cy = x2, y1
			} else {
				cx, cy = x1, y2
			}
		} else {
			if direction == "ccw" {
				cx, cy = x1, y2
			} else {
				cx, cy = x2, y1
			}
		}
		canvas.Qbez(x1, y1, cx, cy, x2, y2, style)
		labelstyle += "text-anchor:middle"
		canvas.Text(lx, ly, label, labelstyle)
	} else {
		canvas.Line(x1, y1, x2, y2, style)
		canvas.Text(lx, ly, label, labelstyle) // midpoint
	}
}
899394
func (pdbg *Pdbg) Pdbgf(format string, args ...interface{}) string {
	return pdbg.pdbgfw(format, pdbg.Err(), args...)
}
136615
func AddTo(sp *svg.SVG, x, y, width, height int, font string, fontsize int, background color.RGBA) *SvgGraphics {
	s := New(sp, width, height, font, fontsize, background)
	s.tx, s.ty = x, y
	return s
}
805506
func (s *SVG) Circle(cx, cy, r interface{}, args map[string]interface{}) {
	circleStr := fmt.Sprintf("<circle cx='%v' cy='%v' r='%v' %s />", cx, cy, r, s.WriteArgs(args))
	s.svgString += circleStr
}
128299
func EllipseRGBA(renderer *sdl.Renderer, x, y, rx, ry int32, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_rx := C.Sint16(rx)
	_ry := C.Sint16(ry)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.ellipseRGBA((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x, _y, _rx, _ry, _r, _g, _b, _a) == 0
}
638526
func (rng *Pcg128x64) Stream(streamH, streamL uint64) {
  // stream must be odd for LCG, so shift left 1 and turn on the 1 bit
  rng.lcg.Stream = Uint128{streamH,streamL}.ShiftLeft(1)
  rng.lcg.Stream.L |= 1
}
807910
func SVGAbort(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "SVGAbort", Listener: listener}
}
126739
func message(canvas *svg.SVG, x, y, w, h, l int, bcolor, scolor string) {
	et := h / 3
	w2 := w / 2
	px := w / 8
	py := h / 8
	e1x := []int{x, x, x + w, x + w, x + w2, x}
	e1y := []int{y + et, y + h, y + h, y + et, y + (et * 2), y + et}
	e2x := []int{x, x + w2, x + w, x + w2, x}
	e2y := []int{y + et, y, y + et, y + (et * 2), y + et}

	canvas.Polygon(e2x, e2y, "fill:"+bcolor)
	canvas.Polygon(e1x, e1y, "fill:"+scolor)
	canvas.Roundrect(x+px, y+py, w-(px*2), h-py, l, l, "fill:"+scolor)
	canvas.Line(x, y+et, x+w2, y+(et*2), "stroke-width:1;stroke:"+bcolor)
	canvas.Line(x+w, y+et, x+w2, y+(et*2), "stroke-width:1;stroke:"+bcolor)
}
439425
func Massage(in bytes.Buffer) string {
	svg := string(in.Bytes())

	// Work around for dot bug which misses quoting some ampersands,
	// resulting on unparsable SVG.
	svg = strings.Replace(svg, "&;", "&amp;;", -1)

	//Dot's SVG output is
	//
	//    <svg width="___" height="___"
	//     viewBox="___" xmlns=...>
	//    <g id="graph0" transform="...">
	//    ...
	//    </g>
	//    </svg>
	//
	// Change it to
	//
	//    <svg width="100%" height="100%"
	//     xmlns=...>
	//    <script>...</script>
	//    <g id="viewport" transform="translate(0,0)">
	//    <g id="graph0" transform="...">
	//    ...
	//    </g>
	//    </g>
	//    </svg>

	if loc := viewBox.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`<svg width="100%" height="100%"` +
			svg[loc[1]:]
	}

	if loc := graphId.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`<script type="text/ecmascript"><![CDATA[` + svgPanJS + `]]></script>` +
			`<g id="viewport" transform="scale(0.5,0.5) translate(0,0)">` +
			svg[loc[0]:]
	}

	if loc := svgClose.FindStringIndex(svg); loc != nil {
		svg = svg[:loc[0]] +
			`</g>` +
			svg[loc[0]:]
	}

	return svg
}
610908
func (wb *WriteBatch) Data() []byte {
	var cSize C.size_t
	cValue := C.rocksdb_writebatch_data(wb.c, &cSize)
	return charToByte(cValue, cSize)
}
1366268
func (g *Geometry) Hex() ([]byte, error) {
	encoder := newWkbEncoder()
	return encoder.encodeHex(g)
}
644446
func (win *Window) GroupEnd() {
	panelEnd(win.ctx, win)
	win.parent.usingSub = false

	// immediate drawing
	win.parent.cmds.Commands = append(win.parent.cmds.Commands, win.cmds.Commands...)
}