Guest User

Untitled

a guest
May 20th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import TSP.Coordinate;
  2. import TSP.TSP_Algorithm;
  3.  
  4. import java.awt.*;
  5. import java.lang.reflect.Array;
  6. import java.util.*;
  7. import java.util.List;
  8.  
  9. public class Convex extends TSP_Algorithm {
  10. ArrayList<Coordinate> coords = new ArrayList<Coordinate>();
  11. ArrayList<Coordinate> sortedCoords = new ArrayList<Coordinate>();
  12. ArrayList<Coordinate> coordinaten = new ArrayList<Coordinate>();
  13.  
  14. public Convex(ArrayList<Coordinate> coords) {
  15. this.coords = coords;
  16. coordinaten = this.coords;
  17. }
  18.  
  19. public ArrayList<Coordinate> getSortedCoordinates() {
  20.  
  21. int coordsSize = (coords).size();
  22.  
  23. ArrayList<Point> Points = coordToPoint(coords);
  24. // Points.sort(new PointXDescending());
  25. // Points.sort(new PointYDescending());
  26. Points.sort(new PointYAscending());
  27. Points.sort(new PointXAscending());
  28.  
  29. for (Point points : Points) {
  30. Coordinate Even = new Coordinate(0, 0);
  31. Coordinate Odd = new Coordinate(0, 0);
  32.  
  33. if (points.x % 2 == 0) {
  34. Even.x = points.x;
  35. Even.y = points.y;
  36. sortedCoords.add(Even);
  37. System.out.println(Even);
  38. }
  39.  
  40. if (points.x % 2 != 0) {
  41. Odd.x = points.x;
  42. Odd.y = points.y;
  43. sortedCoords.add(Odd);
  44. System.out.println(Odd);
  45. }
  46. }
  47. return sortedCoords;
  48. }
  49.  
  50. public ArrayList<Point> coordToPoint(ArrayList<Coordinate> coords) {
  51. ArrayList<Point> points = new ArrayList<Point>();
  52.  
  53. for (Coordinate coord : coords) {
  54. points.add(new Point(coord.x, coord.y));
  55. }
  56. return points;
  57. }
  58.  
  59. public class PointXAscending implements Comparator<Point> {
  60. public int compare(Point a, Point b) {
  61. {
  62. return Integer.compare(a.x, b.x);
  63. }
  64. }
  65.  
  66. } // X oplopend
  67.  
  68. public class PointXDescending implements Comparator<Point> {
  69. public int compare(Point a, Point b) {
  70. {
  71. return Integer.compare(b.x, a.x);
  72. }
  73. }
  74. } // X aflopend
  75.  
  76. public class PointYDescending implements Comparator<Point> {
  77. public int compare(Point a, Point b) {
  78. {
  79. return Integer.compare(b.y, a.y);
  80. }
  81. }
  82. } // Y oplopend
  83.  
  84. public class PointYAscending implements Comparator<Point> {
  85. public int compare(Point a, Point b) {
  86. {
  87. return Integer.compare(a.y, b.y);
  88. }
  89. }
  90. } // Y aflopend
  91. }
Add Comment
Please, Sign In to add comment