Is there any need for different metrics to allow the user to specify how they want distance measured? #231
Replies: 2 comments 5 replies
-
To clarify the world of open source and community collaboration is brand new to me. Anything I worked on before was proprietary. So if this have posted this in the wrong place or I should go about this another way, fill me in. To clarify my initial comment I was thinking about something like this. public static class Metric
{
public static double DistanceTo(Point2D p1, Point2D p2, MetricType metric)
{
switch (metric)
{
case Euclidean:
return DistanceToEuclidean(p1, p2);
case Manhattan:
return DistanceToManhattan(p1, p2);
....
}
private static double DistanceToEuclidean(Point2D p1, Point p2)
{
return Math.Sqrt( (p1.X - p2.X)*(p1.X - p.X) +(p1.Y - p2.Y)*(p1.Y - p.Y));
}
private static double DistanceToManhattan(Point2D p1, Point p2)
{
return Math.Abs(p1.X - p2.X) + Math.Abs(p1.Y - p2.Y)
}
} then include pubic enum MetricType
{
Euclidean,
Manhattan,
Chebyshev,
Discrete,
LP_1,
LP_2,
...
} I think it can be implemented by adding another parameter to any function computing or comparing point to point distances provided it defaults to the current behavior. For example For Point2D public double DistanceTo(Point2D otherPoint, MetricType metric = MetricType.Euclidean)
{
return Metric.DistanceTo(p1, p2, metric)
} Anyone see any value in this or is this too much for this library and NetTopologySuite is the place to go if you need this sort of fine |
Beta Was this translation helpful? Give feedback.
-
I am not really familiar with NetTopologySuite and where it's used. It seems we have a discrepancy here, in which one the one hand we calculate distances based on the Euclidean metric but we use the tolerance for equality comparison in a Manhattan-style metric. I don't know where this might cause problems to be honest. |
Beta Was this translation helpful? Give feedback.
-
As it is the specified tolerance is compared against against each coordinate individually, almost a Manhattan metric, Does anyone have any input on adding the ability to allow a user to specify the metric of their choice? When I first saw the code I was a little surprised that tolerance was not compared against the Euclidean distance between points. It could be added without breaking code by adding an enum value as an additional parameter to the Equals functions that defaults to the current method but would allow a user to specify whatever metric they choose.
I'm not versed enough to even know for sure if the floating point type pass the triangle inequality for sure, I just don't know enough about the IEEE standard and how rounding errors would effect this.
Beta Was this translation helpful? Give feedback.
All reactions