R2::basic_position_qty
namespace nin::R2 {
template <std::floating_point T>
struct basic_position_qty;
using point_qty = basic_position_qty<double>;
}
A 2D point quantity. It holds two length components (x, y) expressed as length quantities. It is a container of raw measurements with no relation to any coordinate system. The components are accessible through a range-based interface.
The type alias R2::point_qty is provided for R2::basic_position_qty<double>.
Nested types
| Type | Definition |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
forward iterator over the two components |
|
const forward iterator over the two components |
Member functions
(Constructor)
(Constructor)
|
(1) |
|
(2) |
-
(1) Default constructor. Both components are zero.
-
(2) Component constructor.
import ninbot;
using namespace nin;
int main() {
R2::point_qty pointq_0; // (0, 0) (m)
R2::point_qty pointq_1 = {1_m, 20_cm}; // (1, 0.2) (m)
}
operator[]
component access by index
operator[]
component access by index
|
(1) |
|
(2) |
Index 0 returns x; any other index returns y.
import ninbot;
using namespace nin;
int main() {
R2::point_qty pointq = {1_m, 2_m};
units::length length_y = pointq[1]; // 2_m
}
begin, cbegin
iterator to the first component
begin, cbegin
iterator to the first component
|
(1) |
|
(2) |
|
(3) |
Returns an iterator to the x component.
import ninbot;
using namespace nin;
int main() {
R2::point_qty pointq = {1_m, 2_m};
for (units::length q : pointq)
{ /* iterates over x then y */ }
}
end, cend
sentinel
end, cend
sentinel
|
(1) |
|
(2) |
|
(3) |
Returns a sentinel for iterating over the components.
import ninbot;
using namespace nin;
int main() {
R2::point_qty pointq = {1_m, 2_m};
for (units::length q : pointq) { /* iterates over x then y */ }
}
size
number of components
size
number of components
|
(1) |
Returns 2.
max_size
maximum number of components
max_size
maximum number of components
|
(1) |
Returns 2.
empty
whether the container holds no components
empty
whether the container holds no components
|
(1) |
Returns false.
operator==
equality comparison
operator==
equality comparison
|
(1) |
Component-wise equality.
This is an exact-value comparison operator: f⁻¹(f(q)) == q may be false.
|
Non-member functions
std::formatter<>
STL overload for the std::format and std::print families.
std::formatter<>
STL overload for the std::format and std::print families.
|
(1) |
|
(2) |
Adds a specialization of std::formatter that formats the
two components in the order x, y.
The <format-spec> syntax is
[<float-spec>] ["_" [<unit>]] ["|" <separator>]
with the following rules:
-
<float-spec>— anything before the first_is forwarded verbatim to the STL formatter for floating points and applied to each component. -
<unit>— the text betweenand|(or the end of the spec) selects the unit used both for the displayed values and the trailing unit label. When theis present but<unit>is empty, the unit label is suppressed and magnitudes are formatted in SI units. -
Parentheses — when the format-spec contains no
|separator, the output is wrapped in parentheses. -
Separator — the text after
|is placed between the two components. Theis not required in order to specify a separator: whenis omitted, the trailing unit label is the default SI label (e.g. ` (m)), and parentheses are dropped as soon as `|is present. When neither_nor|is given,<separator>defaults to", ".
import ninbot;
#include <print>
int main() {
nin::R2::point_qty p = {1.5_m, 2.0_m};
std::println("{}", p); // "(1.5, 2) (m)"
std::println("{:_}", p); // "(1.5, 2)"
std::println("{:|, }", p); // "1.5, 2 (m)"
std::println("{:.2f| }", p); // "1.50 2.00 (m)"
std::println("{:_| }", p); // "1.5 2"
std::println("{:_cm}", p); // "(150, 200) (cm)"
std::println("{:_cm|, }", p); // "150, 200 (cm)"
std::println("{:.2f_m}", p); // "(1.50, 2.00) (m)"
std::println("{:.2f_m|; }", p); // "1.50; 2.00 (m)"
std::println("({:.3f_cm| - })", p); // "(150.000 - 200.000 (cm))"
std::println("{:.2f_|, } m", p); // "1.50, 2.00 m"
}