• 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/layers_to_layers.go
1
package observer
2

3
import (
4
        "github.com/mlange-42/ark/ecs"
5
)
6

7
// LayersToLayers creates an observer that serves as adapter from a [MatrixLayers] observer to a [GridLayers] observer.
8
func LayersToLayers(obs MatrixLayers, origin *[2]float64, cellsize *[2]float64) GridLayers {
2✔
9
        m := layersToLayers{
2✔
10
                Observer: obs,
2✔
11
        }
2✔
12
        if origin != nil {
3✔
13
                m.Origin = *origin
1✔
14
        }
1✔
15
        if cellsize == nil {
3✔
16
                m.CellSize = [2]float64{1, 1}
1✔
17
        } else {
2✔
18
                m.CellSize = *cellsize
1✔
19
        }
1✔
20
        return &m
2✔
21
}
22

23
// layersToLayers is an observer that serves as adapter from a [MatrixLayers] observer to a [GridLayers] observer.
24
type layersToLayers struct {
25
        Observer MatrixLayers // The wrapped MatrixLayers observers.
26
        Origin   [2]float64   // Origin. Optional, defaults to (0, 0)
27
        CellSize [2]float64   // CellSize. Optional, defaults to (1, 1).
28
}
29

30
// Initialize the child observer.
31
func (o *layersToLayers) Initialize(w *ecs.World) {
1✔
32
        o.Observer.Initialize(w)
1✔
33
}
1✔
34

35
// Update the child observer.
36
func (o *layersToLayers) Update(w *ecs.World) {
1✔
37
        o.Observer.Update(w)
1✔
38
}
1✔
39

40
// Dims returns the matrix dimensions.
41
func (o *layersToLayers) Dims() (int, int) {
1✔
42
        return o.Observer.Dims()
1✔
43
}
1✔
44

45
// Layers returns the number of layers.
46
func (o *layersToLayers) Layers() int {
1✔
47
        return o.Observer.Layers()
1✔
48
}
1✔
49

50
// Values for the current model tick.
51
func (o *layersToLayers) Values(w *ecs.World) [][]float64 {
1✔
52
        return o.Observer.Values(w)
1✔
53
}
1✔
54

55
// X axis coordinates.
56
func (o *layersToLayers) X(c int) float64 {
1✔
57
        return o.Origin[0] + o.CellSize[0]*float64(c)
1✔
58
}
1✔
59

60
// Y axis coordinates.
61
func (o *layersToLayers) Y(r int) float64 {
1✔
62
        return o.Origin[1] + o.CellSize[1]*float64(r)
1✔
63
}
1✔
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