• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark-tools / 13609383102

01 Mar 2025 10:23PM CUT coverage: 98.438% (-1.6%) from 100.0%
13609383102

push

github

web-flow
Add observers and reporters (#2)

287 of 297 new or added lines in 9 files covered. (96.63%)

630 of 640 relevant lines covered (98.44%)

133.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/observer/matrix_to_layers.go
1
package observer
2

3
import "github.com/mlange-42/ark/ecs"
4

5
// MatrixToLayers creates an observer that serves as adapter from multiple [Matrix] observers to a [MatrixLayers] observer.
6
func MatrixToLayers(obs ...Matrix) MatrixLayers {
6✔
7
        if len(obs) == 0 {
7✔
8
                panic("no observers given")
1✔
9
        }
10
        return &matrixToLayers{
5✔
11
                Observers: obs,
5✔
12
        }
5✔
13
}
14

15
// matrixToLayers is an observer that serves as adapter from multiple [Matrix] observers to a [MatrixLayers] observer.
16
type matrixToLayers struct {
17
        Observers []Matrix
18
        values    [][]float64
19
}
20

21
// Initialize the child observer.
22
func (o *matrixToLayers) Initialize(w *ecs.World) {
3✔
23
        for i, obs := range o.Observers {
11✔
24
                obs.Initialize(w)
8✔
25
                if i == 0 {
11✔
26
                        continue
3✔
27
                }
28
                obs0 := o.Observers[0]
5✔
29
                w1, h1 := obs0.Dims()
5✔
30
                w2, h2 := obs.Dims()
5✔
31

5✔
32
                if w1 != w2 || h1 != h2 {
6✔
33
                        panic("grids for layers have different dimensions")
1✔
34
                }
35
        }
36

37
        o.values = make([][]float64, len(o.Observers))
2✔
38
}
39

40
// Update the child observer.
41
func (o *matrixToLayers) Update(w *ecs.World) {
2✔
42
        for _, obs := range o.Observers {
8✔
43
                obs.Update(w)
6✔
44
        }
6✔
45
}
46

47
// Dims returns the matrix dimensions.
48
func (o *matrixToLayers) Dims() (int, int) {
2✔
49
        return o.Observers[0].Dims()
2✔
50
}
2✔
51

52
// Layers returns the number of layers.
53
func (o *matrixToLayers) Layers() int {
2✔
54
        return len(o.Observers)
2✔
55
}
2✔
56

57
// Values for the current model tick.
58
func (o *matrixToLayers) Values(w *ecs.World) [][]float64 {
2✔
59
        for i, obs := range o.Observers {
8✔
60
                o.values[i] = obs.Values(w)
6✔
61
        }
6✔
62
        return o.values
2✔
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc