← Back to team overview

kicad-developers team mailing list archive

Re: VECTOR2I and VECTOR2D

 

On 22/06/2019 17:41, Reece R. Pollack wrote:
> 
> 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.

I've never experienced a bug caused by mixing points/vectors together,
at least in the math code. For passing coordinates/measurements from/to
the GUI it might make sense to create custom types. Moreover, most if
not all geometry libraries I've known used the same class for points and
vectors. Single class for both is IMHO Occam's razor approach. As Seth
already remarked, I would like to hear a solid argument for splitting
point/vector classes, otherwise it looks like bikeshedding to me.

Tom

PS1. I'm surprised no one yet noticed the VECTOR2<> class has public x/y
 members, which is an unforgivable violation of the tenets of classical
OO design :-)

PS2. There are some more serious OOD violations in KiCad codebase. Would
anybody here volunteer to refactor the diamond in EDA_TEXT derivatives,
DRAWSEGMENT/EDGE_MODULE classes or global variables in eeschema?


Follow ups

References