krita
kis_perspective_grid.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kis_perspective_grid.h"
00022
00023 int KisSubPerspectiveGrid::s_lastIndex = 0;
00024
00025 KisSubPerspectiveGrid::KisSubPerspectiveGrid(KisPerspectiveGridNodeSP topLeft, KisPerspectiveGridNodeSP topRight, KisPerspectiveGridNodeSP bottomRight, KisPerspectiveGridNodeSP bottomLeft) : m_topLeft(topLeft), m_topRight(topRight), m_bottomRight(bottomRight), m_bottomLeft(bottomLeft), m_subdivisions(5), m_leftGrid(0), m_rightGrid(0), m_topGrid(0), m_bottomGrid(0), m_index(++s_lastIndex)
00026 {
00027
00028 }
00029
00030 bool KisSubPerspectiveGrid::contains(const KisPoint p) const
00031 {
00032 return true;
00033 KisPerspectiveMath::LineEquation d1 = KisPerspectiveMath::computeLineEquation( topLeft(), topRight() );
00034 kdDebug() << p.y() << " " << (p.x() * d1.a + d1.b) << endl;
00035 if( p.y() >= p.x() * d1.a + d1.b)
00036 {
00037 d1 = KisPerspectiveMath::computeLineEquation( topRight(), bottomRight() );
00038 kdDebug() << p.y() << " " << (p.x() * d1.a + d1.b) << endl;
00039 if( p.y() >= p.x() * d1.a + d1.b)
00040 {
00041 d1 = KisPerspectiveMath::computeLineEquation( bottomRight(), bottomLeft() );
00042 kdDebug() << p.y() << " " << (p.x() * d1.a + d1.b) << endl;
00043 if( p.y() <= p.x() * d1.a + d1.b)
00044 {
00045 d1 = KisPerspectiveMath::computeLineEquation( bottomLeft(), topLeft() );
00046 kdDebug() << p.y() << " " << (p.x() * d1.a + d1.b) << endl;
00047 if( p.y() <= p.x() * d1.a + d1.b)
00048 {
00049 return true;
00050 }
00051 }
00052 }
00053 }
00054 return false;
00055 }
00056
00057
00058 KisPerspectiveGrid::KisPerspectiveGrid()
00059 {
00060 }
00061
00062
00063 KisPerspectiveGrid::~KisPerspectiveGrid()
00064 {
00065 clearSubGrids( );
00066 }
00067
00068 bool KisPerspectiveGrid::addNewSubGrid( KisSubPerspectiveGrid* ng )
00069 {
00070 if(hasSubGrids() && !ng->topGrid() && !ng->bottomGrid() && !ng->leftGrid() && !ng->rightGrid() )
00071 {
00072 kdError() << "sub grids need a neighbourgh if they are not the first grid to be added" << endl;
00073 return false;
00074 }
00075 m_subGrids.push_back(ng);
00076 return true;
00077 }
00078
00079
00080 void KisPerspectiveGrid::clearSubGrids( )
00081 {
00082 for( QValueList<KisSubPerspectiveGrid*>::const_iterator it = begin(); it != end(); ++it)
00083 {
00084 delete *it;
00085 }
00086 m_subGrids.clear();
00087 }
00088
00089 KisSubPerspectiveGrid* KisPerspectiveGrid::gridAt(KisPoint p)
00090 {
00091 for( QValueList<KisSubPerspectiveGrid*>::const_iterator it = begin(); it != end(); ++it)
00092 {
00093 if( (*it)->contains(p) )
00094 {
00095 return *it;
00096 }
00097 }
00098 return 0;
00099 }
00100
|