Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
0107775a
Commit
0107775a
authored
Jun 19, 2012
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polygon contains() function now does not use bounding box anymore.
parent
4086fa7c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
6 deletions
+53
-6
tests/testapp.py
tests/testapp.py
+12
-5
tests/utils.py
tests/utils.py
+41
-1
No files found.
tests/testapp.py
View file @
0107775a
...
...
@@ -57,6 +57,12 @@ class Polygon(BoundingBoxArea):
self
.
flick_direction
=
trans
flicks
.
add
(
Flick
(
self
.
flick_drag
,
0.7
,
0.4
))
def
contains
(
self
,
x
,
y
):
if
draw_bounding_boxes
:
return
mt
.
RectangularArea
.
contains
(
self
,
x
,
y
)
return
BoundingBoxArea
.
contains
(
self
,
x
,
y
)
def
handle_drag
(
self
,
g
):
tx
,
ty
=
g
.
get_translation
()
self
.
translate
(
tx
,
ty
)
...
...
@@ -74,10 +80,10 @@ class Polygon(BoundingBoxArea):
self
.
update_bounds
()
refresh
()
def
contains
(
self
,
x
,
y
):
m
=
self
.
margin
return
self
.
x
-
m
<=
x
<
self
.
x
+
self
.
width
+
m
\
and
self
.
y
-
m
<=
y
<
self
.
y
+
self
.
height
+
m
#
def contains(self, x, y):
#
m = self.margin
#
return self.x - m <= x < self.x + self.width + m \
#
and self.y - m <= y < self.y + self.height + m
def
draw
(
self
,
cr
):
# Draw bounding box
...
...
@@ -102,7 +108,8 @@ class Polygon(BoundingBoxArea):
fullscreen
=
False
draw_bounding_boxes
=
draw_touch_objects
=
True
draw_bounding_boxes
=
False
draw_touch_objects
=
True
W
,
H
=
mt
.
screen
.
screen_size
...
...
tests/utils.py
View file @
0107775a
from
__future__
import
division
from
time
import
sleep
from
threading
import
Thread
from
numpy
import
array
,
diag
,
dot
,
cos
,
sin
from
numpy
import
array
,
diag
,
dot
,
cos
,
sin
,
asarray
,
column_stack
,
c_
from
src
import
RectangularArea
...
...
@@ -29,6 +29,10 @@ class BoundingBoxArea(RectangularArea):
self
.
points
=
dot
(
mat
,
self
.
points
)
self
.
translate_points
(
cx
,
cy
)
def
contains
(
self
,
x
,
y
):
ox
,
oy
=
self
.
get_position
()
return
inside_shape
((
x
-
ox
,
y
-
oy
),
self
.
points
)
def
update_bounds
(
self
):
min_x
,
min_y
=
self
.
points
.
min
(
1
)
max_x
,
max_y
=
self
.
points
.
max
(
1
)
...
...
@@ -74,3 +78,39 @@ class FlickThread(Thread):
def
add
(
self
,
flick
):
self
.
flicks
.
append
(
flick
)
def
inside_shape
(
p
,
verts
):
"""Test whether the point p is inside the specified shape.
The shape is specified by 'verts' and 'edges'
Arguments:
p - the 2d point
verts - (N,2) array of points
Returns:
- True/False based on result of in/out test.
Uses the 'ray to infinity' even-odd test.
Let the ray be the horizontal ray starting at p and going to +inf in x.
"""
x
,
y
=
p
inside
=
False
for
i
in
range
(
-
1
,
verts
.
shape
[
1
]
-
1
):
x0
,
y0
=
verts
[:,
i
]
x1
,
y1
=
verts
[:,
i
+
1
]
# Check for horizontal line - another horz line can't intersect it
# Check if both verts to the left, bottom or top of ray
if
(
y0
==
y1
)
or
(
x0
<
x
and
x1
<
x
)
or
(
y0
<
y
and
y1
<
y
)
\
or
(
y0
>
y
and
y1
>
y
):
continue
# Compute x intersection value
xisect
=
x0
+
(
x1
-
x0
)
*
(
y
-
y0
)
/
(
y1
-
y0
)
print
xisect
,
x
if
xisect
>=
x
:
inside
=
not
inside
return
inside
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment