Mercurial > gemma
diff pkg/common/attributes.go @ 2563:dc4fae4bdb8f
Expose axis snapping tolerance to users
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 08 Mar 2019 19:15:47 +0100 |
parents | 2c67c51d57ad |
children | 8c5df0f3562e |
line wrap: on
line diff
--- a/pkg/common/attributes.go Fri Mar 08 18:57:58 2019 +0100 +++ b/pkg/common/attributes.go Fri Mar 08 19:15:47 2019 +0100 @@ -4,12 +4,13 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // License-Filename: LICENSES/AGPL-3.0.txt // -// Copyright (C) 2018 by via donau +// Copyright (C) 2018, 2019 by via donau // – Österreichische Wasserstraßen-Gesellschaft mbH // Software engineering by Intevation GmbH // // Author(s): // * Sascha L. Teichmann <sascha.teichmann@intevation.de> +// * Tom Gottfried <tom.gottfried@intevation.de> package common @@ -158,6 +159,24 @@ return ca.Set(key, v) } +func (ca Attributes) Float(key string) (float64, bool) { + s, found := ca.Get(key) + if !found { + return 0, false + } + f, err := strconv.ParseFloat(s, 64) + if err != nil { + log.Printf("error: %v\n", err) + return 0, false + } + return f, true +} + +func (ca Attributes) SetFloat(key string, value float64) bool { + v := strconv.FormatFloat(value, 'e', -1, 64) + return ca.Set(key, v) +} + func (ca Attributes) Duration(key string) (time.Duration, bool) { s, found := ca.Get(key) if !found {