// FilledTriangle draws a filled triangle given three points
FilledTriangle draws a filled triangle given three points
// FilledTriangle draws a filled triangle given three points
func FilledTriangle(display drivers.Displayer, x0 int16, y0 int16, x1 int16, y1 int16, x2 int16, y2 int16, color color.RGBA) {
	if y0 > y1 {
		x0, y0, x1, y1 = x1, y1, x0, y0
	}
	if y1 > y2 {
		x1, y1, x2, y2 = x2, y2, x1, y1
	}
	if y0 > y1 {
		x0, y0, x1, y1 = x1, y1, x0, y0
	}
	if y0 == y2 { 
		a := x0
		b := x0
		if x1 < a {
			a = x1
		} else if x1 > b {
			b = x1
		}
		if x2 < a {
			a = x2
		} else if x2 > b {
			b = x2
		}
		Line(display, a, y0, b, y0, color)
		return
	}
	dx01 := x1 - x0
	dy01 := y1 - y0
	dx02 := x2 - x0
	dy02 := y2 - y0
	dx12 := x2 - x1
	dy12 := y2 - y1
	sa := int16(0)
	sb := int16(0)
	a := int16(0)
	b := int16(0)
	last := y1 - 1
	if y1 == y2 {
		last = y1
	}
	y := y0
	for ; y <= last; y++ {
		a = x0 + sa/dy01
		b = x0 + sb/dy02
		sa += dx01
		sb += dx02
		Line(display, a, y, b, y, color)
	}
	sa = dx12 * (y - y1)
	sb = dx02 * (y - y0)
	for ; y <= y2; y++ {
		a = x1 + sa/dy12
		b = x0 + sb/dy02
		sa += dx12
		sb += dx02
		Line(display, a, y, b, y, color)
	}
}
func FilledTriangle ( display drivers . Displayer , x0 int16 , y0 int16 , x1 int16 , y1 int16 , x2 int16 , y2 int16 , color color . RGBA ) { if y0 > y1 { x0 , y0 , x1 , y1 = x1 , y1 , x0 , y0 } if y1 > y2 { x1 , y1 , x2 , y2 = x2 , y2 , x1 , y1 } if y0 > y1 { x0 , y0 , x1 , y1 = x1 , y1 , x0 , y0 } if y0 == y2 { a := x0 b := x0 if x1 < a { a = x1 } else if x1 > b { b = x1 } if x2 < a { a = x2 } else if x2 > b { b = x2 } Line ( display , a , y0 , b , y0 , color ) return } dx01 := x1 - x0 dy01 := y1 - y0 dx02 := x2 - x0 dy02 := y2 - y0 dx12 := x2 - x1 dy12 := y2 - y1 sa := int16 ( 0 ) sb := int16 ( 0 ) a := int16 ( 0 ) b := int16 ( 0 ) last := y1 - 1 if y1 == y2 { last = y1 } y := y0 for ; y <= last ; y ++ { a = x0 + sa / dy01 b = x0 + sb / dy02 sa += dx01 sb += dx02 Line ( display , a , y , b , y , color ) } sa = dx12 * ( y - y1 ) sb = dx02 * ( y - y0 ) for ; y <= y2 ; y ++ { a = x1 + sa / dy12 b = x0 + sb / dy02 sa += dx12 sb += dx02 Line ( display , a , y , b , y , color ) } }
FilledTriangle draws a filled triangle given three points
FilledTriangle draws a filled triangle given three points
// y0 = y1 = y2 : it's a line