Merge lp:~thomir-deactivatedaccount/autopilot/trunk-support-point3d into lp:autopilot

Proposed by Thomi Richards
Status: Merged
Approved by: Christopher Lee
Approved revision: 338
Merged at revision: 340
Proposed branch: lp:~thomir-deactivatedaccount/autopilot/trunk-support-point3d
Merge into: lp:autopilot
Diff against target: 165 lines (+120/-0)
2 files modified
autopilot/introspection/types.py (+45/-0)
autopilot/tests/unit/test_types.py (+75/-0)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/autopilot/trunk-support-point3d
Reviewer Review Type Date Requested Status
Christopher Lee (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+187954@code.launchpad.net

Commit message

Add support for 3D points.

Description of the change

Add support for points in 3D space, for the unity7 folk.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/types.py'
2--- autopilot/introspection/types.py 2013-09-20 19:01:27 +0000
3+++ autopilot/introspection/types.py 2013-09-26 23:36:39 +0000
4@@ -66,6 +66,7 @@
5 COLOR = 4
6 DATETIME = 5
7 TIME = 6
8+ POINT3D = 7
9 UNKNOWN = -1
10
11
12@@ -85,6 +86,7 @@
13 ValueType.SIZE: Size,
14 ValueType.DATETIME: DateTime,
15 ValueType.TIME: Time,
16+ ValueType.POINT3D: Point3D,
17 ValueType.UNKNOWN: _make_plain_type,
18 }
19 type_id = value[0]
20@@ -618,3 +620,46 @@
21 if isinstance(other, time):
22 return other == self._cached_time
23 return super(Time, self).__eq__(other)
24+
25+
26+class Point3D(_array_packed_type(3)):
27+
28+ """The Point3D class represents a 3D point in cartesian space.
29+
30+ To construct a Point3D, pass in the x, y and z parameters to the class
31+ constructor::
32+
33+ >>> my_point = Point(50,100,20)
34+
35+ These attributes can be accessed either using named attributes, or via
36+ sequence indexes::
37+
38+ >>> my_point.x == my_point[0] == 50
39+ True
40+ >>> my_point.y == my_point[1] == 100
41+ True
42+ >>> my_point.z == my_point[2] == 20
43+ True
44+
45+ Point3D instances can be compared using ``==`` and ``!=``, either to
46+ another Point3D instance, or to any mutable sequence type with the correct
47+ number of items::
48+
49+ >>> my_point == [50, 100, 20]
50+ True
51+ >>> my_point != Point(5, 10, 2)
52+ True
53+
54+ """
55+
56+ @property
57+ def x(self):
58+ return self[0]
59+
60+ @property
61+ def y(self):
62+ return self[1]
63+
64+ @property
65+ def z(self):
66+ return self[2]
67
68=== modified file 'autopilot/tests/unit/test_types.py'
69--- autopilot/tests/unit/test_types.py 2013-09-18 22:22:23 +0000
70+++ autopilot/tests/unit/test_types.py 2013-09-26 23:36:39 +0000
71@@ -32,6 +32,7 @@
72 DateTime,
73 PlainType,
74 Point,
75+ Point3D,
76 Rectangle,
77 Size,
78 Time,
79@@ -303,6 +304,51 @@
80 self.assertThat(dt1.time, IsInstance(time))
81
82
83+class Point3DTypeTests(TestCase):
84+
85+ def test_can_construct_point3d(self):
86+ r = Point3D(1, 2, 3)
87+ self.assertThat(r, IsInstance(dbus.Array))
88+
89+ def test_point3d_has_xyz_properties(self):
90+ r = Point3D(1, 2, 3)
91+
92+ self.assertThat(r.x, Equals(1))
93+ self.assertThat(r.y, Equals(2))
94+ self.assertThat(r.z, Equals(3))
95+
96+ def test_point3d_has_slice_access(self):
97+ r = Point3D(1, 2, 3)
98+
99+ self.assertThat(r[0], Equals(1))
100+ self.assertThat(r[1], Equals(2))
101+ self.assertThat(r[2], Equals(3))
102+
103+ def test_equality_with_point3d(self):
104+ p1 = Point3D(1, 2, 3)
105+ p2 = Point3D(1, 2, 3)
106+
107+ self.assertThat(p1, Equals(p2))
108+
109+ def test_inequality_with_point3d(self):
110+ p1 = Point3D(1, 2, 3)
111+ p2 = Point3D(1, 2, 4)
112+
113+ self.assertThat(p1, NotEquals(p2))
114+
115+ def test_equality_with_list(self):
116+ p1 = Point3D(1, 2, 3)
117+ p2 = [1, 2, 3]
118+
119+ self.assertThat(p1, Equals(p2))
120+
121+ def test_inequality_with_list(self):
122+ p1 = Point3D(1, 2, 3)
123+ p2 = [1, 2, 4]
124+
125+ self.assertThat(p1, NotEquals(p2))
126+
127+
128 class CreateValueInstanceTests(TestCase):
129
130 """Tests to check that create_value_instance does the right thing."""
131@@ -550,6 +596,35 @@
132 ValueError("Cannot create attribute, no data supplied")
133 ))
134
135+ def test_point3d(self):
136+ data = dbus.Array(
137+ [
138+ dbus.Int32(ValueType.POINT3D),
139+ dbus.Int32(0),
140+ dbus.Int32(10),
141+ dbus.Int32(20),
142+ ]
143+ )
144+
145+ attr = create_value_instance(data, None, None)
146+
147+ self.assertThat(attr, IsInstance(Point3D))
148+
149+ def test_invalid_point3d(self):
150+ data = dbus.Array(
151+ [
152+ dbus.Int32(ValueType.POINT3D),
153+ dbus.Int32(0),
154+ dbus.Int32(0),
155+ ]
156+ )
157+
158+ fn = lambda: create_value_instance(data, None, None)
159+
160+ self.assertThat(fn, raises(
161+ ValueError("Point3D must be constructed with 3 arguments, not 2")
162+ ))
163+
164
165 class DBusIntrospectionObjectTests(TestCase):
166

Subscribers

People subscribed via source and target branches