Repository navigation
Expand file tree
/
Copy pathcomposition_test.go
More file actions
44 lines (41 loc) · 1.64 KB
/
Copy pathcomposition_test.go
File metadata and controls
44 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package progen
import (
"context"
"math"
"testing"
)
func TestCSGBooleanAndSmoothOperations(t *testing.T) {
d:=DefaultRecipe().Domain
d.Resolution=8
fill:=func(value float64)*VolumeGrid{
v:=&VolumeGrid{Space:d,Values:make([]float64,512)}
for i:=range v.Values{v.Values[i]=value}
return v
}
a,b:=fill(-.2),fill(.1)
idx:=3+8*(3+8*3)
for _,test:=range []struct{mode int;want float64}{{0,-.2},{1,.1},{2,-.1},{3,-.2}}{
v,err:=(CSG{Mode:test.mode,Blend:0}).Combine(context.Background(),a,b)
if err!=nil || math.Abs(v.Values[idx]-test.want)>1e-9 {t.Fatalf("mode %d: got %v, err %v",test.mode,v,err)}
}
smooth,err:=(CSG{Mode:3,Blend:.4}).Combine(context.Background(),a,b)
if err!=nil || smooth.Values[idx]>=-.2 {t.Fatalf("smooth union did not blend: %v %v",smooth,err)}
if _,err=(CSG{Mode:5}).Combine(context.Background(),a,b);err==nil {t.Fatal("invalid mode accepted")}
}
func TestWarpIdentityAndCompositePreset(t *testing.T) {
d:=DefaultRecipe().Domain
d.Resolution=8
src:=&VolumeGrid{Space:d,Values:make([]float64,512)}
for i:=range src.Values {src.Values[i]=.1}
src.Values[3+8*(3+8*3)]=-.8
v,err:=(VolumeWarp{Amplitude:0,Frequency:1}).Modify(context.Background(),src)
if err!=nil {t.Fatal(err)}
p:=d.Point(3,3,3)
if math.Abs(v.SignedValue(p)-src.SignedValue(p))>1e-10 {t.Fatal("zero deformation changed interior")}
e:=testEngine(t)
recipe:=HybridRecipe()
recipe.Domain.Resolution=32
c,err:=e.Evaluate(context.Background(),recipe,"",nil)
if err!=nil || !c.Valid || c.Metrics.Triangles==0 {t.Fatalf("hybrid evaluation: %v %v",c,err)}
if len(c.Nodes)!=5 || len(c.Artifacts)!=3 {t.Fatal("wrong compositional artifacts",c.Nodes,c.Artifacts)}
}