KOSMIndoorMap

routingprofile.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "routingprofile.h"
7#include "routingarea.h"
8
9#include <array>
10
11namespace KOSMIndoorRouting {
12class RoutingProfilePrivate : public QSharedData
13{
14public:
15 AreaFlags flags = ~AreaFlags{};
16 std::array<float, AREA_TYPE_COUNT> costs;
17};
18}
19
20using namespace KOSMIndoorRouting;
21
22RoutingProfile::RoutingProfile()
23 : d(new RoutingProfilePrivate)
24{
25 // TODO support for multiple pre-defined profiles
26 d->costs = {
27 1.0f,
28 5.0f, // stairs
29 10.0f, // elevators
30 2.5f, // escalator
31 1.0f, // moving walkways
32 1.5f, // tactile paving
33 10.0f, // street crossing
34 4.0f, // ramp
35 10.0f, // rooms (in order to prefer corridors)
36 1.5f, // walkable area
37 };
38}
39
40RoutingProfile::RoutingProfile(const RoutingProfile&) = default;
41RoutingProfile::RoutingProfile(RoutingProfile&&) noexcept = default;
42RoutingProfile::~RoutingProfile() = default;
43RoutingProfile& RoutingProfile::operator=(const RoutingProfile&) = default;
44RoutingProfile& RoutingProfile::operator=(RoutingProfile&&) noexcept = default;
45
46bool RoutingProfile::operator==(const RoutingProfile &other) const
47{
48 return d->flags == other.d->flags && std::equal(d->costs.begin(), d->costs.end(), other.d->costs.begin());
49}
50
51AreaFlags RoutingProfile::flags() const
52{
53 return d->flags;
54}
55
56void RoutingProfile::setFlags(AreaFlags flags)
57{
58 d.detach();
59 d->flags = flags;
60}
61
62float RoutingProfile::cost(KOSMIndoorRouting::AreaType area) const
63{
64 return area == AreaType::Walkable ? d->costs[d->costs.size() - 1] : d->costs[qToUnderlying(area)];
65}
66
67void RoutingProfile::setCost(KOSMIndoorRouting::AreaType area, float cost)
68{
69 d.detach();
70 if (area == AreaType::Walkable) {
71 d->costs[d->costs.size() - 1] = std::max(1.0f, cost);
72 } else {
73 d->costs[qToUnderlying(area)] = std::max(1.0f, cost);
74 }
75}
76
77#include "moc_routingprofile.cpp"
Q_INVOKABLE float cost(KOSMIndoorRouting::AreaType area) const
Cost factors (>= 1.0) for each area type that is included in the search.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.