Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
cd8411a8
Commit
cd8411a8
authored
Jun 23, 2018
by
Davis King
Browse files
Made clip_line_to_rectangle() and nearest_point() work for point and dpoint.
parent
9330c973
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
dlib/geometry/rectangle.h
dlib/geometry/rectangle.h
+12
-10
dlib/geometry/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
...
@@ -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
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
())
if
(
temp
.
x
()
<
rect
.
left
())
temp
.
x
()
=
rect
.
left
();
temp
.
x
()
=
rect
.
left
();
else
if
(
temp
.
x
()
>
rect
.
right
())
else
if
(
temp
.
x
()
>
rect
.
right
())
...
@@ -495,10 +496,11 @@ namespace dlib
...
@@ -495,10 +496,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
inline
void
clip_line_to_rectangle
(
inline
void
clip_line_to_rectangle
(
const
rectangle
&
box
,
const
rectangle
&
box
,
point
&
p1
,
dlib
::
vector
<
T
,
2
>
&
p1
,
point
&
p2
dlib
::
vector
<
T
,
2
>
&
p2
)
)
{
{
// Now clip the line segment so it is contained inside box.
// Now clip the line segment so it is contained inside box.
...
@@ -525,16 +527,16 @@ namespace dlib
...
@@ -525,16 +527,16 @@ namespace dlib
//box.left() == alpha1*(p1.x()-p2.x()) + p2.x();
//box.left() == alpha1*(p1.x()-p2.x()) + p2.x();
//box.right() == alpha2*(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
alpha1
=
(
box
.
left
()
-
p2
.
x
())
/
(
double
)
d
.
x
();
double
alpha2
=
(
box
.
right
()
-
p2
.
x
())
/
(
double
)
d
.
x
();
double
alpha2
=
(
box
.
right
()
-
p2
.
x
())
/
(
double
)
d
.
x
();
double
alpha3
=
(
box
.
top
()
-
p2
.
y
())
/
(
double
)
d
.
y
();
double
alpha3
=
(
box
.
top
()
-
p2
.
y
())
/
(
double
)
d
.
y
();
double
alpha4
=
(
box
.
bottom
()
-
p2
.
y
())
/
(
double
)
d
.
y
();
double
alpha4
=
(
box
.
bottom
()
-
p2
.
y
())
/
(
double
)
d
.
y
();
const
point
c1
=
alpha1
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c1
=
alpha1
*
d
+
p2
;
const
point
c2
=
alpha2
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c2
=
alpha2
*
d
+
p2
;
const
point
c3
=
alpha3
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c3
=
alpha3
*
d
+
p2
;
const
point
c4
=
alpha4
*
d
+
p2
;
const
dlib
::
vector
<
T
,
2
>
c4
=
alpha4
*
d
+
p2
;
if
(
!
box
.
contains
(
p1
))
if
(
!
box
.
contains
(
p1
))
p1
=
c1
;
p1
=
c1
;
...
...
dlib/geometry/rectangle_abstract.h
View file @
cd8411a8
...
@@ -723,9 +723,10 @@ namespace dlib
...
@@ -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
rectangle
&
rect
,
const
point
&
p
const
dlib
::
vector
<
T
,
2
>
&
p
);
);
/*!
/*!
ensures
ensures
...
@@ -764,10 +765,11 @@ namespace dlib
...
@@ -764,10 +765,11 @@ namespace dlib
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
void
clip_line_to_rectangle
(
void
clip_line_to_rectangle
(
const
rectangle
&
box
,
const
rectangle
&
box
,
point
&
p1
,
dlib
::
vector
<
T
,
2
>
&
p1
,
point
&
p2
dlib
::
vector
<
T
,
2
>
&
p2
);
);
/*!
/*!
ensures
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