Merge lp:~thomas-voss/biometryd/floating-point-mask-coordinates into lp:biometryd

Proposed by Thomas Voß
Status: Merged
Approved by: Thomas Voß
Approved revision: 22
Merged at revision: 22
Proposed branch: lp:~thomas-voss/biometryd/floating-point-mask-coordinates
Merge into: lp:biometryd
Diff against target: 200 lines (+43/-25)
7 files modified
include/biometry/geometry.h (+7/-3)
src/biometry/dbus/codec.h (+6/-6)
src/biometry/geometry.cpp (+14/-0)
tests/test_dbus_codec.cpp (+3/-3)
tests/test_dictionary.cpp (+4/-4)
tests/test_fingerprint_reader.cpp (+1/-1)
tests/test_geometry.cpp (+8/-8)
To merge this branch: bzr merge lp:~thomas-voss/biometryd/floating-point-mask-coordinates
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+295742@code.launchpad.net

Commit message

Switch to a normalized coordinate system for communicating masks.

Description of the change

Switch to a normalized coordinate system for communicating masks.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/biometry/geometry.h'
2--- include/biometry/geometry.h 2016-05-02 06:16:01 +0000
3+++ include/biometry/geometry.h 2016-05-25 16:01:58 +0000
4@@ -27,11 +27,15 @@
5
6 namespace biometry
7 {
8-/// @brief Point models a point in a 2d space.
9+/// @brief Point models a point in a normalized space [0,1]^2.
10 struct BIOMETRY_DLL_PUBLIC Point
11 {
12- std::uint32_t x;
13- std::uint32_t y;
14+ /// @brief Point initializes a new instance with x, y.
15+ /// @ŧhrows std::runtime_error if x or y is not in [0,1].
16+ Point(double x = 0.f, double y = 0.f);
17+
18+ double x;
19+ double y;
20 };
21
22 /// @brief Rectangle models a rectangular region in a 2d space,
23
24=== modified file 'src/biometry/dbus/codec.h'
25--- src/biometry/dbus/codec.h 2016-05-02 06:16:01 +0000
26+++ src/biometry/dbus/codec.h 2016-05-25 16:01:58 +0000
27@@ -84,8 +84,8 @@
28 static std::string signature()
29 {
30 return DBUS_STRUCT_BEGIN_CHAR_AS_STRING
31- + TypeMapper<std::uint32_t>::signature()
32- + TypeMapper<std::uint32_t>::signature()
33+ + TypeMapper<double>::signature()
34+ + TypeMapper<double>::signature()
35 + DBUS_STRUCT_END_CHAR_AS_STRING;
36 }
37 };
38@@ -204,8 +204,8 @@
39 {
40 auto sw = out.open_structure();
41 {
42- sw.push_uint32(in.x);
43- sw.push_uint32(in.y);
44+ sw.push_floating_point(in.x);
45+ sw.push_floating_point(in.y);
46 }
47 out.close_structure(std::move(sw));
48 }
49@@ -213,8 +213,8 @@
50 static void decode_argument(Message::Reader& in, biometry::Point& out)
51 {
52 auto sr = in.pop_structure();
53- out.x = sr.pop_uint32();
54- out.y = sr.pop_uint32();
55+ out.x = sr.pop_floating_point();
56+ out.y = sr.pop_floating_point();
57 }
58 };
59
60
61=== modified file 'src/biometry/geometry.cpp'
62--- src/biometry/geometry.cpp 2016-05-02 06:16:01 +0000
63+++ src/biometry/geometry.cpp 2016-05-25 16:01:58 +0000
64@@ -20,6 +20,20 @@
65 #include <biometry/geometry.h>
66
67 #include <iostream>
68+#include <stdexcept>
69+
70+namespace
71+{
72+double ensure_bounds(double value)
73+{
74+ if (value < 0 || value > 1) throw std::runtime_error{"Bounds exceeded"};
75+ return value;
76+}
77+}
78+
79+biometry::Point::Point(double x, double y) : x{ensure_bounds(x)}, y{ensure_bounds(y)}
80+{
81+}
82
83 bool biometry::operator==(const biometry::Point& lhs, const biometry::Point& rhs)
84 {
85
86=== modified file 'tests/test_dbus_codec.cpp'
87--- tests/test_dbus_codec.cpp 2016-05-02 06:16:01 +0000
88+++ tests/test_dbus_codec.cpp 2016-05-25 16:01:58 +0000
89@@ -55,7 +55,7 @@
90
91 static biometry::Point point()
92 {
93- return biometry::Point{42, 42};
94+ return biometry::Point{0.42, 0.42};
95 }
96
97 static biometry::Rectangle rectangle()
98@@ -84,14 +84,14 @@
99 {
100 biometry::Variant::b(true),
101 biometry::Variant::i(42),
102- biometry::Variant::d(42.),
103+ biometry::Variant::d(0.42),
104 biometry::Variant::r(Reference::rectangle()),
105 biometry::Variant::s("42"),
106 biometry::Variant::v(
107 {
108 biometry::Variant::b(true),
109 biometry::Variant::i(42),
110- biometry::Variant::d(42.),
111+ biometry::Variant::d(0.42),
112 biometry::Variant::r(Reference::rectangle()),
113 biometry::Variant::s("42")
114 })
115
116=== modified file 'tests/test_dictionary.cpp'
117--- tests/test_dictionary.cpp 2016-05-04 12:17:44 +0000
118+++ tests/test_dictionary.cpp 2016-05-25 16:01:58 +0000
119@@ -47,8 +47,8 @@
120 {
121 {const bool rv = true; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::boolean, v.type()); EXPECT_EQ(rv, v.boolean());}
122 {const std::int64_t rv = 42; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::integer, v.type()); EXPECT_EQ(rv, v.integer());}
123- {const double rv = 42.f; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::floating_point, v.type()); EXPECT_EQ(rv, v.floating_point());}
124- {const biometry::Rectangle rv = {biometry::Point{42, 42}, biometry::Point{42, 42}}; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::rectangle, v.type()); EXPECT_EQ(rv, v.rectangle());}
125+ {const double rv = 0.42; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::floating_point, v.type()); EXPECT_EQ(rv, v.floating_point());}
126+ {const biometry::Rectangle rv = {biometry::Point{0.42, 0.42}, biometry::Point{0.42, 0.42}}; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::rectangle, v.type()); EXPECT_EQ(rv, v.rectangle());}
127 {const std::string rv = "42"; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::string, v.type()); EXPECT_EQ(rv, v.string());}
128 {const std::vector<std::uint8_t> rv = {4, 2}; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::blob, v.type()); EXPECT_EQ(rv, v.blob());}
129 {const std::vector<biometry::Variant> rv = {biometry::Variant(std::int64_t(4)), biometry::Variant("2")}; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::vector, v.type()); EXPECT_EQ(rv, v.vector());}
130@@ -58,9 +58,9 @@
131 {
132 {const bool rv = true; auto v = biometry::Variant::b(rv); EXPECT_EQ(biometry::Variant::Type::boolean, v.type()); EXPECT_EQ(rv, v.boolean());}
133 {const std::int64_t rv = 42; auto v = biometry::Variant::i(rv); EXPECT_EQ(biometry::Variant::Type::integer, v.type()); EXPECT_EQ(rv, v.integer());}
134- {const double rv = 42.f; auto v = biometry::Variant::d(rv); EXPECT_EQ(biometry::Variant::Type::floating_point, v.type()); EXPECT_EQ(rv, v.floating_point());}
135+ {const double rv = 0.42; auto v = biometry::Variant::d(rv); EXPECT_EQ(biometry::Variant::Type::floating_point, v.type()); EXPECT_EQ(rv, v.floating_point());}
136 {const std::string rv = "42"; auto v = biometry::Variant::s(rv); EXPECT_EQ(biometry::Variant::Type::string, v.type()); EXPECT_EQ(rv, v.string());}
137- {const biometry::Rectangle rv = {biometry::Point{42, 42}, biometry::Point{42, 42}}; auto v = biometry::Variant::r(rv); EXPECT_EQ(biometry::Variant::Type::rectangle, v.type()); EXPECT_EQ(rv, v.rectangle());}
138+ {const biometry::Rectangle rv = {biometry::Point{0.42, 0.42}, biometry::Point{0.42, 0.42}}; auto v = biometry::Variant::r(rv); EXPECT_EQ(biometry::Variant::Type::rectangle, v.type()); EXPECT_EQ(rv, v.rectangle());}
139 {const std::vector<std::uint8_t> rv = {4, 2}; auto v = biometry::Variant::bl(rv); EXPECT_EQ(biometry::Variant::Type::blob, v.type()); EXPECT_EQ(rv, v.blob());}
140 {const std::vector<biometry::Variant> rv = {biometry::Variant::i(4), biometry::Variant::s("2")}; biometry::Variant v{rv}; EXPECT_EQ(biometry::Variant::Type::vector, v.type()); EXPECT_EQ(rv, v.vector());}
141 }
142
143=== modified file 'tests/test_fingerprint_reader.cpp'
144--- tests/test_fingerprint_reader.cpp 2016-05-02 06:16:01 +0000
145+++ tests/test_fingerprint_reader.cpp 2016-05-25 16:01:58 +0000
146@@ -26,7 +26,7 @@
147 biometry::devices::FingerprintReader::GuidedEnrollment::Hints g1;
148 g1.is_main_cluster_identified = true;
149 g1.suggested_next_direction = biometry::devices::FingerprintReader::Direction::east;
150- g1.masks = std::vector<biometry::Rectangle>{biometry::Rectangle{{42, 42}, {43, 43}}};
151+ g1.masks = std::vector<biometry::Rectangle>{biometry::Rectangle{{0.42, 0.42}, {0.43, 0.43}}};
152
153 auto dict = g1.to_dictionary();
154
155
156=== modified file 'tests/test_geometry.cpp'
157--- tests/test_geometry.cpp 2016-05-02 06:16:01 +0000
158+++ tests/test_geometry.cpp 2016-05-25 16:01:58 +0000
159@@ -23,35 +23,35 @@
160
161 TEST(Point, equality_operator_works)
162 {
163- biometry::Point p1{42, 43}; biometry::Point p2(p1);
164+ biometry::Point p1{0.42, 0.43}; biometry::Point p2(p1);
165 EXPECT_EQ(p2, p1);
166- biometry::Point p3{43, 42};
167+ biometry::Point p3{0.43, 0.42};
168 EXPECT_NE(p3, p1);
169 }
170
171 TEST(Point, stream_insertion_works)
172 {
173- biometry::Point p1{42, 42};
174+ biometry::Point p1{0.42, 0.42};
175 std::stringstream ss; ss << p1;
176- EXPECT_EQ("(42,42)", ss.str());
177+ EXPECT_EQ("(0.42,0.42)", ss.str());
178 }
179
180 TEST(Rectangle, equality_operator_works)
181 {
182- biometry::Point p1{42, 43}; biometry::Point p2(p1);
183+ biometry::Point p1{0.42, 0.43}; biometry::Point p2(p1);
184 biometry::Rectangle r1{p1, p2}; biometry::Rectangle r2(r1);
185 EXPECT_EQ(r2, r1);
186- biometry::Point p3{43, 42};
187+ biometry::Point p3{0.43, 0.42};
188 biometry::Rectangle r3{p1, p3};
189 EXPECT_NE(r3, r1);
190 }
191
192 TEST(Rectangle, stream_insertion_works)
193 {
194- biometry::Point p1{42, 43}; biometry::Point p2(p1);
195+ biometry::Point p1{0.42, 0.43}; biometry::Point p2(p1);
196 biometry::Rectangle r1{p1, p2};
197 std::stringstream ss; ss << r1;
198- EXPECT_EQ("((42,43),(42,43))", ss.str());
199+ EXPECT_EQ("((0.42,0.43),(0.42,0.43))", ss.str());
200 }
201
202

Subscribers

People subscribed via source and target branches