1
0
Fork 0
mirror of https://github.com/Luzifer/sii.git synced 2024-10-18 05:14:19 +00:00

Support negative float values

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-12-11 18:38:05 +01:00
parent a26d79eefb
commit ab32292dfe
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 3 additions and 3 deletions

View file

@ -15,7 +15,7 @@ import (
// float2-4 => [2]float - [4]float // float2-4 => [2]float - [4]float
var placementRegexp = regexp.MustCompile(`^\(([0-9.]+|&[0-9a-f]+), ([0-9.]+|&[0-9a-f]+), ([0-9.]+|&[0-9a-f]+)\) \(([0-9.]+|&[0-9a-f]+); ([0-9.]+|&[0-9a-f]+), ([0-9.]+|&[0-9a-f]+), ([0-9.]+|&[0-9a-f]+)\)$`) var placementRegexp = regexp.MustCompile(`^\(([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+)\) \(([0-9.-]+|&[0-9a-f]+); ([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+)\)$`)
// Placement contains 7 floats: (x, y, z) (w; x, y, z) // Placement contains 7 floats: (x, y, z) (w; x, y, z)
type Placement [7]float32 type Placement [7]float32

View file

@ -113,7 +113,7 @@ func genericUnmarshal(in []byte, out interface{}, unit *Unit) error {
switch typeField.Type.Len() { switch typeField.Type.Len() {
case 3: case 3:
grps := regexp.MustCompile(`^\(([0-9.]+|&[0-9a-f]+), ([0-9.]+|&[0-9a-f]+), ([0-9.]+|&[0-9a-f]+)\)$`). grps := regexp.MustCompile(`^\(([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+), ([0-9.-]+|&[0-9a-f]+)\)$`).
FindSubmatch(getSingleValue(in, attributeName)) FindSubmatch(getSingleValue(in, attributeName))
var v [3]float32 var v [3]float32

View file

@ -17,7 +17,7 @@ func float2sii(f float32) ([]byte, error) {
err error err error
) )
if math.Floor(float64(f)) == float64(f) && f < 1000 { if math.Floor(float64(f)) == float64(f) && f < 1000 && f > -1000 {
return []byte(fmt.Sprintf("%.0f", f)), nil return []byte(fmt.Sprintf("%.0f", f)), nil
} }