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

mlange-42 / ark / 13593874277

28 Feb 2025 06:06PM CUT coverage: 96.872% (+2.1%) from 94.795%
13593874277

Pull #79

github

web-flow
Merge 94da96c6d into 10315654e
Pull Request #79: Relation getters for queries and maps

118 of 118 new or added lines in 6 files covered. (100.0%)

8 existing lines in 1 file now uncovered.

3562 of 3677 relevant lines covered (96.87%)

50530.93 hits per line

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

96.15
/ecs/relation.go
1
package ecs
2

3
import "fmt"
4

5
var relationType = typeOf[Relation]()
6

7
// Relation is a marker for entity relation components.
8
// It must be embedded as first field of a component that represent an entity relation
9
// (see the example).
10
//
11
// Entity relations allow for fast queries using entity relationships.
12
// E.g. to iterate over all entities that are the child of a certain parent entity.
13
// Currently, each entity can only have a single relation component.
14
type Relation struct{}
15

16
type relationID struct {
17
        component ID
18
        target    Entity
19
}
20

21
// RelationIndex specifies an entity relation target by component index.
22
//
23
// Note that the index refers to the position of the component in the generics
24
// of e.g. a [Map2] or [Filter2].
25
// This should not be confused with component IDs as obtained by [ComponentID]!
26
type RelationIndex struct {
27
        index  uint8
28
        target Entity
29
}
30

31
// Rel creates a new RelationIndex.
32
func Rel(index int, target Entity) RelationIndex {
391✔
33
        return RelationIndex{
391✔
34
                index:  uint8(index),
391✔
35
                target: target,
391✔
36
        }
391✔
37
}
391✔
38

39
type relations []RelationIndex
40

41
func (r relations) toRelations(reg *componentRegistry, ids []ID, out []relationID) []relationID {
2,203✔
42
        out = out[:0]
2,203✔
43
        for _, rel := range r {
2,586✔
44
                id := ids[rel.index]
383✔
45
                if !reg.IsRelation[id.id] {
383✔
46
                        panic(fmt.Sprintf("component at index %d is not a relation component", rel.index))
×
47
                }
48
                out = append(out, relationID{
383✔
49
                        component: id,
383✔
50
                        target:    rel.target,
383✔
51
                })
383✔
52
        }
53
        return out
2,203✔
54
}
55

56
type relationEntities []Entity
57

58
func (r relationEntities) toRelation(id ID, out []relationID) []relationID {
496,572✔
59
        out = out[:0]
496,572✔
60
        for _, rel := range r {
496,605✔
61
                out = append(out, relationID{
33✔
62
                        component: id,
33✔
63
                        target:    rel,
33✔
64
                })
33✔
65
        }
33✔
66
        return out
496,572✔
67
}
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