BuildInitialWholeIndex.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package index.alg;
  2. import index.entity.Point;
  3. import index.entity.WholeIndex;
  4. import index.file.OperateFile;
  5. import java.io.FileNotFoundException;
  6. import java.util.ArrayList;
  7. public class BuildInitialWholeIndex {
  8. //
  9. public WholeIndex build(ArrayList<Point> pointsList,Integer numOfGapsX,Integer numOfGapsY){
  10. pointsList.add(pointsList.get(0));
  11. Point point0 = pointsList.get(0);
  12. double minX = point0.getColX();
  13. double minY = point0.getColY();
  14. double maxX = point0.getColX();
  15. double maxY = point0.getColY();
  16. for (int i = 0 ; i < pointsList.size();i++){
  17. Point point = pointsList.get(i);
  18. double corX = point.getColX();
  19. double corY = point.getColY();
  20. if (corX < minX){
  21. minX = corX;
  22. }
  23. if (corX > maxX){
  24. maxX = corX;
  25. }
  26. if (corY < minY){
  27. minY = corY;
  28. }
  29. if (corY > maxY){
  30. maxY = corY;
  31. }
  32. }
  33. double xGap = (maxX - minX) / numOfGapsX;
  34. double yGap = (maxY - minY) / numOfGapsY;
  35. WholeIndex wholeIndex = new WholeIndex();
  36. wholeIndex.setMinX(minX);
  37. wholeIndex.setMinY(minY);
  38. wholeIndex.setNumOfGapsX(numOfGapsX);
  39. wholeIndex.setNumOfGapsY(numOfGapsY);
  40. wholeIndex.setxGap(xGap);
  41. wholeIndex.setyGap(yGap);
  42. return wholeIndex;
  43. }
  44. }