123456789101112131415161718192021222324252627282930313233343536 |
- package main
- import (
- "fmt"
- "strconv"
- "strings"
- )
- type Vec2 struct {
- X, Y float64
- }
- func (v *Vec2) String() string {
- return fmt.Sprintf("%f %f", v.X, v.Y)
- }
- func (v *Vec2) Parse(line string) error {
- parts := strings.Split(line, " ")
- have_x := false
- for _, p := range parts {
- if CanFloat(p) || CanInt(p) {
- val, err := strconv.ParseFloat(p, 64)
- if err != nil {
- return err
- }
- if !have_x {
- v.X = val
- have_x = true
- } else {
- v.Y = val
- break
- }
- }
- }
- return nil
- }
|