Skip to content

Commit

Permalink
fix eq triangle calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
soypat committed Aug 17, 2024
1 parent 37951ff commit e4a0355
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
14 changes: 2 additions & 12 deletions cpu_evaluators.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ func (h *hex) Evaluate(pos []ms3.Vec, dist []float32, userData any) error {
return nil
}

func (t *tri) Evaluate(pos []ms3.Vec, dist []float32, userData any) error {
h1, h2 := t.args()
for i, p := range pos {
q := ms3.AbsElem(p)
m1 := maxf(q.X*tribisect+p.Y*0.5, -p.Y)
dist[i] = maxf(q.Z-h2, m1-h1)
}
return nil
}

func evaluateSDF3(obj bounder3, pos []ms3.Vec, dist []float32, userData any) error {
sdf, err := gleval.AssertSDF3(obj)
if err != nil {
Expand Down Expand Up @@ -520,7 +510,7 @@ func (e *extrusion) Evaluate(pos []ms3.Vec, dist []float32, userData any) error
if err != nil {
return err
}
h := e.h
h := e.h / 2
for i, p := range pos {
d := dist[i]
wy := math32.Abs(p.Z) - h
Expand Down Expand Up @@ -557,7 +547,7 @@ func (c *circle2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error {

func (t *equilateralTri2d) Evaluate(pos []ms2.Vec, dist []float32, userData any) error {
const k = sqrt3
r := t.hTri * tribisect
r := t.hTri / sqrt3
for i, p := range pos {
p.X = math32.Abs(p.X) - r
p.Y += r / k
Expand Down
4 changes: 2 additions & 2 deletions gsdf2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (t *equilateralTri2d) AppendShaderName(b []byte) []byte {
}

func (t *equilateralTri2d) AppendShaderBody(b []byte) []byte {
b = appendFloatDecl(b, "h", t.hTri/1.7)
b = appendFloatDecl(b, "h", t.hTri/sqrt3)
b = append(b, `const float k = sqrt(3.0);
p.x = abs(p.x) - h;
p.y = p.y + h/k;
Expand Down Expand Up @@ -332,7 +332,7 @@ func (e *extrusion) AppendShaderName(b []byte) []byte {
}

func (e *extrusion) AppendShaderBody(b []byte) []byte {
b = appendFloatDecl(b, "h", e.h)
b = appendFloatDecl(b, "h", e.h/2)
b = appendDistanceDecl(b, e.s, "d", "p.xy")
b = append(b, `vec2 w = vec2( d, abs(p.z) - h );
return min(max(w.x,w.y),0.0) + length(max(w,0.0));`...)
Expand Down

0 comments on commit e4a0355

Please sign in to comment.