Skip to content

Commit 5731d50

Browse files
committed
Web page icons, slice by plane fixes, New Nodes: vector3/Normalize+NormalizeArray
1 parent 05cc635 commit 5731d50

File tree

15 files changed

+302
-152
lines changed

15 files changed

+302
-152
lines changed

generator/app_server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func (as *AppServer) Handler(indexFile string) (*http.ServeMux, error) {
120120

121121
fs := http.FileServer(http.FS(fSys))
122122
mux.Handle("/js/", fs)
123+
mux.Handle("/icons/", fs)
123124

124125
var graphSaver *GraphSaver
125126
if as.autosave {
44.9 KB
Loading
206 KB
Loading
40.4 KB
Loading
740 Bytes
Loading
2.27 KB
Loading

generator/html/icons/favicon.ico

15 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}

generator/html/server.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
<head>
55
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
6-
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-touch-icon.png">
8+
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
9+
<link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png">
10+
<link rel="manifest" href="/icons/site.webmanifest">
711
<meta charset="utf-8">
812
<title>{{.Title}}</title>
913
<style>

math/nodes_test.go

Lines changed: 67 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -7,110 +7,38 @@ import (
77

88
"github.com/EliCDavis/polyform/math"
99
"github.com/EliCDavis/polyform/nodes"
10+
"github.com/EliCDavis/polyform/nodes/nodetest"
1011
"github.com/stretchr/testify/assert"
1112
)
1213

13-
type NodeAssert interface {
14-
Assert(t *testing.T, node nodes.Node)
15-
}
16-
17-
type AssertPortValue[T any] struct {
18-
Port string
19-
Value T
20-
}
21-
22-
func (apv AssertPortValue[T]) Assert(t *testing.T, node nodes.Node) {
23-
out := nodes.GetNodeOutputPort[T](node, apv.Port).Value()
24-
assert.Equal(t, apv.Value, out)
25-
}
26-
27-
type AssertNodeDescription struct {
28-
Description string
29-
}
30-
31-
func (apv AssertNodeDescription) Assert(t *testing.T, node nodes.Node) {
32-
if describable, ok := node.(nodes.Describable); ok {
33-
assert.Equal(t, apv.Description, describable.Description())
34-
return
35-
}
36-
t.Error("node does not contain a description")
37-
}
38-
39-
type AssertNodeInputPortDescription struct {
40-
Port string
41-
Description string
42-
}
43-
44-
func (apv AssertNodeInputPortDescription) Assert(t *testing.T, node nodes.Node) {
45-
outputs := node.Inputs()
46-
47-
port, ok := outputs[apv.Port]
48-
if !ok {
49-
t.Error("node does not contain input port", apv.Port)
50-
return
51-
}
52-
53-
describable, ok := port.(nodes.Describable)
54-
if !ok {
55-
t.Error("node input port does not contain a description", apv.Port)
56-
return
57-
}
58-
59-
assert.Equal(t, apv.Description, describable.Description())
60-
}
61-
62-
func NewAssertInputPortDescription(port, description string) AssertNodeInputPortDescription {
63-
return AssertNodeInputPortDescription{
64-
Port: port,
65-
Description: description,
66-
}
67-
}
68-
69-
func NewAssertPortValue[T any](port string, value T) AssertPortValue[T] {
70-
return AssertPortValue[T]{
71-
Port: port,
72-
Value: value,
73-
}
74-
}
75-
76-
func NewNode[T any](data T) nodes.Node {
77-
return &nodes.Struct[T]{
78-
Data: data,
79-
}
80-
}
81-
82-
func NewPortValue[T any](data T) nodes.Output[T] {
83-
return nodes.ConstOutput[T]{Val: data}
84-
}
85-
8614
func TestNodes(t *testing.T) {
8715
tests := map[string]struct {
8816
node nodes.Node
89-
assertions []NodeAssert
17+
assertions []nodetest.Assertion
9018
}{
9119
"Square: 1 => 1": {
92-
node: NewNode(math.SquareNode{
93-
In: NewPortValue(1.),
20+
node: nodetest.NewNode(math.SquareNode{
21+
In: nodetest.NewPortValue(1.),
9422
}),
95-
assertions: []NodeAssert{
96-
NewAssertPortValue("Out", 1.),
23+
assertions: []nodetest.Assertion{
24+
nodetest.NewAssertPortValue("Out", 1.),
9725
},
9826
},
9927
"Square: 10 => 100": {
100-
node: NewNode(math.SquareNode{
101-
In: NewPortValue(10.),
28+
node: nodetest.NewNode(math.SquareNode{
29+
In: nodetest.NewPortValue(10.),
10230
}),
103-
assertions: []NodeAssert{
104-
NewAssertPortValue("Out", 100.),
31+
assertions: []nodetest.Assertion{
32+
nodetest.NewAssertPortValue("Out", 100.),
10533
},
10634
},
10735
"Round: nil => 0": {
10836
node: &nodes.Struct[math.RoundNodeData]{
10937
Data: math.RoundNodeData{},
11038
},
111-
assertions: []NodeAssert{
112-
NewAssertPortValue("Int", 0),
113-
NewAssertPortValue("Float", 0.),
39+
assertions: []nodetest.Assertion{
40+
nodetest.NewAssertPortValue("Int", 0),
41+
nodetest.NewAssertPortValue("Float", 0.),
11442
},
11543
},
11644
"Round: 1.23 => 1": {
@@ -119,94 +47,94 @@ func TestNodes(t *testing.T) {
11947
In: nodes.ConstOutput[float64]{Val: 1.23},
12048
},
12149
},
122-
assertions: []NodeAssert{
123-
NewAssertPortValue("Int", 1),
124-
NewAssertPortValue("Float", 1.),
50+
assertions: []nodetest.Assertion{
51+
nodetest.NewAssertPortValue("Int", 1),
52+
nodetest.NewAssertPortValue("Float", 1.),
12553
},
12654
},
12755
"Circumference: nil => 0": {
128-
node: NewNode(math.CircumferenceNode{}),
129-
assertions: []NodeAssert{
130-
NewAssertPortValue("Int", 0),
131-
NewAssertPortValue("Float", 0.),
56+
node: nodetest.NewNode(math.CircumferenceNode{}),
57+
assertions: []nodetest.Assertion{
58+
nodetest.NewAssertPortValue("Int", 0),
59+
nodetest.NewAssertPortValue("Float", 0.),
13260
},
13361
},
13462
"Circumference: 2 => 4pi": {
135-
node: NewNode(math.CircumferenceNode{
136-
Radius: NewPortValue(2.),
63+
node: nodetest.NewNode(math.CircumferenceNode{
64+
Radius: nodetest.NewPortValue(2.),
13765
}),
138-
assertions: []NodeAssert{
139-
NewAssertPortValue("Int", 13),
140-
NewAssertPortValue("Float", 4.*gomath.Pi),
141-
AssertNodeDescription{Description: "Circumference of a circle"},
66+
assertions: []nodetest.Assertion{
67+
nodetest.NewAssertPortValue("Int", 13),
68+
nodetest.NewAssertPortValue("Float", 4.*gomath.Pi),
69+
nodetest.AssertNodeDescription{Description: "Circumference of a circle"},
14270
},
14371
},
14472
"One": {
145-
node: NewNode(math.OneNode{}),
146-
assertions: []NodeAssert{
147-
NewAssertPortValue("Int", 1),
148-
NewAssertPortValue("Float 64", 1.),
149-
AssertNodeDescription{Description: "Just the number 1"},
73+
node: nodetest.NewNode(math.OneNode{}),
74+
assertions: []nodetest.Assertion{
75+
nodetest.NewAssertPortValue("Int", 1),
76+
nodetest.NewAssertPortValue("Float 64", 1.),
77+
nodetest.AssertNodeDescription{Description: "Just the number 1"},
15078
},
15179
},
15280
"Zero": {
153-
node: NewNode(math.ZeroNode{}),
154-
assertions: []NodeAssert{
155-
NewAssertPortValue("Int", 0),
156-
NewAssertPortValue("Float 64", 0.),
157-
AssertNodeDescription{Description: "Just the number 0"},
81+
node: nodetest.NewNode(math.ZeroNode{}),
82+
assertions: []nodetest.Assertion{
83+
nodetest.NewAssertPortValue("Int", 0),
84+
nodetest.NewAssertPortValue("Float 64", 0.),
85+
nodetest.AssertNodeDescription{Description: "Just the number 0"},
15886
},
15987
},
16088
"Double: nil => 0": {
161-
node: NewNode(math.DoubleNode[float64]{}),
162-
assertions: []NodeAssert{
163-
NewAssertPortValue("Int", 0),
164-
NewAssertPortValue("Float 64", 0.),
89+
node: nodetest.NewNode(math.DoubleNode[float64]{}),
90+
assertions: []nodetest.Assertion{
91+
nodetest.NewAssertPortValue("Int", 0),
92+
nodetest.NewAssertPortValue("Float 64", 0.),
16593
},
16694
},
16795
"Double: 2 => 4": {
168-
node: NewNode(math.DoubleNode[float64]{
169-
In: NewPortValue(2.),
96+
node: nodetest.NewNode(math.DoubleNode[float64]{
97+
In: nodetest.NewPortValue(2.),
17098
}),
171-
assertions: []NodeAssert{
172-
NewAssertPortValue("Int", 4),
173-
NewAssertPortValue("Float 64", 4.),
174-
AssertNodeDescription{Description: "Doubles the number provided"},
175-
NewAssertInputPortDescription("In", "The number to double"),
99+
assertions: []nodetest.Assertion{
100+
nodetest.NewAssertPortValue("Int", 4),
101+
nodetest.NewAssertPortValue("Float 64", 4.),
102+
nodetest.AssertNodeDescription{Description: "Doubles the number provided"},
103+
nodetest.NewAssertInputPortDescription("In", "The number to double"),
176104
},
177105
},
178106
"Half: nil => 0": {
179-
node: NewNode(math.HalfNode[float64]{}),
180-
assertions: []NodeAssert{
181-
NewAssertPortValue("Int", 0),
182-
NewAssertPortValue("Float 64", 0.),
107+
node: nodetest.NewNode(math.HalfNode[float64]{}),
108+
assertions: []nodetest.Assertion{
109+
nodetest.NewAssertPortValue("Int", 0),
110+
nodetest.NewAssertPortValue("Float 64", 0.),
183111
},
184112
},
185113
"Half: 4 => 2": {
186-
node: NewNode(math.HalfNode[float64]{
187-
In: NewPortValue(4.),
114+
node: nodetest.NewNode(math.HalfNode[float64]{
115+
In: nodetest.NewPortValue(4.),
188116
}),
189-
assertions: []NodeAssert{
190-
NewAssertPortValue("Int", 2),
191-
NewAssertPortValue("Float 64", 2.),
192-
AssertNodeDescription{Description: "Divides the number in half"},
193-
NewAssertInputPortDescription("In", "The number to halve"),
117+
assertions: []nodetest.Assertion{
118+
nodetest.NewAssertPortValue("Int", 2),
119+
nodetest.NewAssertPortValue("Float 64", 2.),
120+
nodetest.AssertNodeDescription{Description: "Divides the number in half"},
121+
nodetest.NewAssertInputPortDescription("In", "The number to halve"),
194122
},
195123
},
196124
"Negate: nil => 0": {
197-
node: NewNode(math.NegateNode[float64]{}),
198-
assertions: []NodeAssert{
199-
NewAssertPortValue("Out", 0.),
200-
NewAssertInputPortDescription("In", "The number to take the additive inverse of"),
201-
AssertNodeDescription{Description: "The additive inverse of an element x, denoted −x, is the element that when added to x, yields the additive identity, 0"},
125+
node: nodetest.NewNode(math.NegateNode[float64]{}),
126+
assertions: []nodetest.Assertion{
127+
nodetest.NewAssertPortValue("Out", 0.),
128+
nodetest.NewAssertInputPortDescription("In", "The number to take the additive inverse of"),
129+
nodetest.AssertNodeDescription{Description: "The additive inverse of an element x, denoted −x, is the element that when added to x, yields the additive identity, 0"},
202130
},
203131
},
204132
"Negate: 4 => -4": {
205-
node: NewNode(math.NegateNode[float64]{
206-
In: NewPortValue(4.),
133+
node: nodetest.NewNode(math.NegateNode[float64]{
134+
In: nodetest.NewPortValue(4.),
207135
}),
208-
assertions: []NodeAssert{
209-
NewAssertPortValue("Out", -4.),
136+
assertions: []nodetest.Assertion{
137+
nodetest.NewAssertPortValue("Out", -4.),
210138
},
211139
},
212140
}

0 commit comments

Comments
 (0)