TraceMaker
C++ API of the engine
Loading...
Searching...
No Matches
units.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2#pragma once
3#include <cmath>
4#include <cstdint>
5
6#include "core/hd.hpp"
7
8namespace tmk {
9
10// Engine coordinate: signed 64-bit nanometres. KiCad's internal unit is also 1 nm, so file
11// round-trips are exact. Millimetres appear only at I/O and UI boundaries.
12using Coord = std::int64_t;
13
14inline constexpr Coord kNmPerMm = 1'000'000;
15inline constexpr Coord kNmPerMil = 25'400;
16
17// Converts millimetres to nanometres, rounding half away from zero (KiCad's parser behaviour).
18inline Coord mm_to_nm(double mm) { return static_cast<Coord>(std::llround(mm * static_cast<double>(kNmPerMm))); }
19
20TM_HD_INLINE double nm_to_mm(Coord nm) { return static_cast<double>(nm) / static_cast<double>(kNmPerMm); }
21
22} // namespace tmk
TM_HD marks functions that must compile identically for host and device.
#define TM_HD_INLINE
Definition hd.hpp:10
Definition advice.hpp:44
constexpr Coord kNmPerMil
Definition units.hpp:15
Coord mm_to_nm(double mm)
Converts millimetres to nanometres, rounding half away from zero (KiCad's parser behaviour).
Definition units.hpp:18
TM_HD_INLINE double nm_to_mm(Coord nm)
Definition units.hpp:20
std::int64_t Coord
Engine coordinate: signed 64-bit nanometres.
Definition units.hpp:12
constexpr Coord kNmPerMm
Definition units.hpp:14