minor rework and filter dimensions

This commit is contained in:
Aleksandr Trushkin
2024-02-13 21:19:39 +03:00
parent f4bff6fe01
commit 3c3b4e4670
13 changed files with 969 additions and 780 deletions

View File

@ -49,7 +49,15 @@ type Dimension struct {
Kind DimensionKind
}
func (d Dimension) IsZero() bool {
return d.Value == 0
}
func (d Dimension) MarshalText() ([]byte, error) {
if d.Value == 0 && d.Kind == DimensionKindUnspecified {
return nil, nil
}
value := strconv.FormatFloat(d.Value, 'f', 4, 64) + " " + d.Kind.String()
return []byte(value), nil
}
@ -114,10 +122,14 @@ func ParseDimention(value string, locale DimensionLocale) (Dimension, error) {
return out, nil
}
func NewMilimeterDimension(value float64) Dimension {
func NewCentimeterDimensionOrEmpty(value float64) Dimension {
if value == 0 {
return Dimension{}
}
return Dimension{
Value: value,
Kind: DimensionKindMilimeter,
Kind: DimensionKindCentimeter,
}
}