kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #41173
Re: VECTOR2I and VECTOR2D
On 6/22/19 3:09 AM, Greg Smith wrote:
Adding two points and dividing by two results in a point that is
minimally equidistant from both points (I.e. The midpoint of the line
formed by the points).
While it is true that you can add two point coordinates and multiply by
scalar 0.5 to get the midpoint, this is not true in the general case for
arbitrary scalar multipliers. However, calculating the vector distance
between two points, multiplying the vector by a scalar, then adding the
resulting vector distance to the first point /does/ work in the general
case.
This is exactly the sort of bug that can be avoided by not allowing
arbitrary operations on random vectors.
If finding the midpoint between two points proves to be a common
operation, and is found to be too costly to implement in the general
fashion, then a special method for determining the midpoint can be
provided that calculates it in the optimal fashion.
Follow ups
References