|
<html><head><title>dlib C++ Library - rectangle.h</title></head><body bgcolor='white'><pre> |
|
<font color='#009900'>// Copyright (C) 2005 Davis E. King ([email protected]) |
|
</font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license. |
|
</font><font color='#0000FF'>#ifndef</font> DLIB_RECTANGLe_ |
|
<font color='#0000FF'>#define</font> DLIB_RECTANGLe_ |
|
|
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='rectangle_abstract.h.html'>rectangle_abstract.h</a>" |
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>" |
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>algorithm<font color='#5555FF'>></font> |
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>iostream<font color='#5555FF'>></font> |
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../serialize.h.html'>../serialize.h</a>" |
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='vector.h.html'>vector.h</a>" |
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../image_processing/generic_image.h.html'>../image_processing/generic_image.h</a>" |
|
|
|
<font color='#0000FF'>namespace</font> dlib |
|
<b>{</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>class</font> <b><a name='rectangle'></a>rectangle</b> |
|
<b>{</b> |
|
<font color='#009900'>/*! |
|
INITIAL VALUE |
|
The initial value of this object is defined by its constructor. |
|
|
|
CONVENTION |
|
left() == l |
|
top() == t |
|
right() == r |
|
bottom() == b |
|
!*/</font> |
|
|
|
<font color='#0000FF'>public</font>: |
|
|
|
<b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>long</u></font> l_, |
|
<font color='#0000FF'><u>long</u></font> t_, |
|
<font color='#0000FF'><u>long</u></font> r_, |
|
<font color='#0000FF'><u>long</u></font> b_ |
|
<font face='Lucida Console'>)</font> : |
|
l<font face='Lucida Console'>(</font>l_<font face='Lucida Console'>)</font>, |
|
t<font face='Lucida Console'>(</font>t_<font face='Lucida Console'>)</font>, |
|
r<font face='Lucida Console'>(</font>r_<font face='Lucida Console'>)</font>, |
|
b<font face='Lucida Console'>(</font>b_<font face='Lucida Console'>)</font> |
|
<b>{</b><b>}</b> |
|
|
|
<b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> w, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> h |
|
<font face='Lucida Console'>)</font> : |
|
l<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, |
|
t<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, |
|
r<font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, |
|
b<font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>h<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>w <font color='#5555FF'>></font> <font color='#979000'>0</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> h <font color='#5555FF'>></font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font face='Lucida Console'>(</font>w <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> h <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>, |
|
"<font color='#CC0000'>\trectangle(width,height)</font>" |
|
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>\n\twidth and height must be > 0 or both == 0</font>" |
|
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>\n\twidth: </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> w |
|
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>\n\theight: </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> h |
|
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> <font color='#0000FF'>this</font> |
|
<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> : |
|
l<font face='Lucida Console'>(</font>p.x<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, |
|
t<font face='Lucida Console'>(</font>p.y<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, |
|
r<font face='Lucida Console'>(</font>p.x<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, |
|
b<font face='Lucida Console'>(</font>p.y<font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<b>}</b> |
|
|
|
<b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p1, |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p2 |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> |
|
<b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> p1, |
|
<font color='#0000FF'>const</font> vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> p2 |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<b><a name='rectangle'></a>rectangle</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> : |
|
l<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, |
|
t<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, |
|
r<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>, |
|
b<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b><b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font> <b><a name='top'></a>top</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> t; <b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font><font color='#5555FF'>&</font> <b><a name='top'></a>top</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> t; <b>}</b> |
|
|
|
<font color='#0000FF'><u>void</u></font> <b><a name='set_top'></a>set_top</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>long</u></font> top_ |
|
<font face='Lucida Console'>)</font> <b>{</b> t <font color='#5555FF'>=</font> top_; <b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font> <b><a name='left'></a>left</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> l; <b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font><font color='#5555FF'>&</font> <b><a name='left'></a>left</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> l; <b>}</b> |
|
|
|
<font color='#0000FF'><u>void</u></font> <b><a name='set_left'></a>set_left</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>long</u></font> left_ |
|
<font face='Lucida Console'>)</font> <b>{</b> l <font color='#5555FF'>=</font> left_; <b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font> <b><a name='right'></a>right</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> r; <b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font><font color='#5555FF'>&</font> <b><a name='right'></a>right</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> r; <b>}</b> |
|
|
|
<font color='#0000FF'><u>void</u></font> <b><a name='set_right'></a>set_right</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>long</u></font> right_ |
|
<font face='Lucida Console'>)</font> <b>{</b> r <font color='#5555FF'>=</font> right_; <b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font> <b><a name='bottom'></a>bottom</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> b; <b>}</b> |
|
|
|
<font color='#0000FF'><u>long</u></font><font color='#5555FF'>&</font> <b><a name='bottom'></a>bottom</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> b; <b>}</b> |
|
|
|
<font color='#0000FF'><u>void</u></font> <b><a name='set_bottom'></a>set_bottom</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>long</u></font> bottom_ |
|
<font face='Lucida Console'>)</font> <b>{</b> b <font color='#5555FF'>=</font> bottom_; <b>}</b> |
|
|
|
<font color='#0000FF'>const</font> point <b><a name='tl_corner'></a>tl_corner</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b> |
|
|
|
<font color='#0000FF'>const</font> point <b><a name='bl_corner'></a>bl_corner</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b> |
|
|
|
<font color='#0000FF'>const</font> point <b><a name='tr_corner'></a>tr_corner</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b> |
|
|
|
<font color='#0000FF'>const</font> point <b><a name='br_corner'></a>br_corner</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b> |
|
|
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='width'></a>width</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'>else</font> |
|
<font color='#0000FF'>return</font> r <font color='#5555FF'>-</font> l <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='height'></a>height</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'>else</font> |
|
<font color='#0000FF'>return</font> b <font color='#5555FF'>-</font> t <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='area'></a>area</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>bool</u></font> <b><a name='is_empty'></a>is_empty</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>t <font color='#5555FF'>></font> b <font color='#5555FF'>|</font><font color='#5555FF'>|</font> l <font color='#5555FF'>></font> r<font face='Lucida Console'>)</font>; <b>}</b> |
|
|
|
rectangle <b><a name='operator'></a>operator</b> <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rhs.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> rhs; |
|
|
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font> <font face='Lucida Console'>(</font> |
|
std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>l,rhs.l<font face='Lucida Console'>)</font>, |
|
std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>t,rhs.t<font face='Lucida Console'>)</font>, |
|
std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>r,rhs.r<font face='Lucida Console'>)</font>, |
|
std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>b,rhs.b<font face='Lucida Console'>)</font> |
|
<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
rectangle <b><a name='intersect'></a>intersect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font> <font face='Lucida Console'>(</font> |
|
std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>l,rhs.l<font face='Lucida Console'>)</font>, |
|
std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>t,rhs.t<font face='Lucida Console'>)</font>, |
|
std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>r,rhs.r<font face='Lucida Console'>)</font>, |
|
std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>b,rhs.b<font face='Lucida Console'>)</font> |
|
<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>bool</u></font> <b><a name='contains'></a>contains</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> l <font color='#5555FF'>|</font><font color='#5555FF'>|</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> r <font color='#5555FF'>|</font><font color='#5555FF'>|</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> t <font color='#5555FF'>|</font><font color='#5555FF'>|</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> b<font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>bool</u></font> <b><a name='contains'></a>contains</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>long</u></font> x, |
|
<font color='#0000FF'><u>long</u></font> y |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>x <font color='#5555FF'><</font> l <font color='#5555FF'>|</font><font color='#5555FF'>|</font> x <font color='#5555FF'>></font> r <font color='#5555FF'>|</font><font color='#5555FF'>|</font> y <font color='#5555FF'><</font> t <font color='#5555FF'>|</font><font color='#5555FF'>|</font> y <font color='#5555FF'>></font> b<font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>bool</u></font> <b><a name='contains'></a>contains</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>rect <font color='#5555FF'>+</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
rectangle<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
rectangle<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>+</font> rect; |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>l <font color='#5555FF'>=</font><font color='#5555FF'>=</font> rect.l<font face='Lucida Console'>)</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font face='Lucida Console'>(</font>t <font color='#5555FF'>=</font><font color='#5555FF'>=</font> rect.t<font face='Lucida Console'>)</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font face='Lucida Console'>(</font>r <font color='#5555FF'>=</font><font color='#5555FF'>=</font> rect.r<font face='Lucida Console'>)</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font face='Lucida Console'>(</font>b <font color='#5555FF'>=</font><font color='#5555FF'>=</font> rect.b<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>!</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> rect<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>inline</font> <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'><</font> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&</font> b<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> b.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> b.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> b.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> b.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> b.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> b.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> b.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> b.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>private</font>: |
|
<font color='#0000FF'><u>long</u></font> l; |
|
<font color='#0000FF'><u>long</u></font> t; |
|
<font color='#0000FF'><u>long</u></font> r; |
|
<font color='#0000FF'><u>long</u></font> b; |
|
<b>}</b>; |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='serialize'></a>serialize</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> item, |
|
std::ostream<font color='#5555FF'>&</font> out |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>try</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,out<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,out<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,out<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,out<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>serialization_error<font color='#5555FF'>&</font> e<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>throw</font> <font color='#BB00BB'>serialization_error</font><font face='Lucida Console'>(</font>e.info <font color='#5555FF'>+</font> "<font color='#CC0000'>\n while serializing an object of type rectangle</font>"<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='deserialize'></a>deserialize</b> <font face='Lucida Console'>(</font> |
|
rectangle<font color='#5555FF'>&</font> item, |
|
std::istream<font color='#5555FF'>&</font> in |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>try</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,in<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>serialization_error<font color='#5555FF'>&</font> e<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>throw</font> <font color='#BB00BB'>serialization_error</font><font face='Lucida Console'>(</font>e.info <font color='#5555FF'>+</font> "<font color='#CC0000'>\n while deserializing an object of type rectangle</font>"<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>inline</font> std::ostream<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'><</font><font color='#5555FF'><</font> <font face='Lucida Console'>(</font> |
|
std::ostream<font color='#5555FF'>&</font> out, |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> item |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
out <font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>[(</font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> item.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>, </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> item.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>) (</font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> item.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>, </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> item.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>)]</font>"; |
|
<font color='#0000FF'>return</font> out; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>inline</font> std::istream<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font> |
|
std::istream<font color='#5555FF'>&</font> in, |
|
rectangle<font color='#5555FF'>&</font> item |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// ignore any whitespace |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'> </font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\t</font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\r</font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font> |
|
in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// now eat the leading '[' character |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> '<font color='#FF0000'>[</font>'<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
in.<font color='#BB00BB'>setstate</font><font face='Lucida Console'>(</font>in.<font color='#BB00BB'>rdstate</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font> std::ios::failbit<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> in; |
|
<b>}</b> |
|
|
|
point p1, p2; |
|
in <font color='#5555FF'>></font><font color='#5555FF'>></font> p1; |
|
in <font color='#5555FF'>></font><font color='#5555FF'>></font> p2; |
|
item <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// ignore any whitespace |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'> </font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\t</font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\r</font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font> |
|
in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// now eat the trailing ']' character |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> '<font color='#FF0000'>]</font>'<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
in.<font color='#BB00BB'>setstate</font><font face='Lucida Console'>(</font>in.<font color='#BB00BB'>rdstate</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font> std::ios::failbit<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> in; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='centered_rect'></a>centered_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>long</u></font> x, |
|
<font color='#0000FF'><u>long</u></font> y, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
rectangle result; |
|
result.<font color='#BB00BB'>set_left</font> <font face='Lucida Console'>(</font> x <font color='#5555FF'>-</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>width<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font> <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_top</font> <font face='Lucida Console'>(</font> y <font color='#5555FF'>-</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>height<font face='Lucida Console'>)</font> <font color='#5555FF'>/</font> <font color='#979000'>2</font> <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_right</font> <font face='Lucida Console'>(</font> result.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> width <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_bottom</font> <font face='Lucida Console'>(</font> result.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> height <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> result; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> rectangle <b><a name='intersect'></a>intersect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> a, |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> b |
|
<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> a.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>b<font face='Lucida Console'>)</font>; <b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='area'></a>area</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> a |
|
<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> a.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> point <b><a name='center'></a>center</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&</font> rect |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
point <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>, |
|
rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
temp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
temp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
|
|
<font color='#0000FF'>return</font> temp<font color='#5555FF'>/</font><font color='#979000'>2</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> dlib::vector<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>></font> <b><a name='dcenter'></a>dcenter</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> dlib::rectangle<font color='#5555FF'>&</font> rect |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
dlib::vector<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>></font> <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, |
|
rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>return</font> temp<font color='#5555FF'>/</font><font color='#979000'>2.0</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'><u>long</u></font> <b><a name='distance_to_rect_edge'></a>distance_to_rect_edge</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>using</font> std::max; |
|
<font color='#0000FF'>using</font> std::min; |
|
<font color='#0000FF'>using</font> std::abs; |
|
|
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dist_x <font color='#5555FF'>=</font> <font color='#BB00BB'>min</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> dist_y <font color='#5555FF'>=</font> <font color='#BB00BB'>min</font><font face='Lucida Console'>(</font><font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>dist_x,dist_y<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> dist_y; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> dist_x; |
|
<font color='#0000FF'>else</font> |
|
<font color='#0000FF'>return</font> dist_x <font color='#5555FF'>+</font> dist_y; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font> <b><a name='nearest_point'></a>nearest_point</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font> <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
temp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
temp.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
temp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
temp.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>return</font> temp; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'><u>size_t</u></font> <b><a name='nearest_rect'></a>nearest_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font>rectangle<font color='#5555FF'>></font><font color='#5555FF'>&</font> rects, |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'><u>size_t</u></font> idx <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'><u>double</u></font> best_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>></font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>size_t</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rects[i].<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> i; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#0000FF'><u>double</u></font> dist <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>nearest_point</font><font face='Lucida Console'>(</font>rects[i],p<font face='Lucida Console'>)</font><font color='#5555FF'>-</font>p<font face='Lucida Console'>)</font>.<font color='#BB00BB'>length</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>dist <font color='#5555FF'><</font> best_dist<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
best_dist <font color='#5555FF'>=</font> dist; |
|
idx <font color='#5555FF'>=</font> i; |
|
<b>}</b> |
|
<b>}</b> |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> idx; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='clip_line_to_rectangle'></a>clip_line_to_rectangle</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> box, |
|
dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> p1, |
|
dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font><font color='#5555FF'>&</font> p2 |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// Now clip the line segment so it is contained inside box. |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> box.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> box.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>p1.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p1.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> box.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> box.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#009900'>// We use these relations to find alpha values. These values tell us |
|
</font> <font color='#009900'>// how to generate points intersecting the rectangle boundaries. We then |
|
</font> <font color='#009900'>// test the resulting points for ones that are inside the rectangle and output |
|
</font> <font color='#009900'>// those. |
|
</font> <font color='#009900'>//box.left() == alpha1*(p1.x()-p2.x()) + p2.x(); |
|
</font> <font color='#009900'>//box.right() == alpha2*(p1.x()-p2.x()) + p2.x(); |
|
</font> |
|
<font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font> d <font color='#5555FF'>=</font> p1<font color='#5555FF'>-</font>p2; |
|
<font color='#0000FF'><u>double</u></font> alpha1 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>box.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font>p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>d.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'><u>double</u></font> alpha2 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>box.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font>p2.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>d.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'><u>double</u></font> alpha3 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>box.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font>p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>d.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'><u>double</u></font> alpha4 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>box.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>p2.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>d.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font> c1 <font color='#5555FF'>=</font> alpha1<font color='#5555FF'>*</font>d <font color='#5555FF'>+</font> p2; |
|
<font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font> c2 <font color='#5555FF'>=</font> alpha2<font color='#5555FF'>*</font>d <font color='#5555FF'>+</font> p2; |
|
<font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font> c3 <font color='#5555FF'>=</font> alpha3<font color='#5555FF'>*</font>d <font color='#5555FF'>+</font> p2; |
|
<font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'><</font>T,<font color='#979000'>2</font><font color='#5555FF'>></font> c4 <font color='#5555FF'>=</font> alpha4<font color='#5555FF'>*</font>d <font color='#5555FF'>+</font> p2; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p1 <font color='#5555FF'>=</font> c1; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p2 <font color='#5555FF'>=</font> c2; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>c3<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p2 <font color='#5555FF'>=</font> c3; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p1 <font color='#5555FF'>=</font> c3; |
|
<b>}</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>c4<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p2<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p2 <font color='#5555FF'>=</font> c4; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>box.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>p1<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
p1 <font color='#5555FF'>=</font> c4; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
p1 <font color='#5555FF'>=</font> <font color='#BB00BB'>nearest_point</font><font face='Lucida Console'>(</font>box, p1<font face='Lucida Console'>)</font>; |
|
p2 <font color='#5555FF'>=</font> <font color='#BB00BB'>nearest_point</font><font face='Lucida Console'>(</font>box, p2<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='centered_rect'></a>centered_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,width,height<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> std::vector<font color='#5555FF'><</font>rectangle<font color='#5555FF'>></font> <b><a name='centered_rects'></a>centered_rects</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font>point<font color='#5555FF'>></font><font color='#5555FF'>&</font> pts, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
std::vector<font color='#5555FF'><</font>rectangle<font color='#5555FF'>></font> tmp; |
|
tmp.<font color='#BB00BB'>reserve</font><font face='Lucida Console'>(</font>pts.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>auto</font><font color='#5555FF'>&</font> p : pts<font face='Lucida Console'>)</font> |
|
tmp.<font color='#BB00BB'>emplace_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>p, width, height<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> tmp; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='centered_rect'></a>centered_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>, <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>, width, height<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='shrink_rect'></a>shrink_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>long</u></font> num |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>num, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>num, rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>num, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>num<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='grow_rect'></a>grow_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>long</u></font> num |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font>rect, <font color='#5555FF'>-</font>num<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='shrink_rect'></a>shrink_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>long</u></font> width, |
|
<font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>width, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>height, rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>width, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>height<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='grow_rect'></a>grow_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>long</u></font> width, |
|
<font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>shrink_rect</font><font face='Lucida Console'>(</font>rect, <font color='#5555FF'>-</font>width, <font color='#5555FF'>-</font>height<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='scale_rect'></a>scale_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>double</u></font> scale |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>scale <font color='#5555FF'>></font> <font color='#979000'>0</font>, "<font color='#CC0000'>scale factor must be > 0</font>"<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'><u>long</u></font> l <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>scale<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'><u>long</u></font> t <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>scale<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'><u>long</u></font> r <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>scale<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'><u>long</u></font> b <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>scale<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>l, t, r, b<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='translate_rect'></a>translate_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
rectangle result; |
|
result.<font color='#BB00BB'>set_top</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_bottom</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_left</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_right</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> result; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='translate_rect'></a>translate_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>long</u></font> x, |
|
<font color='#0000FF'><u>long</u></font> y |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
rectangle result; |
|
result.<font color='#BB00BB'>set_top</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> y <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_bottom</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> y <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_left</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> x <font face='Lucida Console'>)</font>; |
|
result.<font color='#BB00BB'>set_right</font> <font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> x <font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> result; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='resize_rect'></a>resize_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, |
|
rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font>, |
|
rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='resize_rect_width'></a>resize_rect_width</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, |
|
rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>width<font color='#5555FF'>-</font><font color='#979000'>1</font>, |
|
rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='resize_rect_height'></a>resize_rect_height</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, |
|
rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, |
|
rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='move_rect'></a>move_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='move_rect'></a>move_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>long</u></font> x, |
|
<font color='#0000FF'><u>long</u></font> y |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>x, y, x<font color='#5555FF'>+</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, y<font color='#5555FF'>+</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> rectangle <b><a name='set_rect_area'></a>set_rect_area</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> area |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>area <font color='#5555FF'>></font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// In this case we will make the output rectangle a square with the requested |
|
</font> <font color='#009900'>// area. |
|
</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> scale <font color='#5555FF'>=</font> std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>area<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>rect, scale, scale<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#0000FF'><u>double</u></font> scale <font color='#5555FF'>=</font> std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>area<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font><font face='Lucida Console'>)</font>rect.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>rect, <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>scale<font face='Lucida Console'>)</font>, <font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>round</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>scale<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> rectangle <b><a name='set_aspect_ratio'></a>set_aspect_ratio</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> rect, |
|
<font color='#0000FF'><u>double</u></font> ratio |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>ratio <font color='#5555FF'>></font> <font color='#979000'>0</font>, |
|
"<font color='#CC0000'>\t rectangle set_aspect_ratio()</font>" |
|
<font color='#5555FF'><</font><font color='#5555FF'><</font> "<font color='#CC0000'>\n\t ratio: </font>" <font color='#5555FF'><</font><font color='#5555FF'><</font> ratio |
|
<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// aspect ratio is w/h |
|
</font> |
|
<font color='#009900'>// we need to find the rectangle that is nearest to rect in area but |
|
</font> <font color='#009900'>// with an aspect ratio of ratio. |
|
</font> |
|
<font color='#009900'>// w/h == ratio |
|
</font> <font color='#009900'>// w*h == rect.area() |
|
</font> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ratio <font color='#5555FF'>></font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> h <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>ratio<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>0.5</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> w <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>h<font color='#5555FF'>*</font>ratio <font color='#5555FF'>+</font> <font color='#979000'>0.5</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>rect, w, h<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> w <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>sqrt</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>area</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>ratio<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>0.5</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> h <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font face='Lucida Console'>(</font>w<font color='#5555FF'>/</font>ratio <font color='#5555FF'>+</font> <font color='#979000'>0.5</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>rect, w, h<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>template</font> <font color='#5555FF'><</font> |
|
<font color='#0000FF'>typename</font> T |
|
<font color='#5555FF'>></font> |
|
<font color='#0000FF'>inline</font> <font color='#0000FF'>const</font> rectangle <b><a name='get_rect'></a>get_rect</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> m |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>, <font color='#979000'>0</font>, <font color='#BB00BB'>num_columns</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font>, <font color='#BB00BB'>num_rows</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> rectangle <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> r, |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> r <font color='#5555FF'>+</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>inline</font> rectangle <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> point<font color='#5555FF'>&</font> p, |
|
<font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&</font> r |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> r <font color='#5555FF'>+</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_RECTANGLe_ |
|
</font> |
|
|
|
|
|
</pre></body></html> |