// TrigonRGBA draws trigon (triangle outline) with alpha blending.
// (http://www.ferzkopp.net/Software/SDL_gfx-2.0/Docs/html/_s_d_l__gfx_primitives_8c.html#a45d6a7edcd8b25e1a60e39b7f60bda3f)
433690
func TrigonRGBA(renderer *sdl.Renderer, x1, y1, x2, y2, x3, y3 int32, r, g, b, a uint8) bool {
	_x1 := C.Sint16(x1)
	_y1 := C.Sint16(y1)
	_x2 := C.Sint16(x2)
	_y2 := C.Sint16(y2)
	_x3 := C.Sint16(x3)
	_y3 := C.Sint16(y3)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.trigonRGBA((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x1, _y1, _x2, _y2, _x3, _y3, _r, _g, _b, _a) == 0
}
859996
func Geometry(g orb.Geometry, proj orb.Projection) orb.Geometry {
	if g == nil {
		return nil
	}

	switch g := g.(type) {
	case orb.Point:
		return Point(g, proj)
	case orb.MultiPoint:
		return MultiPoint(g, proj)
	case orb.LineString:
		return LineString(g, proj)
	case orb.MultiLineString:
		return MultiLineString(g, proj)
	case orb.Ring:
		return Ring(g, proj)
	case orb.Polygon:
		return Polygon(g, proj)
	case orb.MultiPolygon:
		return MultiPolygon(g, proj)
	case orb.Collection:
		return Collection(g, proj)
	case orb.Bound:
		return Bound(g, proj)
	}

	panic("geometry type not supported")
}
204186
func drawGopher(canvas *xgraphics.Image, gopher image.Image,
	win *xwindow.Window, x, y int) {

	// Find the rectangle of the canvas where we're going to draw the gopher.
	gopherRect := midRect(x, y, gopherWidth, gopherHeight, width, height)

	// If the rectangle contains no pixels, don't draw anything.
	if gopherRect.Empty() {
		return
	}

	// Output a little message.
	log.Printf("Drawing gopher at (%d, %d)", x, y)

	// Get a subimage of the gopher that's in sync with gopherRect.
	gopherPt := image.Pt(gopher.Bounds().Min.X, gopher.Bounds().Min.Y)
	if gopherRect.Min.X == 0 {
		gopherPt.X = gopherWidth - gopherRect.Dx()
	}
	if gopherRect.Min.Y == 0 {
		gopherPt.Y = gopherHeight - gopherRect.Dy()
	}

	// Create the canvas subimage.
	subCanvas := canvas.SubImage(gopherRect).(*xgraphics.Image)

	// Blend the gopher image into the sub-canvas.
	// This does alpha blending.
	xgraphics.Blend(subCanvas, gopher, gopherPt)

	// Now draw the changes to the pixmap.
	subCanvas.XDraw()

	// And paint them to the window.
	subCanvas.XPaint(win.Id)
}
1354248
func StringRGBA(renderer *sdl.Renderer, x, y int32, s string, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_s := C.CString(s)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.stringRGBA((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x, _y, _s, _r, _g, _b, _a) == 0
}
282950
func DrawRectangles(img gocv.Mat, rects []image.Rectangle, r int, g int, b int, thickness int) {
	for _, rect := range rects {
		gocv.Rectangle(&img, rect, color.RGBA{uint8(r), uint8(g), uint8(b), 0}, thickness)
	}
	return
}
1055881
func triangleArea(p1, p2, p3 engo.Point) float32 {
	// Law of cosines states: (note a2 = math.Pow(a, 2))
	// a2 = b2 + c2 - 2bc*cos(alpha)
	// This ends in: alpha = arccos ((-a2 + b2 + c2)/(2bc))
	a := p1.PointDistance(p3)
	b := p1.PointDistance(p2)
	c := p2.PointDistance(p3)
	alpha := math.Acos((-math.Pow(a, 2) + math.Pow(b, 2) + math.Pow(c, 2)) / (2 * b * c))

	// Law of sines state: a / sin(alpha) = c / sin(gamma)
	height := (c / math.Sin(math.Pi/2)) * math.Sin(alpha)

	return (b * height) / 2
}
252681
func (dc *Context) SetRGB(r, g, b float64) {
	dc.SetRGBA(r, g, b, 1)
}
370947
func CharacterRGBA(renderer *sdl.Renderer, x, y int32, c, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_c := C.char(c)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.characterRGBA((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x, _y, _c, _r, _g, _b, _a) == 0
}
994122
func (p *Image) RGBAAt(x, y int) color.RGBA {
	if !(image.Point{x, y}.In(p.Rect)) {
		return color.RGBA{}
	}
	i := (y-p.Rect.Min.Y)*p.Stride + (x-p.Rect.Min.X)*3
	return color.RGBA{p.Pix[i+0], p.Pix[i+1], p.Pix[i+2], 0xFF}
}
28370
func (c BGRA) RGBA() (r, g, b, a uint32) {
	r = uint32(c.R)
	r |= r << 8

	g = uint32(c.G)
	g |= g << 8

	b = uint32(c.B)
	b |= b << 8

	a = uint32(c.A)
	a |= a << 8

	return
}
409308
func (p *Pattern) geoTriangles() {
	scale := utils.HexVal(p.Hash, 0, 1)
	sideLength := utils.Map(scale, 0, 15, 15, 80)
	triangleHeight := sideLength / 2 * math.Sqrt(3)
	triangle := shapes.BuildTriangle(sideLength, triangleHeight)

	p.Svg.SetHeight(int(triangleHeight * 6))
	p.Svg.SetWidth(int(sideLength * 3))

	i := 0
	for y := 0; y <= 5; y++ {
		for x := 0; x <= 5; x++ {

			val := utils.HexVal(p.Hash, i, 1)
			opacity := utils.Opacity(val)
			fill := utils.FillColor(val)

			styles := make(map[string]interface{})
			styles["fill"] = fill
			styles["fill-opacity"] = opacity
			styles["stroke"] = utils.StrokeColor
			styles["stroke-opacity"] = utils.StrokeOpacity

			var rotation int
			if y%2 == 0 {
				if x%2 == 0 {
					rotation = 180
				}
			} else {
				if x%2 != 0 {
					rotation = 180
				}
			}

			style := make(map[string]interface{})

			style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", float64(x)*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2)
			p.Svg.Polyline(triangle, utils.Merge(styles, style))

			if x == 0 {
				style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", 6*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2)
				p.Svg.Polyline(triangle, utils.Merge(styles, style))
			}

			i = i + 1
		}
	}
}
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
}
1059703
func Sin(real []float64) []float64 {
	var outBegIdx C.int
	var outNBElement C.int
	outReal := make([]float64, len(real))
	C.TA_SIN(0, C.int(len(real)-1), (*C.double)(unsafe.Pointer(&real[0])), &outBegIdx, &outNBElement, (*C.double)(unsafe.Pointer(&outReal[0])))
	return outReal[:outNBElement]
}
996393
func FilledCircleRGBA(renderer *sdl.Renderer, x, y, rad int32, r, g, b, a uint8) bool {
	_x := C.Sint16(x)
	_y := C.Sint16(y)
	_rad := C.Sint16(rad)
	_r := C.Uint8(r)
	_g := C.Uint8(g)
	_b := C.Uint8(b)
	_a := C.Uint8(a)
	return C.filledCircleRGBA((*C.SDL_Renderer)(unsafe.Pointer(renderer)), _x, _y, _rad, _r, _g, _b, _a) == 0
}
756111
func ImageToNRGBA(img image.Image, width, height int) *image.NRGBA {
	newm := image.NewNRGBA(image.Rect(0, 0, width, height))
	draw.Draw(newm, newm.Bounds(), img, image.Point{0, 0}, draw.Src)

	return newm
}
624547
func drawBlock(img *image.Paletted, x, y, size float64, angle int, points []float64) {
	if angle > 0 { // 0 角度不需要转换
		// 中心坐标与 x、y 的距离，方便下面指定中心坐标(x+m,y+m)，
		// 0.5 的偏移值不能少，否则坐标靠右，非正中央
		m := size/2 - 0.5
		rotate(points, x+m, y+m, angle)
	}

	for i := x; i < x+size; i++ {
		for j := y; j < y+size; j++ {
			if pointInPolygon(i, j, points) {
				img.SetColorIndex(int(i), int(j), 1)
			}
		}
	}
}
1218680
func (img *Image) DrawCircle(xc, yc, r int, fill bool, c color.Color) {
	size := img.Bounds().Size()
	// 如果圆在图片可见区域外，直接退出
	if xc+r < 0 || xc-r >= size.X || yc+r < 0 || yc-r >= size.Y {
		return
	}
	x, y, d := 0, r, 3-2*r
	for x <= y {
		if fill {
			for yi := x; yi <= y; yi++ {
				img.drawCircle8(xc, yc, x, yi, c)
			}
		} else {
			img.drawCircle8(xc, yc, x, y, c)
		}
		if d < 0 {
			d = d + 4*x + 6
		} else {
			d = d + 4*(x-y) + 10
			y--
		}
		x++
	}
}