mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
f32: implement fmt.Stringer to Point and Rectangle
Signed-off-by: Wagner Riffel <wgrriffel@gmail.com>
This commit is contained in:
committed by
Elias Naur
parent
4bbc6379ed
commit
390949790e
+13
@@ -9,17 +9,30 @@ corner with the axes extending right and down.
|
|||||||
*/
|
*/
|
||||||
package f32
|
package f32
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
// A Point is a two dimensional point.
|
// A Point is a two dimensional point.
|
||||||
type Point struct {
|
type Point struct {
|
||||||
X, Y float32
|
X, Y float32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String return a string representation of p.
|
||||||
|
func (p Point) String() string {
|
||||||
|
return "(" + strconv.FormatFloat(float64(p.X), 'f', -1, 32) +
|
||||||
|
"," + strconv.FormatFloat(float64(p.Y), 'f', -1, 32) + ")"
|
||||||
|
}
|
||||||
|
|
||||||
// A Rectangle contains the points (X, Y) where Min.X <= X < Max.X,
|
// A Rectangle contains the points (X, Y) where Min.X <= X < Max.X,
|
||||||
// Min.Y <= Y < Max.Y.
|
// Min.Y <= Y < Max.Y.
|
||||||
type Rectangle struct {
|
type Rectangle struct {
|
||||||
Min, Max Point
|
Min, Max Point
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String return a string representation of r.
|
||||||
|
func (r Rectangle) String() string {
|
||||||
|
return r.Min.String() + "-" + r.Max.String()
|
||||||
|
}
|
||||||
|
|
||||||
// Add return the point p+p2.
|
// Add return the point p+p2.
|
||||||
func (p Point) Add(p2 Point) Point {
|
func (p Point) Add(p2 Point) Point {
|
||||||
return Point{X: p.X + p2.X, Y: p.Y + p2.Y}
|
return Point{X: p.X + p2.X, Y: p.Y + p2.Y}
|
||||||
|
|||||||
Reference in New Issue
Block a user