← Back to team overview

kicad-developers team mailing list archive

Re: Converting KiCAD to metric units: The approach

 

>> I think a nice way to do a conversion is to call a function.  I don't think
>> hiding the conversion in an operator overload or constructor is superior to
>> calling an obvious conversion function such as:
>>
>> 1) mm2internal()
>> 2) mil2internal()
>> 3) internal2mm()
>> 4) internal2mil()
> Hey, don't you joking? It's the one of the worst examples of code reuse i ever 
> seen. I dont even realise if it better than just hardcoding a constant. :)
>
> Say, we have set of usable units. They are (currently used):
> - mm;
> - inch;
> - mil;
> - decimil;
> You suggest me to write 8 functions, twice the number of units! EIGHT 
> functions doing nothing more than multiply or divide by constant.
:
> First better soultion is to make this function take second parameter
>     unit2internal(what, unit_from); // use it like x = (x_in_mm,millimeter)
>     internal2unit(what, unit_to);
>
> Only two functions (and several constants, one per unit).


Vladimir,

The above sounds good.  Vladimir, I see your point to the two argument function,
and find it superior to my suggestion.

I see these being used in the load and save to disk functions.

Let us know if you still want to do this work.  There will be no surprise to
learn that you are no longer interested.  That would be typical in the open
source world where egos get damaged, and volunteers decide how they are to do
anything, and if they are to do anything.

Vladimir, if you are no longer interested, at least be communicative.   Perhaps
someone else can then put off painting his/her back porch a little longer.   Not
sure who that would be however.  So we do appreciate your efforts, sincerely.


I think the feature you have brought up will be a valuable enhancement.


According to Jean-Pierre's concerns, some of our integer arithmetic may begin to
overflow as written.  We do have the option of putting a cast to 64 bit int on
the temporary products of those calculations.  This is a fairly simple solution
in some cases, and causes a modern day computer no grief.


#define SCALE_WHAT  ?  // a constant int number


int x;
int y;
int z;

x =  ( int64_t( y ) * SCALE_WHAT ) / z;


Wayne has pointed out that MS VC++ has no int64_t stuff and that there is a wx
equivalent to assist poor little Microsoft.  Maybe we should simply define
int64_t, if MS VC++, so we can use a int standard type rather than the wxInt64
(or whatever it is).    Unnecessary allegience to wx over pure C++ seems
unnecessary.



Thanks,

Dick




Follow ups

References