-
Notifications
You must be signed in to change notification settings - Fork 14
/
polyline.go
61 lines (48 loc) · 1.27 KB
/
polyline.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package tilepix
import (
"fmt"
log "github.com/sirupsen/logrus"
)
/*
___ _ _ _
| _ \___| |_ _| (_)_ _ ___
| _/ _ \ | || | | | ' \/ -_)
|_| \___/_|\_, |_|_|_||_\___|
|__/
*/
// PolyLine is a TMX file structure representing a Tiled Polyline.
type PolyLine struct {
Points string `xml:"points,attr"`
decodedPoints []*Point
// parentMap is the map which contains this object
parentMap *Map
}
// Decode will return a slice of points which make up this polyline.
func (p *PolyLine) Decode() ([]*Point, error) {
if p.decodedPoints == nil {
dp, err := decodePoints(p.Points)
if err != nil {
log.WithError(err).Error("PolyLine.Decode: could not decode points")
return nil, err
}
p.decodedPoints = dp
}
return p.decodedPoints, nil
}
func (p *PolyLine) String() string {
return fmt.Sprintf("Polyline{Points: %v}", p.decodedPoints)
}
func (p *PolyLine) setParent(m *Map) {
p.parentMap = m
// Must decode points before they can be set
_, err := p.Decode()
if err != nil {
log.WithError(err).Error("PolyLine.setParent: could not decode points")
return
}
for _, dp := range p.decodedPoints {
dp.setParent(m)
// We have to flip the Y co-ordinate here because the `tilepix.Point` is only used to provide `pixel.Vec`s
dp.flipY()
}
}