-
-
Notifications
You must be signed in to change notification settings - Fork 38
Basic Planar fns, Simplifier interface #6
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
Conversation
Added some handy planar functions, and defined an Interface for Simplifers. This way we can add and change out simplifiers easily.
I know there aren't enough tests on this currently, but was not expecting to put it up quite yet. But it should help you @jasonsurratt. |
Pull Request Test Coverage Report for Build 49
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at my questions/comments. I may not understand the intent in some cases.
planar/planar.go
Outdated
m1, _, _ := Slope([2][2]float64{pt2, pt1}) | ||
m2, _, _ := Slope([2][2]float64{pt3, pt1}) | ||
// 6 digits of prec | ||
d, _ := new(big.Float).SetPrec(6*4).Sub(big.NewFloat(m2), big.NewFloat(m1)).Float64() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you limiting this to 6 digits of precision when float64 supports ~15?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this seems to be returning the difference in slope between the three lines, not the angle between the three lines. I think if you want angle that would be calling atan2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SetPrec is really me guessing. I think I will just remove it, when I have a better answer we can add it.
planar/planar.go
Outdated
} | ||
|
||
// 4 digits of precision | ||
d, _ := new(big.Float).SetPrec(16).Mul(big.NewFloat(dist), semimajor).Float64() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 digits of precision, or 16? What does this operation achieve over dist * semimajor
?
planar/planar.go
Outdated
math.Cos(rpt2x)* | ||
(math.Pow(math.Sin(disty/2), 2)), | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI This is the hoot haversine implementation I mentioned previously. Looks like I was getting about 9cm precision using float64 with Haversine (likely plenty for your needs).
There are differences in the implementation, but there are a bunch of ways to get to the same answer and I'm sure your tests will reveal it if there are any problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I can use hootenanny's implementation as it's GPL'd.
planar/planar.go
Outdated
dist := 2 * math.Asin( | ||
math.Sqrt( | ||
|
||
(math.Pow(math.Sin(distx/2), 2)+math.Cos(rpt1x))* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to replace math.Pow(x, 2)
with x * x
. Likely quite a bit faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
planar/planar.go
Outdated
func (hs Haversine) PerpendicularDistance(line [2][2]float64, point [2]float64) float64 { | ||
dist := hs.Distance(line[0], point) | ||
angle := Angle3Pts(line[0], line[1], point) | ||
return math.Abs(dist * math.Sin(angle)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading this right, this seems to be mixing planar operations (Angle3Pts) and spherical operations (hs.Distance). Based on the comment, I think you're looking for Cross-track distance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm not calculating the Angle3Pts correctly. I should be using a radian_slop function instead of a euclidian slop function. Good catch.
line: [2][2]float64{{0, 0}, {10, 10}}, | ||
m: 1, | ||
b: 0, | ||
defined: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With all the test framework in place, you'll want to add some more tests. For instance, this won't catch a case where x/y get swapped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I don't have very good tests in there right now. I was still in the process of converting over the code, and did not have time to add all the test cases. This was just to get the framework for the test in place, to make it easy to add more.
planar/planar.go
Outdated
deltaX := line[1][0] - line[0][0] | ||
deltaY := line[1][1] - line[0][1] | ||
denom := math.Abs((deltaY * point[0]) - (deltaX * point[1]) + (line[1][0] * line[0][1]) - (line[1][1] * line[0][0])) | ||
num := math.Sqrt(math.Pow(deltaY, 2) + math.Pow(deltaX, 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why math.Pow(deltaY, 2)
instead of deltaY * deltaY
?
planar/planar.go
Outdated
if num == 0 { | ||
return 0 | ||
} | ||
return denom / num |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you swapped the naming of num & denom.
|
||
type PointLineDistanceFunc func(line [2][2]float64, point [2]float64) float64 | ||
|
||
// PerpendicularDistance provides the distance between a line and a point in Euclidean space. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a reference to: https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Line defined by two points" section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
added NewTileLatLon funcitonnality added an iterator function RangeFamilyAt to Tile Added tests and bug fixes for lat/lon -> tile conversion Added reference to the formula for PerpendicularDisance. Added references to docs used for algos. Removing spherical functions as they are not correct.
Added some handy planar functions, and defined an Interface for
Simplifers. This way we can add and change out simplifiers easily.