Skip to content

Commit

Permalink
fixed error names (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek authored Apr 20, 2018
1 parent d175991 commit 8d121cd
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 55 deletions.
6 changes: 3 additions & 3 deletions core/ConvertLPToXY.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (op *ConvertLPToXY) forwardPrepare(lp *CoordLP) (*CoordLP, error) {
sys := op.System

if math.MaxFloat64 == lp.Lam {
return nil, merror.New(merror.ErrCoordinateError)
return nil, merror.New(merror.CoordinateError)
}

/* Check validity of angular input coordinates */
Expand All @@ -105,7 +105,7 @@ func (op *ConvertLPToXY) forwardPrepare(lp *CoordLP) (*CoordLP, error) {
t = lp.Phi - support.PiOverTwo
}
if t > epsLat || lp.Lam > 10 || lp.Lam < -10 {
return nil, merror.New(merror.ErrLatOrLonExceededLimit)
return nil, merror.New(merror.LatOrLonExceededLimit)
}

/* Clamp latitude to -90..90 degree range */
Expand Down Expand Up @@ -177,7 +177,7 @@ func (op *ConvertLPToXY) inversePrepare(coo *CoordXY) (*CoordXY, error) {
sys := op.System

if coo.X == math.MaxFloat64 {
return nil, merror.New(merror.ErrInvalidXOrY)
return nil, merror.New(merror.InvalidXOrY)
}

/* Handle remaining possible input types */
Expand Down
26 changes: 13 additions & 13 deletions core/Ellipsoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (e *Ellipsoid) doEllps(ps *support.ProjString) error {

/* Then look up the right size and shape parameters from the builtin list */
if name == "" {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}

ellps, ok := support.EllipsoidsTable[name]
Expand Down Expand Up @@ -317,7 +317,7 @@ func (e *Ellipsoid) doShape(ps *support.ProjString) error {
case "rf":
P.Rf = foundValue
if P.Rf == math.MaxFloat64 {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
if P.Rf == 0 {
return merror.New(merror.ReverseFlatteningIsZero)
Expand All @@ -329,10 +329,10 @@ func (e *Ellipsoid) doShape(ps *support.ProjString) error {
case "f":
P.F = foundValue
if P.F == math.MaxFloat64 {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
if P.F == 0 {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
P.Rf = 1 / P.F
P.Es = 2*P.F - P.F*P.F
Expand All @@ -341,7 +341,7 @@ func (e *Ellipsoid) doShape(ps *support.ProjString) error {
case "es":
P.Es = foundValue
if P.Es == math.MaxFloat64 {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
if P.Es == 1 {
return merror.New(merror.EccentricityIsOne)
Expand All @@ -351,10 +351,10 @@ func (e *Ellipsoid) doShape(ps *support.ProjString) error {
case "e":
P.E = foundValue
if P.E == math.MaxFloat64 {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
if P.E == 0 {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
if P.E == 1 {
return merror.New(merror.EccentricityIsOne)
Expand All @@ -365,7 +365,7 @@ func (e *Ellipsoid) doShape(ps *support.ProjString) error {
case "b":
P.B = foundValue
if P.B == math.MaxFloat64 {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
if P.B == 0 {
return merror.New(merror.EccentricityIsOne)
Expand All @@ -377,12 +377,12 @@ func (e *Ellipsoid) doShape(ps *support.ProjString) error {
P.Es = 2*P.F - P.F*P.F

default:
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)

}

if P.Es < 0 {
return merror.New(merror.ErrEsLessThanZero)
return merror.New(merror.EsLessThanZero)
}

return nil
Expand Down Expand Up @@ -448,14 +448,14 @@ func (e *Ellipsoid) doSpherification(ps *support.ProjString) error {
case "R_lat_a", "R_lat_g":
v, ok := ps.GetAsString(key)
if !ok {
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)
}
t, err := support.DMSToR(v)
if err != nil {
return err
}
if math.Abs(t) > support.PiOverTwo {
return merror.New(merror.ErrRefRadLargerThan90)
return merror.New(merror.RefRadLargerThan90)
}
t = math.Sin(t)
t = 1 - P.Es*t*t
Expand All @@ -466,7 +466,7 @@ func (e *Ellipsoid) doSpherification(ps *support.ProjString) error {
}

default:
return merror.New(merror.ErrInvalidArg)
return merror.New(merror.InvalidArg)

}

Expand Down
12 changes: 6 additions & 6 deletions core/System.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (sys *System) readUnits(vertical bool) (float64, float64, error) {
if ok {
u, ok := support.UnitsTable[name]
if !ok {
return 0.0, 0.0, merror.New(merror.ErrUnknownUnit)
return 0.0, 0.0, merror.New(merror.UnknownUnit)
}
s = u.ToMetersS
}
Expand All @@ -383,7 +383,7 @@ func (sys *System) readUnits(vertical bool) (float64, float64, error) {
return 0.0, 0.0, merror.New(merror.InvalidProjectionSyntax, s)
}
if (factor <= 0.0) || (1.0/factor == 0.0) {
return 0.0, 0.0, merror.New(merror.ErrUnitFactorLessThanZero)
return 0.0, 0.0, merror.New(merror.UnitFactorLessThanZero)
}

if ratio {
Expand Down Expand Up @@ -420,7 +420,7 @@ func (sys *System) processMisc() error {
/* when correcting longitudes around it */
/* The test is written this way to error on long_wrap_center "=" NaN */
if !(math.Abs(sys.LongWrapCenter) < 10.0*support.TwoPi) {
return merror.New(merror.ErrLatOrLonExceededLimit)
return merror.New(merror.LatOrLonExceededLimit)
}
}

Expand Down Expand Up @@ -483,7 +483,7 @@ func (sys *System) processScaling() error {
sys.K0 = 1.0
}
if sys.K0 <= 0.0 {
return merror.New(merror.ErrKLessThanZero)
return merror.New(merror.KLessThanZero)
}

return nil
Expand Down Expand Up @@ -537,13 +537,13 @@ func (sys *System) processAxis() error {
axisLegal := "ewnsud"
axisArg, _ := sys.ProjString.GetAsString("axis")
if len(axisArg) != 3 {
return merror.New(merror.ErrAxis)
return merror.New(merror.Axis)
}

if !strings.ContainsAny(axisArg[0:1], axisLegal) ||
!strings.ContainsAny(axisArg[1:2], axisLegal) ||
!strings.ContainsAny(axisArg[2:3], axisLegal) {
return merror.New(merror.ErrAxis)
return merror.New(merror.Axis)
}

/* TODO: it would be nice to validate we don't have on axis repeated */
Expand Down
45 changes: 22 additions & 23 deletions merror/error_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,26 @@ var (
ReverseFlatteningIsZero = "reverse flattening (rf) is zero"
EccentricityIsOne = "eccentricity is one"
ToleranceCondition = "tolerance condition error"

ProjValueMissing = "proj value missing in string"
NoSuchDatum = "no such datum"
NotYetSupported = "not yet supported" // TODO
ErrInvalidArg = "ERR_INVALID_ARG"
ErrEsLessThanZero = "ERR_ES_LESS_THAN_ZERO"
ErrRefRadLargerThan90 = "ERR_REF_RAD_LARGER_THAN_90"
ErrInvalidDMS = "ErrInvalidDMS"
ErrEllipsoidUseRequired = "ERR_ELLIPSOID_USE_REQUIRED"
ErrInvalidUTMZone = "ERR_INVALID_UTM_ZONE"
ErrLatOrLonExceededLimit = "ERR_LAT_OR_LON_EXCEED_LIMIT"
ErrUnknownUnit = "ERR_UNKNOWN_UNIT_ID"
ErrUnitFactorLessThanZero = "ERR_UNIT_FACTOR_LESS_THAN_0"
ErrAxis = "ERR_AXIS"
ErrKLessThanZero = "ERR_K_LESS_THAN_ZERO"
ErrCoordinateError = "ErrCoordinateError"
ErrInvalidXOrY = "ERR_INVALID_X_OR_Y"
ErrConicLatEqual = "ErrConicLatEqual"
ErrAeaSetupFailed = "ErrAeaSetupFailed"
ErrInvMlfn = "ErrInvMlfn"
ErrAeaProjString = "ErrAeaProjString"
ErrLatTSLargerThan90 = "ErrLatTSLargerThan90"
ErrPhi2 = "ErrPhi2"
ProjValueMissing = "proj value missing"
NoSuchDatum = "no such datum"
NotYetSupported = "not yet supported" // TODO
InvalidArg = "invalid argument in proj string"
EsLessThanZero = "ES is less than zero"
RefRadLargerThan90 = "ref rad is greater than 90"
InvalidDMS = "invalid DMS (degrees-minutes-seconds)"
EllipsoidUseRequired = "use of ellipsoid required"
InvalidUTMZone = "invalid UTM zone"
LatOrLonExceededLimit = "lat or lon limit exceeded"
UnknownUnit = "unknown unit"
UnitFactorLessThanZero = "unit factor less than zero"
Axis = "invalid axis configuration"
KLessThanZero = "K is less than zero"
CoordinateError = "invalid coordinates"
InvalidXOrY = "invalid X or Y"
ConicLatEqual = "Conic lat is equal"
AeaSetupFailed = "setup for aea projection failed"
InvMlfn = "invalid mlfn computation"
AeaProjString = "invalid projection string for aea"
LatTSLargerThan90 = "lat ts is greater than 90"
Phi2 = "invalid phi2 computation"
)
4 changes: 2 additions & 2 deletions operations/Aea.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (aea *Aea) localSetup(sys *core.System) error {
PE := P.Ellipsoid

if math.Abs(Q.phi1+Q.phi2) < eps10 {
return merror.New(merror.ErrConicLatEqual)
return merror.New(merror.ConicLatEqual)
}
sinphi = math.Sin(Q.phi1)
Q.n = sinphi
Expand All @@ -132,7 +132,7 @@ func (aea *Aea) localSetup(sys *core.System) error {
m2 = support.Msfn(sinphi, cosphi, PE.Es)
ml2 = support.Qsfn(sinphi, PE.E, PE.OneEs)
if ml2 == ml1 {
return merror.New(merror.ErrAeaSetupFailed)
return merror.New(merror.AeaSetupFailed)
}

Q.n = (m1*m1 - m2*m2) / (ml2 - ml1)
Expand Down
8 changes: 4 additions & 4 deletions operations/EtMerc.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (xxx *EtMerc) localSetup(P *core.System) error {
PE := P.Ellipsoid

if PE.Es <= 0 {
return merror.New(merror.ErrEllipsoidUseRequired)
return merror.New(merror.EllipsoidUseRequired)
}

/* flattening */
Expand Down Expand Up @@ -341,10 +341,10 @@ func (xxx *EtMerc) etmercSetup(op *core.System) error {
func (xxx *EtMerc) utmSetup(op *core.System) error {

if op.Ellipsoid.Es == 0.0 {
return merror.New(merror.ErrEllipsoidUseRequired)
return merror.New(merror.EllipsoidUseRequired)
}
if op.Lam0 < -1000.0 || op.Lam0 > 1000.0 {
return merror.New(merror.ErrInvalidUTMZone)
return merror.New(merror.InvalidUTMZone)
}

op.Y0 = 0.0
Expand All @@ -358,7 +358,7 @@ func (xxx *EtMerc) utmSetup(op *core.System) error {
if zone > 0 && zone <= 60 {
zone--
} else {
return merror.New(merror.ErrInvalidUTMZone)
return merror.New(merror.InvalidUTMZone)
}
} else { /* nearest central meridian input */
zone = (int)(math.Floor((support.Adjlon(op.Lam0) + support.Pi) * 30. / support.Pi))
Expand Down
2 changes: 1 addition & 1 deletion operations/Merc.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (merc *Merc) mercSetup(sys *core.System) error {
phits = support.DDToR(phits)
phits = math.Abs(phits)
if phits >= support.PiOverTwo {
return merror.New(merror.ErrLatTSLargerThan90)
return merror.New(merror.LatTSLargerThan90)
}
}

Expand Down
2 changes: 1 addition & 1 deletion support/DMS.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func DMSToDD(input string) (float64, error) {

tokens := r.FindStringSubmatch(input)
if tokens == nil {
return 0.0, merror.New(merror.ErrInvalidArg)
return 0.0, merror.New(merror.InvalidArg)
}

sign := tokens[1]
Expand Down
2 changes: 1 addition & 1 deletion support/Mlfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ func InvMlfn(arg float64, es float64, en []float64) (float64, error) {
}
}

return phi, merror.New(merror.ErrInvMlfn)
return phi, merror.New(merror.InvMlfn)
}
2 changes: 1 addition & 1 deletion support/Phi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Phi2(ts, e float64) (float64, error) {
break
}
if i <= 0 {
return 0.0, merror.New(merror.ErrPhi2)
return 0.0, merror.New(merror.Phi2)
}
return Phi, nil
}

0 comments on commit 8d121cd

Please sign in to comment.