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

mlange-42 / ark-tools / 13944569950

19 Mar 2025 10:41AM CUT coverage: 98.445%. Remained the same
13944569950

push

github

web-flow
Upgrade to Ark v0.4.0 (#9)

633 of 643 relevant lines covered (98.44%)

140.44 hits per line

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

100.0
/observer/matrix_to_grid.go
1
package observer
2

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

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

21
// matrixToGrid is an observer that serves as adapter from a [Matrix] observer to a [Grid] observer.
22
type matrixToGrid struct {
23
        Observer Matrix     // The wrapped Matrix observer.
24
        Origin   [2]float64 // Origin. Optional, defaults to (0, 0)
25
        CellSize [2]float64 // CellSize. Optional, defaults to (1, 1).
26
}
27

28
// Initialize the child observer.
29
func (o *matrixToGrid) Initialize(w *ecs.World) {
7✔
30
        o.Observer.Initialize(w)
7✔
31

7✔
32
        if o.CellSize[0] == 0 {
13✔
33
                o.CellSize[0] = 1
6✔
34
        }
6✔
35
        if o.CellSize[1] == 0 {
13✔
36
                o.CellSize[1] = 1
6✔
37
        }
6✔
38
}
39

40
// Update the child observer.
41
func (o *matrixToGrid) Update(w *ecs.World) {
4✔
42
        o.Observer.Update(w)
4✔
43
}
4✔
44

45
// Dims returns the matrix dimensions.
46
func (o *matrixToGrid) Dims() (int, int) {
8✔
47
        return o.Observer.Dims()
8✔
48
}
8✔
49

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

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

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