17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-31 16:59:06 +01:00
Files
maszyna/maj0sted/include/maj0sted/domain/value_objects/length.hpp
maj00r a083269867 Vendor the maj0sted track layout library and link it into the editor
Drop-in copy of C:\Users\maj00r\Projects\maj0sted-master minus its web/
directory - the WASM frontend is not being ported, the editor drives the
same C++ API natively. What is left is plain C++20 with no dependencies:
domain model (niweleta, plan and profile geometry, fitting, parallelism),
project serialization, rail sampling and the editor document.

src/web/ribbon.cpp was missing from the library source list; added, since
without it the ribbon symbols never make it into the archive.
2026-08-27 19:36:55 +02:00

38 lines
998 B
C++

#pragma once
#include <compare>
#include <stdexcept>
namespace maj0sted::domain {
/// Value Object: a non-negative length, in metres (the unit of the default
/// EPSG:2180 CRS). Lengths add and compare by value.
class Length {
public:
constexpr Length() noexcept = default;
static constexpr Length from_metres(double metres) {
if (metres < 0.0) {
throw std::invalid_argument{"Length cannot be negative"};
}
return Length{metres};
}
static constexpr Length zero() noexcept { return Length{}; }
[[nodiscard]] constexpr double metres() const noexcept { return metres_; }
[[nodiscard]] constexpr Length operator+(Length other) const noexcept {
return Length{metres_ + other.metres_};
}
friend constexpr auto operator<=>(const Length&, const Length&) noexcept = default;
private:
explicit constexpr Length(double metres) noexcept : metres_{metres} {}
double metres_{0.0};
};
} // namespace maj0sted::domain