Better naming and comments.

This commit is contained in:
Alex Roitman 2019-06-13 13:33:07 -07:00
parent 2d83e18934
commit eb214cb889
1 changed files with 25 additions and 25 deletions

View File

@ -19,7 +19,7 @@ const (
tokenRParen = ")" tokenRParen = ")"
) )
// areaExpression is either an object or operator+children // areaExpression is (maybe negated) either an spatial object or operator + children (other expressions).
type areaExpression struct { type areaExpression struct {
negate bool negate bool
obj geojson.Object obj geojson.Object
@ -63,7 +63,7 @@ func (e *areaExpression) maybeNegate(val bool) bool {
return val return val
} }
// Methods for testing an areaExpression against the spatial object // Methods for testing an areaExpression against the spatial object.
func (e *areaExpression) testObject( func (e *areaExpression) testObject(
o geojson.Object, o geojson.Object,
objObjTest func(o1, o2 geojson.Object) bool, objObjTest func(o1, o2 geojson.Object) bool,
@ -115,31 +115,31 @@ func (e *areaExpression) Within(o geojson.Object) bool {
return e.maybeNegate(e.rawWithin(o)) return e.maybeNegate(e.rawWithin(o))
} }
// Methods for testing an areaExpression against another areaExpression // Methods for testing an areaExpression against another areaExpression.
func (e *areaExpression) testExpression( func (e *areaExpression) testExpression(
oe *areaExpression, other *areaExpression,
exprObjTest func(ae *areaExpression, ob geojson.Object) bool, exprObjTest func(ae *areaExpression, ob geojson.Object) bool,
rawExprExprTest func(ae1, ae2 *areaExpression) bool, rawExprExprTest func(ae1, ae2 *areaExpression) bool,
exprExprTest func(ae1, ae2 *areaExpression) bool, exprExprTest func(ae1, ae2 *areaExpression) bool,
) bool { ) bool {
if oe.negate { if other.negate {
e2 := &areaExpression{negate: !e.negate, obj: e.obj, op: e.op, children: e.children} oppositeExp := &areaExpression{negate: !e.negate, obj: e.obj, op: e.op, children: e.children}
oe2 := &areaExpression{negate: false, obj: oe.obj, op: oe.op, children: oe.children} nonNegateOther := &areaExpression{obj: other.obj, op: other.op, children: other.children}
return exprExprTest(e2, oe2) return exprExprTest(oppositeExp, nonNegateOther)
} }
if oe.obj != nil { if other.obj != nil {
return exprObjTest(e, oe.obj) return exprObjTest(e, other.obj)
} }
switch oe.op { switch other.op {
case AND: case AND:
for _, c := range oe.children { for _, c := range other.children {
if !rawExprExprTest(e, c) { if !rawExprExprTest(e, c) {
return false return false
} }
} }
return true return true
case OR: case OR:
for _, c := range oe.children { for _, c := range other.children {
if rawExprExprTest(e, c) { if rawExprExprTest(e, c) {
return true return true
} }
@ -149,38 +149,38 @@ func (e *areaExpression) testExpression(
return false return false
} }
func (e *areaExpression) rawIntersectsExpr(oe *areaExpression) bool { func (e *areaExpression) rawIntersectsExpr(other *areaExpression) bool {
return e.testExpression( return e.testExpression(
oe, other,
(*areaExpression).rawIntersects, (*areaExpression).rawIntersects,
(*areaExpression).rawIntersectsExpr, (*areaExpression).rawIntersectsExpr,
(*areaExpression).IntersectsExpr) (*areaExpression).IntersectsExpr)
} }
func (e *areaExpression) rawWithinExpr(oe *areaExpression) bool { func (e *areaExpression) rawWithinExpr(other *areaExpression) bool {
return e.testExpression( return e.testExpression(
oe, other,
(*areaExpression).rawWithin, (*areaExpression).rawWithin,
(*areaExpression).rawWithinExpr, (*areaExpression).rawWithinExpr,
(*areaExpression).WithinExpr) (*areaExpression).WithinExpr)
} }
func (e *areaExpression) rawContainsExpr(oe *areaExpression) bool { func (e *areaExpression) rawContainsExpr(other *areaExpression) bool {
return e.testExpression( return e.testExpression(
oe, other,
(*areaExpression).rawContains, (*areaExpression).rawContains,
(*areaExpression).rawContainsExpr, (*areaExpression).rawContainsExpr,
(*areaExpression).ContainsExpr) (*areaExpression).ContainsExpr)
} }
func (e *areaExpression) IntersectsExpr(oe *areaExpression) bool { func (e *areaExpression) IntersectsExpr(other *areaExpression) bool {
return e.maybeNegate(e.rawIntersectsExpr(oe)) return e.maybeNegate(e.rawIntersectsExpr(other))
} }
func (e *areaExpression) WithinExpr(oe *areaExpression) bool { func (e *areaExpression) WithinExpr(other *areaExpression) bool {
return e.maybeNegate(e.rawWithinExpr(oe)) return e.maybeNegate(e.rawWithinExpr(other))
} }
func (e *areaExpression) ContainsExpr(oe *areaExpression) bool { func (e *areaExpression) ContainsExpr(other *areaExpression) bool {
return e.maybeNegate(e.rawContainsExpr(oe)) return e.maybeNegate(e.rawContainsExpr(other))
} }