kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #43450
Re: Internal units in the KiCAD source code
-
To:
kicad-developers@xxxxxxxxxxxxxxxxxxx
-
From:
Simon Richter <Simon.Richter@xxxxxxxxxx>
-
Date:
Thu, 13 Feb 2020 18:11:53 +0100
-
Autocrypt:
addr=Simon.Richter@xxxxxxxxxx; prefer-encrypt=mutual; keydata= mQINBEsFLRIBEAC7462Btbl5lLGjG+qgeNHfBUBiZ+q47M1xMC9hAQ5nbCSBqxH7eSinz4u9 DSNp4VT5pTkAcnLj2/f3d4Tis7LVRXA5hWS6aHVKvtk0k7TweXzU5nqGBvQUuwEzyx/TOQ8r wx+IhjnIgh5g0enhVVNw3DoTXRHtEqQ6twAMj5WccNy9DApFC07OchJz92/b747juTRL3p0E WQnss8sZ4MKQ7fZhOh6W2QDgvG7ZCKx2UWiRytDzVY+QgCe6oLHG0kIw7rAgqtosSNGZkPZ8 Iav1UVxHDAzOHvyGC48FARvSqExnpJqQU+UK5nYacwH4uoL+Su+un/8DMtpfG8m3+DGiX2Ng DSfvIXOQczaCLRTr9U7ma5v7Y+7sWLO7lbIDH6UYovo2C13iTa8qoSIJa1rM6BbwFntAMXtp LIo+DABepHeswy3ulfb9EmfcS73O/ML+LqlayHUMkwUGx/RsE+ko3asfWmKIMeH9vs7uO2za ZKu/zmIAHb6Zi1i2+47kAKIy/gyFeOPkT8vhRMgZlZ7qSKrKl+5jfWwGInGxePabE4TC4nVJ TZn2Sa0+zb3/h74RLeFpNBhWMH2A0ayIC88mQrzDNSOieaPX+7EjfLBc0n/CUW75hLe3YlFu 0nx/Qit4SyGZP+xN0VYFUw+iVz54+1Io6gQuZHpDwc+nGPBijwARAQABtChTaW1vbiBSaWNo dGVyIDxTaW1vbi5SaWNodGVyQGhvZ3lyb3MuZGU+iQI3BBMBCAAhBQJLBS3AAhsBBQsJCAcD BRUKCQgLBRYCAwEAAh4BAheAAAoJEOv2eoRqq+NUaTEP/2/JJR8wq60oN95ZJ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SE+oelfK
-
In-reply-to:
<91e5ad08-5df1-7661-0681-8e9e8285522d@gmx.at>
-
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.2
Hi,
On 13.02.20 16:06, Thomas Pointhuber wrote:
> The solution discussed was to move to 64bit and to use
> constexpr/templates handling unit conversion. So a programmer can for
> example enter 2mm and the compiler automatically converts it into the
> internal unit like nm.
> I'm still in favour of improving this. The same with angles.
Angles have to go first, because we have many different representations
based on lengths, and several of the 2D representations have overloaded
"rotate" functions that consume an angle -- so if we were to add new
length/vector/size/distance types, we'd need to add more "rotate"
functions for all of these as well.
For angles, this is somewhat complicated by the fact that we have three
different representations (radians, degrees, tenths of a degree), and
the latter can also be floating point or integer. Adding new classes is
somewhat[1] straightforward[2], but the code actually using it is full
of magic multiplications and divisions with factors like 0.1, 10,
M_PI/1800, 1800/M_PI and so on, all of which are scalar so they aren't
caught by making the new type deliberately incompatible.
Once angles are done, the same thing can be done for lengths, where,
thankfully, the magic values are somewhat confined to the headers.
One thing I really like is that we can express things like
angle a = 90_deg;
and in places where we need a scalar, such as the file reader/writer
code, we can then use
out << ( a / deg );
to write a value in degrees ("deg" is a global constexpr angle object
with a value of M_PI/180. :) ).
For the foreseeable future I'm going to concentrate on net ties, so if
anyone wants to run wild with the angle code, go ahead.
Simon
[1] lol
[2] https://gitlab.com/GyrosGeier/kicad/-/commits/refactor/angle
Attachment:
signature.asc
Description: OpenPGP digital signature
References