1/*
2 * Copyright (C) 2007 Tomasz Boczkowski <tboczkowski@onet.pl>
3 *
4 * This file is part of the KDE project "KBounce"
5 *
6 * KBounce is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * KBounce is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with KBounce; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "gameobject.h"
23
24KBounceVector KBounceVector::normal( const QRectF& rect1, const QRectF& rect2 )
25{
26 KBounceVector normal( 0, 0 );
27
28 if ( rect1.bottom() > rect2.top() && rect1.bottom() < rect2.bottom() )
29 normal += KBounceVector( 0, -1 );
30 if ( rect1.top() < rect2.bottom() && rect1.top() > rect2.top() )
31 normal += KBounceVector( 0, 1 );
32 if ( rect1.right() < rect2.right() && rect1.right() > rect2.left() )
33 normal += KBounceVector( 1, 0 );
34 if ( rect1.left() > rect2.left() && rect1.left() < rect2.right() )
35 normal += KBounceVector( -1, 0 );
36
37 return normal;
38}
39
40