Skip to content

Commit

Permalink
Fix compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jphsd committed Sep 9, 2024
1 parent 0503869 commit 636f9fa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion color/frgba.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ func (c FRGBA) Scale(v float64) FRGBA {

// IsBlack returns true if the color is black.
func (c FRGBA) IsBlack() bool {
return c.R < 0.0001 && c.G < 0.0001 && c.B < 0.0001
return c.A < 0.0001 || (c.R < 0.0001 && c.G < 0.0001 && c.B < 0.0001)
}
1 change: 1 addition & 0 deletions fractal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Fractal struct {
// NewFractal returns a new Fractal instance.
func NewFractal(src Field, xfm *g2d.Aff3, comb OctaveCombiner, octaves float64) *Fractal {
oct := int(octaves)
oct++
w := make([]float64, oct)
for i := 0; i < oct; i++ {
w[i] = 1
Expand Down
2 changes: 1 addition & 1 deletion shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type ShapeCombinerVF struct {
Shape *graphics2d.Shape
}

func NewShapeCombinerVF(src1, src2 ColorField, shape *graphics2d.Shape) *ShapeCombinerVF {
func NewShapeCombinerVF(src1, src2 VectorField, shape *graphics2d.Shape) *ShapeCombinerVF {
return &ShapeCombinerVF{"ShapeCombinerVF", src1, src2, shape}
}

Expand Down
29 changes: 16 additions & 13 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ func (d *Direction) Eval2(x, y float64) float64 {

// Magnitude converts a VectorField to a Field based on the vector's magnitude.
type Magnitude struct {
Name string
Src VectorField
Name string
Src VectorField
Scale float64
}

func NewMagnitude(src VectorField) *Magnitude {
return &Magnitude{"Magnitude", src}
func NewMagnitude(src VectorField, scale float64) *Magnitude {
return &Magnitude{"Magnitude", src, scale}
}

// Eval2 implements the Field interface. Always >= 0
Expand All @@ -88,24 +89,26 @@ func (m *Magnitude) Eval2(x, y float64) float64 {
for _, f := range v {
s += f * f
}
return math.Sqrt(s)
r := math.Sqrt(s) * m.Scale
return clamp(r)
}

// Select converts a VectorField to a field by selecting one of its components.
type Select struct {
Name string
Src VectorField
Chan int
Name string
Src VectorField
Chan int
Scale float64
}

func NewSelect(src VectorField, ch int) *Select {
return &Select{"Select", src, ch}
func NewSelect(src VectorField, ch int, scale float64) *Select {
return &Select{"Select", src, ch, scale}
}

// Eval2 implements the Field interface.
func (s *Select) Eval2(x, y float64) float64 {
v := s.Src.Eval2(x, y)[s.Chan]
return v
v := s.Src.Eval2(x, y)[s.Chan] * s.Scale
return clamp(v)
}

// Weighted converts a VectorField to a field by selecting one of its components.
Expand All @@ -130,5 +133,5 @@ func (w *Weighted) Eval2(x, y float64) float64 {
for i := 0; i < n; i++ {
s += v[i] * w.Weights[i]
}
return s
return clamp(s)
}

0 comments on commit 636f9fa

Please sign in to comment.