Mercurial > gemma
annotate pkg/common/floats.go @ 5311:72d3b8321ed0 zpg-exception
Fixed broken migration which erased the style of the modified GeoServer view.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 02 Jun 2021 16:55:00 +0200 |
parents | 4ca884dfc470 |
children |
rev | line source |
---|---|
4256
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2019 by via donau |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
13 |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
14 package common |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
15 |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
16 import "sort" |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
17 |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
18 // DedupFloat64s sorts arr and removes duplicates in place. |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
19 // Returns a sub slice of arr only containing the unique elements. |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
20 func DedupFloat64s(arr []float64) []float64 { |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
21 sort.Float64s(arr) |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
22 for i := 1; i < len(arr); { |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
23 if arr[i-1] == arr[i] { |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
24 copy(arr[i:], arr[i+1:]) |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
25 arr = arr[:len(arr)-1] |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
26 } else { |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
27 i++ |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
28 } |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
29 } |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
30 return arr |
4ca884dfc470
Prevent heights duplicates in iso line calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff
changeset
|
31 } |