bool FindPoints(int N, int M, int A, int &x1, int &y1, int &x2, int &y2, int &x3, int &y3) { if (A > N * M) return false; // -------------------------------------------------------------- //int H = A / M; // N //int R = A % M; // N //x1 = 0; y1 = 0; //x2 = M; // N //if (R == 0) //{ // y2 = 0; // x3 = 0; y3 = H; //} //else //{ // y2 = 1; // x3 = M - R; //(N*M - A) % M; // y3 = H + 1; //} //return true; // -------------------------------------------------------------- //int P = A - A % N; //if (P < A) //{ // P += N; //} //x1 = 0; y1 = 0; //x2 = M; y2 = 1; //x3 = P - A; y3 = P / N; //return true; // -------------------------------------------------------------- //x1 = 0; y1 = 0; //x2 = M; y2 = 1; //x3 = -(A % M); //while (x3 < 0) //{ // x3 += M; //} //y3 = A / M + 1; //return true; // -------------------------------------------------------------- // -------------------------------------------------------------- int area = 0; // (x1 y1) x1 = 0; y1 = 0; while ((area + A) <= (N * M)) { // {x2} [y2 x3] {y3} if (TestArea(area, N, M, x3, y2) && TestArea(area + A, N, M, x2, y3)) { return true; } ++area; } return false; // -------------------------------------------------------------- // -------------------------------------------------------------- //int size = 0; //int areas[ 20000 ]; //for (int i = 0; i <= N; ++i) //{ // for (int j = 0; j <= M; ++j) // { // areas[ size++ ] = i * j; // } //} //std::sort//<int[]> // (areas, areas + size); //int k = 0; //x1 = 0; y1 = 0; //for (int i = 0; i < size; ++i) //{ // for (; k < size && areas[ k ] - areas[ i ] < A; ++k) // ; // if (k == size) break; // // if (areas[ k ] - areas[ i ] == A) // { // TestArea(areas[ i ], N, M, x3, y2); // TestArea(areas[ k ], N, M, x2, y3); // return true; // } //} //return false; // -------------------------------------------------------------- }
/* ============ idAASCallback::Test ============ */ idAASCallback::testResult_t idAASCallback::Test ( class idAAS *aas, int areaNum, const idVec3& origin, float minDistance, float maxDistance, const idVec3* point, aasGoal_t& goal ) { // Get AAS file idAASFile* file = ((idAAS&)*aas).GetFile ( ); if ( !file ) { return TEST_BADAREA; } // Get area for edges aasArea_t& area = file->GetArea ( areaNum ); if ( ai_debugTactical.GetInteger ( ) > 1 ) { gameRenderWorld->DebugLine ( colorYellow, area.center, area.center + idVec3(0,0,80.0f), 10000 ); } // Make sure the area itself is valid if ( !TestArea ( aas, areaNum, area ) ) { return TEST_BADAREA; } if ( ai_debugTactical.GetInteger ( ) > 1 && point ) { gameRenderWorld->DebugLine ( colorMagenta, *point, *point + idVec3(0,0,64.0f), 10000 ); } // Test the original origin first if ( point && TestPointDistance ( origin, *point, minDistance, maxDistance) && TestPoint ( aas, *point ) ) { goal.areaNum = areaNum; goal.origin = *point; return TEST_OK; } if ( ai_debugTactical.GetInteger ( ) > 1 ) { gameRenderWorld->DebugLine ( colorCyan, area.center, area.center + idVec3(0,0,64.0f), 10000 ); } // Test the center of the area if ( TestPointDistance ( origin, area.center, minDistance, maxDistance) && TestPoint ( aas, area.center, area.ceiling ) ) { goal.areaNum = areaNum; goal.origin = area.center; return TEST_OK; } // For each face test all available edges int f; int e; for ( f = 0; f < area.numFaces; f ++ ) { aasFace_t& face = file->GetFace ( abs ( file->GetFaceIndex (area.firstFace + f ) ) ); // for each edge test a point between the center of the edge and the center for ( e = 0; e < face.numEdges; e ++ ) { idVec3 edgeCenter = file->EdgeCenter ( abs( file->GetEdgeIndex( face.firstEdge + e ) ) ); idVec3 dir = area.center - edgeCenter; float dist; for ( dist = dir.Normalize() - 64.0f; dist > 0.0f; dist -= 64.0f ) { idVec3 testPoint = edgeCenter + dir * dist; if ( ai_debugTactical.GetInteger ( ) > 1 ) { gameRenderWorld->DebugLine ( colorPurple, testPoint, testPoint + idVec3(0,0,64.0f), 10000 ); } if ( TestPointDistance ( origin, testPoint, minDistance, maxDistance) && TestPoint ( aas, testPoint, area.ceiling ) ) { goal.areaNum = areaNum; goal.origin = testPoint; return TEST_OK; } } } } return TEST_BADPOINT; }