Renaming and comments to reflect the fact that the functions currently return a list of title positions (not a list of title instances)

This commit is contained in:
mossroy 2013-11-24 14:22:43 +01:00
parent 5c84a8fd79
commit 57cf1e5c18
2 changed files with 26 additions and 23 deletions

View File

@ -737,20 +737,20 @@ define(function(require) {
* found, the callbackFunction is called
*
* @param {type} localArchive
* @param {type} titlesFound
* @param {type} titlePositionsFound
* @param {type} i : index of the coordinate file
* @param {type} maxTitles
* @param {type} normalizedRectangle
* @param {type} callbackFunction
*/
LocalArchive.callbackGetTitlesInCoordsInt = function(localArchive, titlesFound, i, maxTitles, normalizedRectangle, callbackFunction) {
LocalArchive.callbackGetTitlesInCoordsInt = function(localArchive, titlePositionsFound, i, maxTitles, normalizedRectangle, callbackFunction) {
i++;
if (titlesFound.length < maxTitles && i < localArchive.coordinateFiles.length) {
LocalArchive.getTitlesInCoordsInt(localArchive, i, 0, normalizedRectangle, GLOBE_RECTANGLE, maxTitles, titlesFound, callbackFunction, LocalArchive.callbackGetTitlesInCoordsInt);
if (titlePositionsFound.length < maxTitles && i < localArchive.coordinateFiles.length) {
LocalArchive.getTitlesInCoordsInt(localArchive, i, 0, normalizedRectangle, GLOBE_RECTANGLE, maxTitles, titlePositionsFound, callbackFunction, LocalArchive.callbackGetTitlesInCoordsInt);
}
else {
// TODO convert title_positions in titles
callbackFunction(titlesFound);
// TODO convert titlePositions in titles
callbackFunction(titlePositionsFound);
}
};
@ -777,11 +777,11 @@ define(function(require) {
* @param {type} targetRect
* @param {type} thisRect
* @param {type} maxTitles
* @param {type} titlesFound
* @param {type} titlePositionsFound
* @param {type} callbackFunction
* @param {type} callbackGetTitlesInCoordsInt
*/
LocalArchive.getTitlesInCoordsInt = function(localArchive, coordinateFileIndex, coordFilePos, targetRect, thisRect, maxTitles, titlesFound, callbackFunction, callbackGetTitlesInCoordsInt) {
LocalArchive.getTitlesInCoordsInt = function(localArchive, coordinateFileIndex, coordFilePos, targetRect, thisRect, maxTitles, titlePositionsFound, callbackFunction, callbackGetTitlesInCoordsInt) {
var reader = new FileReader();
reader.onerror = errorHandler;
reader.onabort = function(e) {
@ -813,16 +813,16 @@ define(function(require) {
var rectNE = (new geometry.rect(thisRect.corner(), center)).normalized();
// Recursively call this function for each rectangle around
if (targetRect.intersect(rectSW)) {
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos0, targetRect, rectSW, maxTitles, titlesFound, callbackFunction, callbackGetTitlesInCoordsInt);
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos0, targetRect, rectSW, maxTitles, titlePositionsFound, callbackFunction, callbackGetTitlesInCoordsInt);
}
if (targetRect.intersect(rectSE)) {
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos1, targetRect, rectSE, maxTitles, titlesFound, callbackFunction, callbackGetTitlesInCoordsInt);
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos1, targetRect, rectSE, maxTitles, titlePositionsFound, callbackFunction, callbackGetTitlesInCoordsInt);
}
if (targetRect.intersect(rectNW)) {
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos2, targetRect, rectNW, maxTitles, titlesFound, callbackFunction, callbackGetTitlesInCoordsInt);
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos2, targetRect, rectNW, maxTitles, titlePositionsFound, callbackFunction, callbackGetTitlesInCoordsInt);
}
if (targetRect.intersect(rectNE)) {
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos3, targetRect, rectNE, maxTitles, titlesFound, callbackFunction, callbackGetTitlesInCoordsInt);
LocalArchive.getTitlesInCoordsInt(localArchive, coordinateFileIndex, pos3, targetRect, rectNE, maxTitles, titlePositionsFound, callbackFunction, callbackGetTitlesInCoordsInt);
}
}
else {
@ -843,14 +843,16 @@ define(function(require) {
if (!targetRect.containsPoint(articleCoordinates)) {
continue;
}
// TODO also add the coordinates of each title
titlesFound.push(title_pos);
if (maxTitles >= 0 && titlesFound.length >= maxTitles) {
callbackGetTitlesInCoordsInt(localArchive, titlesFound, coordinateFileIndex, maxTitles, targetRect, callbackFunction);
// We currently do not use the article coordinates
// so it's no use putting it in the result list : we only put
// the position in title list
titlePositionsFound.push(title_pos);
if (maxTitles >= 0 && titlePositionsFound.length >= maxTitles) {
callbackGetTitlesInCoordsInt(localArchive, titlePositionsFound, coordinateFileIndex, maxTitles, targetRect, callbackFunction);
return;
}
}
callbackGetTitlesInCoordsInt(localArchive, titlesFound, coordinateFileIndex, maxTitles, targetRect, callbackFunction);
callbackGetTitlesInCoordsInt(localArchive, titlePositionsFound, coordinateFileIndex, maxTitles, targetRect, callbackFunction);
}
};

View File

@ -288,15 +288,15 @@ define(function(require) {
module("articles_nearby");
asyncTest("check articles found nearby France and Germany", function() {
var callbackTitlesNearbyFound = function(titles) {
ok(titles !== null, "Some titles should be found");
equal(titles.length, 3, "3 titles should be found");
var callbackTitlesNearbyFound = function(titlePositions) {
ok(titlePositions !== null, "Some titles should be found");
equal(titlePositions.length, 3, "3 titles should be found");
var titleDanube = null;
var titleParis = null;
var titleAlps = null;
for (var i=0; i<titles.length; i++) {
for (var i=0; i<titlePositions.length; i++) {
// TODO : read the titles instead of their position
var titlepos = titles[i];
var titlepos = titlePositions[i];
if (titlepos === 6030) {
titleDanube = titlepos;
}
@ -310,7 +310,8 @@ define(function(require) {
ok(titleDanube !== null, "The title 'Danube' should be found");
ok(titleParis !== null, "The title 'Paris' should be found");
ok(titleAlps !== null, "The title 'Alps' should be found");
// TODO : check the title name and coordinates of each title (or at least one)
// TODO : check the title name
start();
};
var rectFranceGermany = new geometry.rect(0,40,10,10);