File indexing completed on 2024-04-28 04:02:02

0001 /*
0002     This file is part of the KDE project "KBounce"
0003 
0004     SPDX-FileCopyrightText: 2007 Tomasz Boczkowski <tboczkowski@onet.pl>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "gameobject.h"
0010 
0011 KBounceVector KBounceVector::normal( const QRectF& rect1, const QRectF& rect2 )
0012 {
0013     KBounceVector normal( 0, 0 );
0014 
0015     if ( rect1.bottom() > rect2.top() && rect1.bottom() < rect2.bottom() )
0016         normal += KBounceVector( 0, -1 );
0017     if ( rect1.top() < rect2.bottom() && rect1.top() > rect2.top() )
0018         normal += KBounceVector( 0, 1 );
0019     if ( rect1.right() < rect2.right() && rect1.right() > rect2.left() )
0020         normal += KBounceVector( 1, 0 );
0021     if ( rect1.left() > rect2.left() && rect1.left() < rect2.right() )
0022         normal += KBounceVector( -1, 0 );
0023 
0024     return normal;
0025 }
0026