~thomas-voss/location-service/add-snapcraft-setup-next

« back to all changes in this revision

Viewing changes to src/location/criteria.cpp

Merge lp:~thomas-voss/location-service/simplify-provider-interface.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012-2013 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU Lesser General Public License version 3,
6
 
 * as published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU Lesser General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17
 
 */
18
 
 
19
 
#include <location/criteria.h>
20
 
 
21
 
bool location::Criteria::satisfies(const location::Criteria& rhs) const
22
 
{
23
 
    bool result = false;
24
 
 
25
 
    if (rhs.requires.position)
26
 
        result &= requires.position;
27
 
 
28
 
    if (rhs.requires.altitude)
29
 
        result &= requires.altitude;
30
 
 
31
 
    if (rhs.requires.heading)
32
 
        result &= requires.heading;
33
 
 
34
 
    if (rhs.requires.velocity)
35
 
        result &= requires.velocity;
36
 
 
37
 
    result &= accuracy.horizontal <= rhs.accuracy.horizontal;
38
 
 
39
 
    if (rhs.accuracy.vertical)
40
 
        result &= accuracy.vertical && accuracy.vertical <= rhs.accuracy.vertical;
41
 
 
42
 
    if (rhs.accuracy.heading)
43
 
        result &= accuracy.heading && accuracy.heading <= rhs.accuracy.heading;
44
 
 
45
 
    if (rhs.accuracy.velocity)
46
 
        result &= accuracy.velocity && accuracy.velocity <= rhs.accuracy.velocity;
47
 
 
48
 
    return result;
49
 
}
50
 
 
51
 
location::Criteria location::operator+(
52
 
        const location::Criteria& lhs,
53
 
        const location::Criteria& rhs)
54
 
{
55
 
    Criteria result{lhs};
56
 
 
57
 
    result.requires.position |= rhs.requires.position;
58
 
    result.requires.velocity |= rhs.requires.velocity;
59
 
    result.requires.heading |= rhs.requires.heading;
60
 
    result.requires.altitude |= rhs.requires.altitude;
61
 
 
62
 
    if (rhs.accuracy.horizontal < result.accuracy.horizontal)
63
 
        result.accuracy.horizontal = rhs.accuracy.horizontal;
64
 
 
65
 
    if (result.accuracy.vertical)
66
 
    {
67
 
        if (rhs.accuracy.vertical && rhs.accuracy.vertical < result.accuracy.vertical)
68
 
        {
69
 
            result.accuracy.vertical = rhs.accuracy.vertical;
70
 
        }
71
 
    } else
72
 
    {
73
 
        result.accuracy.vertical = rhs.accuracy.vertical;
74
 
    }
75
 
 
76
 
    if (result.accuracy.velocity)
77
 
    {
78
 
        if (rhs.accuracy.velocity && rhs.accuracy.velocity < result.accuracy.velocity)
79
 
        {
80
 
            result.accuracy.velocity = rhs.accuracy.velocity;
81
 
        }
82
 
    } else
83
 
    {
84
 
        result.accuracy.velocity = rhs.accuracy.velocity;
85
 
    }
86
 
 
87
 
    if (result.accuracy.heading)
88
 
    {
89
 
        if (rhs.accuracy.heading && rhs.accuracy.heading < result.accuracy.heading)
90
 
        {
91
 
            result.accuracy.heading = rhs.accuracy.heading;
92
 
        }
93
 
    } else
94
 
    {
95
 
        result.accuracy.heading = rhs.accuracy.heading;
96
 
    }
97
 
 
98
 
    return result;
99
 
}