Skip to content

Commit

Permalink
reduce cyclomatic complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek committed Apr 19, 2018
1 parent 3adbb96 commit cb20350
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 130 deletions.
47 changes: 26 additions & 21 deletions core/Ellipsoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,28 @@ func (e *Ellipsoid) doSize(ps *support.ProjString) error {
return nil
}

func (e *Ellipsoid) doShape(ps *support.ProjString) error {
func getShapeKey(ps *support.ProjString) (bool, string, float64) {

P := e
/* Check which shape key is specified */

keys := []string{"rf", "f", "es", "e", "b"}

/* Check which shape key is specified */
found := false
var foundValue float64
var foundKey string
for _, key := range keys {
value, ok := ps.GetAsFloat(key)
if ok {
found = true
foundKey = key
foundValue = value
break
return true, key, value
}
}

return false, "", 0.0
}

func (e *Ellipsoid) doShape(ps *support.ProjString) error {

P := e

found, foundKey, foundValue := getShapeKey(ps)

/* Not giving a shape parameter means selecting a sphere, unless shape */
/* has been selected previously via ellps=xxx */
if !found && P.Es != 0 {
Expand Down Expand Up @@ -409,6 +411,18 @@ func (e *Ellipsoid) doShape(ps *support.ProjString) error {
return nil
}

func getSphereKey(ps *support.ProjString) string {
keys := []string{"R_A", "R_V", "R_a", "R_g", "R_h", "R_lat_a", "R_lat_g"}

for _, key := range keys {
if ps.ContainsKey(key) {
return key
}
}

return ""
}

func (e *Ellipsoid) doSpherification(ps *support.ProjString) error {

P := e
Expand All @@ -420,19 +434,10 @@ func (e *Ellipsoid) doSpherification(ps *support.ProjString) error {
const RV4 = 5 / 72.
const RV6 = 55 / 1296.

keys := []string{"R_A", "R_V", "R_a", "R_g", "R_h", "R_lat_a", "R_lat_g"}

var key string
found := false
for _, key = range keys {
if ps.ContainsKey(key) {
found = true
break
}
}
key := getSphereKey(ps)

/* No spherification specified? Then we're done */
if !found {
if key == "" {
return nil
}

Expand Down
Loading

0 comments on commit cb20350

Please sign in to comment.