Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
cd8411a8
Commit
cd8411a8
authored
Jun 23, 2018
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made clip_line_to_rectangle() and nearest_point() work for point and dpoint.
parent
9330c973
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
rectangle.h
dlib/geometry/rectangle.h
+12
-10
rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+6
-4
No files found.
dlib/geometry/rectangle.h
View file @
cd8411a8
...
...
@@ -444,12 +444,13 @@ namespace dlib
// ----------------------------------------------------------------------------------------
inline
const
point
nearest_point
(
template
<
typename
T
>
inline
const
dlib
::
vector
<
T
,
2
>
nearest_point
(
const
rectangle
&
rect
,
const
point
&
p
const
dlib
::
vector
<
T
,
2
>
&
p
)
{
point
temp
(
p
);
dlib
::
vector
<
T
,
2
>
temp
(
p
);
if
(
temp
.
x
()
<
rect
.
left
())
temp
.
x
()
=
rect
.
left
();
else
if
(
temp
.
x
()
>
rect
.
right
())
...
...
@@ -495,10 +496,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
inline
void
clip_line_to_rectangle
(
const
rectangle
&
box
,
point
&
p1
,
point
&
p2
dlib
::
vector
<
T
,
2
>
&
p1
,
dlib
::
vector
<
T
,
2
>
&
p2
)
{
// Now clip the line segment so it is contained inside box.
...
...
@@ -525,16 +527,16 @@ namespace dlib
//box.left() == alpha1*(p1.x()-p2.x()) + p2.x();
//box.right() == alpha2*(p1.x()-p2.x()) + p2.x();
const
point
d
=
p1
-
p2
;
const
dlib
::
vector
<
T
,
2
>
d
=
p1
-
p2
;
double
alpha1
=
(
box
.
left
()
-
p2
.
x
())
/
(
double
)
d
.
x
();
double
alpha2
=
(
box
.
right
()
-
p2
.
x
())
/
(
double
)
d
.
x
();
double
alpha3
=
(
box
.
top
()
-
p2
.
y
())
/
(
double
)
d
.
y
();
double
alpha4
=
(
box
.
bottom
()
-
p2
.
y
())
/
(
double
)
d
.
y
();
const
point
c1
=
alpha1
*
d
+
p2
;
const
point
c2
=
alpha2
*
d
+
p2
;
const
point
c3
=
alpha3
*
d
+
p2
;
const
point
c4
=
alpha4
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c1
=
alpha1
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c2
=
alpha2
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c3
=
alpha3
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c4
=
alpha4
*
d
+
p2
;
if
(
!
box
.
contains
(
p1
))
p1
=
c1
;
...
...
dlib/geometry/rectangle_abstract.h
View file @
cd8411a8
...
...
@@ -723,9 +723,10 @@ namespace dlib
// ----------------------------------------------------------------------------------------
inline
const
point
nearest_point
(
template
<
typename
T
>
inline
const
dlib
::
vector
<
T
,
2
>
nearest_point
(
const
rectangle
&
rect
,
const
point
&
p
const
dlib
::
vector
<
T
,
2
>
&
p
);
/*!
ensures
...
...
@@ -764,10 +765,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
clip_line_to_rectangle
(
const
rectangle
&
box
,
point
&
p1
,
point
&
p2
dlib
::
vector
<
T
,
2
>
&
p1
,
dlib
::
vector
<
T
,
2
>
&
p2
);
/*!
ensures
...
...
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