-
-
Notifications
You must be signed in to change notification settings - Fork 38
Port constrained #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Port constrained #88
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ cover.out | |
.idea.cover | ||
.cover | ||
.idea/ | ||
output.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,116 @@ | ||
package cmp | ||
|
||
import ( | ||
"sync/atomic" | ||
|
||
"github.com/go-spatial/geom" | ||
) | ||
|
||
// HiPrecision is a high precision for comparator | ||
const HiPrecision = 0.000000001 | ||
|
||
// HiCMP is a high precision comparator | ||
var HiCMP = New(HiPrecision) | ||
|
||
// compare will have six digits of precision by default. | ||
// This is equivalent to : | ||
// var compare = NewForNumPrecision(6) | ||
var compare = Compare{ | ||
Tolerance: 0.000001, | ||
// It was calculated as math.Float64bits(1.000001) - math.Float64bits(1.0) | ||
BitTolerance: 4503599627, | ||
var compare = func() (av atomic.Value) { | ||
av.Store(NewForNumPrecision(6)) | ||
return av | ||
}() | ||
|
||
// DefaultCompare returns the current default compare | ||
func DefaultCompare() Compare { | ||
return compare.Load().(Compare) | ||
} | ||
|
||
// SetDefault will set the default for the package. | ||
func SetDefault(cmp Compare) Compare { | ||
old := compare.Load().(Compare) | ||
compare.Store(cmp) | ||
return old | ||
} | ||
|
||
// Tolerances returns the default tolerance values | ||
func Tolerances() (float64, int64) { return compare.Tolerances() } | ||
func Tolerances() (float64, int64) { return DefaultCompare().Tolerances() } | ||
|
||
// Float compares two floats to see if they are within 0.00001 from each other. This is the best way to compare floats. | ||
func Float(f1, f2 float64) bool { return compare.Float(f1, f2) } | ||
func Float(f1, f2 float64) bool { return DefaultCompare().Float(f1, f2) } | ||
|
||
// FloatSlice compare two sets of float slices. | ||
func FloatSlice(f1, f2 []float64) bool { return compare.FloatSlice(f1, f2) } | ||
func FloatSlice(f1, f2 []float64) bool { return DefaultCompare().FloatSlice(f1, f2) } | ||
|
||
// Extent will check to see if the Extents's are the same. | ||
func Extent(extent1, extent2 [4]float64) bool { return compare.Extent(extent1, extent2) } | ||
func Extent(extent1, extent2 [4]float64) bool { return DefaultCompare().Extent(extent1, extent2) } | ||
|
||
// GeomExtent will check to see if geom.BoundingBox's are the same. | ||
func GeomExtent(extent1, extent2 geom.Extenter) bool { return compare.GeomExtent(extent1, extent2) } | ||
func GeomExtent(extent1, extent2 geom.Extenter) bool { | ||
return DefaultCompare().GeomExtent(extent1, extent2) | ||
} | ||
|
||
// PointLess returns weather p1 is < p2 by first comparing the X values, and if they are the same the Y values. | ||
func PointLess(p1, p2 [2]float64) bool { return compare.PointLess(p1, p2) } | ||
func PointLess(p1, p2 [2]float64) bool { return DefaultCompare().PointLess(p1, p2) } | ||
|
||
// PointEqual returns weather both points have the same value for x,y. | ||
func PointEqual(p1, p2 [2]float64) bool { return compare.PointEqual(p1, p2) } | ||
func PointEqual(p1, p2 [2]float64) bool { return DefaultCompare().PointEqual(p1, p2) } | ||
|
||
// GeomPointEqual returns weather both points have the same value for x,y. | ||
func GeomPointEqual(p1, p2 geom.Point) bool { return compare.GeomPointEqual(p1, p2) } | ||
func GeomPointEqual(p1, p2 geom.Point) bool { return DefaultCompare().GeomPointEqual(p1, p2) } | ||
|
||
// MultiPointEqual will check to see see if the given slices are the same. | ||
func MultiPointEqual(p1, p2 [][2]float64) bool { return compare.MultiPointEqual(p1, p2) } | ||
func MultiPointEqual(p1, p2 [][2]float64) bool { return DefaultCompare().MultiPointEqual(p1, p2) } | ||
|
||
// LineStringEqual given two LineStrings it will check to see if the line | ||
// strings have the same points in the same order. | ||
func LineStringEqual(v1, v2 [][2]float64) bool { return compare.LineStringEqual(v1, v2) } | ||
func LineStringEqual(v1, v2 [][2]float64) bool { return DefaultCompare().LineStringEqual(v1, v2) } | ||
|
||
// MultiLineEqual will return if the two multilines are equal. | ||
func MultiLineEqual(ml1, ml2 [][][2]float64) bool { return compare.MultiLineEqual(ml1, ml2) } | ||
func MultiLineEqual(ml1, ml2 [][][2]float64) bool { return DefaultCompare().MultiLineEqual(ml1, ml2) } | ||
|
||
// PolygonEqual will return weather the two polygons are the same. | ||
func PolygonEqual(ply1, ply2 [][][2]float64) bool { return compare.PolygonEqual(ply1, ply2) } | ||
func PolygonEqual(ply1, ply2 [][][2]float64) bool { return DefaultCompare().PolygonEqual(ply1, ply2) } | ||
|
||
// PointerEqual will check to see if the x and y of both points are the same. | ||
func PointerEqual(geo1, geo2 geom.Pointer) bool { return compare.PointerEqual(geo1, geo2) } | ||
func PointerEqual(geo1, geo2 geom.Pointer) bool { return DefaultCompare().PointerEqual(geo1, geo2) } | ||
|
||
// PointerLess returns weather p1 is < p2 by first comparing the X values, and if they are the same the Y values. | ||
func PointerLess(p1, p2 geom.Pointer) bool { return compare.PointLess(p1.XY(), p2.XY()) } | ||
func PointerLess(p1, p2 geom.Pointer) bool { return DefaultCompare().PointLess(p1.XY(), p2.XY()) } | ||
|
||
// MultiPointerEqual will check to see if the provided multipoints have the same points. | ||
func MultiPointerEqual(geo1, geo2 geom.MultiPointer) bool { | ||
return compare.MultiPointerEqual(geo1, geo2) | ||
return DefaultCompare().MultiPointerEqual(geo1, geo2) | ||
} | ||
|
||
// LineStringerEqual will check to see if the two linestrings passed to it are equal, if | ||
// there lengths are both the same, and the sequence of points are in the same order. | ||
// The points don't have to be in the same index point in both line strings. | ||
func LineStringerEqual(geo1, geo2 geom.LineStringer) bool { | ||
return compare.LineStringerEqual(geo1, geo2) | ||
return DefaultCompare().LineStringerEqual(geo1, geo2) | ||
} | ||
|
||
// MultiLineStringerEqual will check to see if the 2 MultiLineStrings pass to it | ||
// are equal. This is done by converting them to lineStrings and using MultiLineEqual | ||
func MultiLineStringerEqual(geo1, geo2 geom.MultiLineStringer) bool { | ||
return compare.MultiLineStringerEqual(geo1, geo2) | ||
return DefaultCompare().MultiLineStringerEqual(geo1, geo2) | ||
} | ||
|
||
// PolygonerEqual will check to see if the Polygoners are the same, by checking | ||
// if the linearRings are equal. | ||
func PolygonerEqual(geo1, geo2 geom.Polygoner) bool { return compare.PolygonerEqual(geo1, geo2) } | ||
func PolygonerEqual(geo1, geo2 geom.Polygoner) bool { | ||
return DefaultCompare().PolygonerEqual(geo1, geo2) | ||
} | ||
|
||
// MultiPolygonerEqual will check to see if the given multipolygoners are the same, by check each of the constitute | ||
// polygons to see if they match. | ||
func MultiPolygonerEqual(geo1, geo2 geom.MultiPolygoner) bool { | ||
return compare.MultiPolygonerEqual(geo1, geo2) | ||
return DefaultCompare().MultiPolygonerEqual(geo1, geo2) | ||
} | ||
|
||
// CollectionerEqual will check if the two collections are equal based on length | ||
// then if each geometry inside is equal. Therefor order matters. | ||
func CollectionerEqual(col1, col2 geom.Collectioner) bool { | ||
return compare.CollectionerEqual(col1, col2) | ||
return DefaultCompare().CollectionerEqual(col1, col2) | ||
} | ||
|
||
// GeometryEqual checks if the two geometries are of the same type and then | ||
// calls the type method to check if they are equal | ||
func GeometryEqual(g1, g2 geom.Geometry) bool { return compare.GeometryEqual(g1, g2) } | ||
func GeometryEqual(g1, g2 geom.Geometry) bool { return DefaultCompare().GeometryEqual(g1, g2) } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.