Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multitouch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
multitouch
Commits
0107775a
Commit
0107775a
authored
12 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Polygon contains() function now does not use bounding box anymore.
parent
4086fa7c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/testapp.py
+12
-5
12 additions, 5 deletions
tests/testapp.py
tests/utils.py
+41
-1
41 additions, 1 deletion
tests/utils.py
with
53 additions
and
6 deletions
tests/testapp.py
+
12
−
5
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
...
...
This diff is collapsed.
Click to expand it.
tests/utils.py
+
41
−
1
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment