Mike Fowler <mike@mlfowler.com> writes:
> On 10/11/10 10:08, Jin wrote:
>> The distance of the horizontal lseg and the point on that is inaccurate.
> From my digging it appears that this is returning the distance between
> the first point in the line and the individual point.
I didn't look into the code yet, but that would match the result.
> The distance of the horizontal lseg and the point is calculated against
> the first point in the line. Should this be calculated against the
> midpoint of the line instead?
The standard geometrical notion of distance between a point and a line
is that you drop the perpendicular from the point to the line, and the
length of that perpendicular is the distance. Now, in the case of a
line segment, the perpendicular might not intersect the segment:
x
|
|
|
+ o-----------------o
in which case I think the distance from the point to the segment's
nearer endpoint is a reasonable definition. In some quick testing
it seems to work that way for every case except a perfectly horizontal
line segment. So I'm thinking somebody fat-fingered the corner case
where the perpendicular would have infinite slope, and it is falling
through to the "take the nearer endpoint" case when it shouldn't.
regards, tom lane