aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/ch-go/proto/col_point.go
blob: 0e1549ffeb42427a0a315f075574353f9838dddc (plain) (blame)
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
62
63
package proto

import "github.com/go-faster/errors"

type Point struct {
	X, Y float64
}

// Compile-time assertions for ColPoint.
var (
	_ ColInput        = ColPoint{}
	_ ColResult       = (*ColPoint)(nil)
	_ Column          = (*ColPoint)(nil)
	_ ColumnOf[Point] = (*ColPoint)(nil)
)

type ColPoint struct {
	X, Y ColFloat64
}

func (c *ColPoint) Append(v Point) {
	c.X.Append(v.X)
	c.Y.Append(v.Y)
}

func (c *ColPoint) AppendArr(v []Point) {
	for _, vv := range v {
		c.Append(vv)
	}
}

func (c ColPoint) Row(i int) Point {
	return Point{
		X: c.X.Row(i),
		Y: c.Y.Row(i),
	}
}

func (c ColPoint) Type() ColumnType { return ColumnTypePoint }
func (c ColPoint) Rows() int        { return c.X.Rows() }

func (c *ColPoint) DecodeColumn(r *Reader, rows int) error {
	if err := c.X.DecodeColumn(r, rows); err != nil {
		return errors.Wrap(err, "x")
	}
	if err := c.Y.DecodeColumn(r, rows); err != nil {
		return errors.Wrap(err, "y")
	}
	return nil
}

func (c *ColPoint) Reset() {
	c.X.Reset()
	c.Y.Reset()
}

func (c ColPoint) EncodeColumn(b *Buffer) {
	if b == nil {
		return
	}
	c.X.EncodeColumn(b)
	c.Y.EncodeColumn(b)
}