func RGBAColorMulNumber(c *ast.RGBAColor, n *ast.Number) *ast.RGBAColor { var val = uint32(n.Value) var r = c.R * val var g = c.G * val var b = c.B * val return ast.NewRGBAColor(r, g, b, c.A, nil) }
func RGBAColorDivNumber(c *ast.RGBAColor, n *ast.Number) *ast.RGBAColor { var val = n.Value var r = math.Floor(float64(c.R) / val) var g = math.Floor(float64(c.G) / val) var b = math.Floor(float64(c.B) / val) return ast.NewRGBAColor(uint32(r), uint32(g), uint32(b), c.A, nil) }
func RGBAColorSubNumber(c *ast.RGBAColor, n *ast.Number) *ast.RGBAColor { var val = uint32(n.Value) var r = uintsub(c.R, val) var g = uintsub(c.G, val) var b = uintsub(c.B, val) return ast.NewRGBAColor(r, g, b, c.A, nil) }
func TestComputeRGBAColorWithNumber(t *testing.T) { val := Compute(ast.NewOp(ast.T_PLUS), ast.NewRGBAColor(10, 10, 10, 0.2, nil), ast.NewNumber(3, nil, nil)) c, ok := val.(*ast.RGBAColor) assert.True(t, ok) assert.Equal(t, "rgba(13, 13, 13, 0.2)", c.String()) }