-
Notifications
You must be signed in to change notification settings - Fork 14
/
geometry.go
executable file
·52 lines (38 loc) · 990 Bytes
/
geometry.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
package gopi
import (
"fmt"
)
/*
This file contains interface defininitons for graphics geometry:
* Points
* Rectangles
Dimensions are defined in float32 rather than uint to support
vector graphics.
*/
////////////////////////////////////////////////////////////////////////////////
// TYPES
type Point struct {
X, Y float32
}
type Size struct {
W, H float32
}
////////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
var (
ZeroPoint = Point{0, 0}
ZeroSize = Size{0, 0}
)
////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
func (p1 Point) Equals(p2 Point) bool {
return p1.X == p2.X && p1.Y == p2.Y
}
////////////////////////////////////////////////////////////////////////////////
// STRINGIFY
func (p Point) String() string {
return fmt.Sprintf("gopi.Point{ %.1f,%.1f }", p.X, p.Y)
}
func (s Size) String() string {
return fmt.Sprintf("gopi.Size{ %.1f,%.1f }", s.W, s.H)
}