-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: BoxSize to common type XyDim
- Loading branch information
1 parent
b0c4ed3
commit a03e37d
Showing
4 changed files
with
82 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package xydim | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type XyDimInt struct { | ||
X int | ||
Y int | ||
} | ||
|
||
func (d *XyDimInt) String() string { | ||
return fmt.Sprintf("%dx%d", d.X, d.Y) | ||
} | ||
|
||
func (d *XyDimInt) Set(s string) error { | ||
parts := strings.Split(s, "x") | ||
if len(parts) != 2 { | ||
return fmt.Errorf("must be WxH") | ||
} | ||
|
||
var err1, err2 error | ||
d.X, err1 = strconv.Atoi(parts[0]) | ||
d.Y, err2 = strconv.Atoi(parts[1]) | ||
|
||
if err1 != nil || err2 != nil { | ||
return fmt.Errorf("int conversion error") | ||
} | ||
return nil | ||
} | ||
|
||
type XyDimFloat struct { | ||
X float32 | ||
Y float32 | ||
} | ||
|
||
func (d *XyDimFloat) String() string { | ||
return fmt.Sprintf("%gx%g", d.X, d.Y) | ||
} | ||
|
||
func (d *XyDimFloat) Set(s string) error { | ||
parts := strings.Split(s, "x") | ||
if len(parts) != 2 { | ||
return fmt.Errorf("must be WxH") | ||
} | ||
|
||
x, err1 := strconv.ParseFloat(parts[0], 32) | ||
y, err2 := strconv.ParseFloat(parts[1], 32) | ||
|
||
if err1 != nil || err2 != nil { | ||
return fmt.Errorf("float conversion error") | ||
} | ||
|
||
d.X = float32(x) | ||
d.Y = float32(y) | ||
return nil | ||
} |