Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Papermerge.Js
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Jonas Leder
Papermerge.Js
Commits
944bba96
Commit
944bba96
authored
3 years ago
by
Eugen Ciur
Browse files
Options
Downloads
Patches
Plain Diff
fix 'intersect' method + add couple of tests
parent
10e90065
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
app/utils/rectangle.js
+19
-1
19 additions, 1 deletion
app/utils/rectangle.js
tests/unit/rectangle-test.js
+30
-0
30 additions, 0 deletions
tests/unit/rectangle-test.js
with
49 additions
and
1 deletion
app/utils/rectangle.js
+
19
−
1
View file @
944bba96
...
@@ -17,7 +17,8 @@ export default class Rectangle {
...
@@ -17,7 +17,8 @@ export default class Rectangle {
intersect
(
rect
)
{
intersect
(
rect
)
{
/*
/*
Returns true if this rectangle intersects with rect.
Returns true if this rectangle intersects with rect
(or other way around).
Two rectangle intersect if one of them has a point inside other.
Two rectangle intersect if one of them has a point inside other.
*/
*/
if
(
this
.
contains_point
(
rect
.
p1
))
{
if
(
this
.
contains_point
(
rect
.
p1
))
{
...
@@ -36,6 +37,23 @@ export default class Rectangle {
...
@@ -36,6 +37,23 @@ export default class Rectangle {
return
true
;
return
true
;
}
}
// or other way around
if
(
rect
.
contains_point
(
this
.
p1
))
{
return
true
;
}
if
(
rect
.
contains_point
(
this
.
p2
))
{
return
true
;
}
if
(
rect
.
contains_point
(
this
.
p3
))
{
return
true
;
}
if
(
rect
.
contains_point
(
this
.
p4
))
{
return
true
;
}
return
false
;
return
false
;
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/unit/rectangle-test.js
+
30
−
0
View file @
944bba96
...
@@ -53,5 +53,35 @@ module('Unit | Rectangle', function () {
...
@@ -53,5 +53,35 @@ module('Unit | Rectangle', function () {
rect
.
p4
.
isEqual
(
new
Point
(
100
,
205
))
rect
.
p4
.
isEqual
(
new
Point
(
100
,
205
))
);
);
});
});
test
(
'
instersect positive
'
,
function
(
assert
)
{
let
rect1
,
rect2
;
rect1
=
new
Rectangle
(
100
,
100
,
20
,
20
);
rect2
=
new
Rectangle
(
110
,
90
,
5
,
25
);
assert
.
true
(
rect1
.
intersect
(
rect2
)
);
assert
.
true
(
rect2
.
intersect
(
rect1
)
);
});
test
(
'
instersect negative
'
,
function
(
assert
)
{
let
rect1
,
rect2
;
rect1
=
new
Rectangle
(
100
,
100
,
20
,
20
);
rect2
=
new
Rectangle
(
10
,
10
,
15
,
15
);
assert
.
false
(
rect1
.
intersect
(
rect2
)
);
assert
.
false
(
rect2
.
intersect
(
rect1
)
);
});
});
});
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