Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import TSP.Coordinate;
- import TSP.TSP_Algorithm;
- import java.awt.*;
- import java.lang.reflect.Array;
- import java.util.*;
- import java.util.List;
- public class Convex extends TSP_Algorithm {
- ArrayList<Coordinate> coords = new ArrayList<Coordinate>();
- ArrayList<Coordinate> sortedCoords = new ArrayList<Coordinate>();
- ArrayList<Coordinate> coordinaten = new ArrayList<Coordinate>();
- public Convex(ArrayList<Coordinate> coords) {
- this.coords = coords;
- coordinaten = this.coords;
- }
- public ArrayList<Coordinate> getSortedCoordinates() {
- int coordsSize = (coords).size();
- ArrayList<Point> Points = coordToPoint(coords);
- // Points.sort(new PointXDescending());
- // Points.sort(new PointYDescending());
- Points.sort(new PointYAscending());
- Points.sort(new PointXAscending());
- for (Point points : Points) {
- Coordinate Even = new Coordinate(0, 0);
- Coordinate Odd = new Coordinate(0, 0);
- if (points.x % 2 == 0) {
- Even.x = points.x;
- Even.y = points.y;
- sortedCoords.add(Even);
- System.out.println(Even);
- }
- if (points.x % 2 != 0) {
- Odd.x = points.x;
- Odd.y = points.y;
- sortedCoords.add(Odd);
- System.out.println(Odd);
- }
- }
- return sortedCoords;
- }
- public ArrayList<Point> coordToPoint(ArrayList<Coordinate> coords) {
- ArrayList<Point> points = new ArrayList<Point>();
- for (Coordinate coord : coords) {
- points.add(new Point(coord.x, coord.y));
- }
- return points;
- }
- public class PointXAscending implements Comparator<Point> {
- public int compare(Point a, Point b) {
- {
- return Integer.compare(a.x, b.x);
- }
- }
- } // X oplopend
- public class PointXDescending implements Comparator<Point> {
- public int compare(Point a, Point b) {
- {
- return Integer.compare(b.x, a.x);
- }
- }
- } // X aflopend
- public class PointYDescending implements Comparator<Point> {
- public int compare(Point a, Point b) {
- {
- return Integer.compare(b.y, a.y);
- }
- }
- } // Y oplopend
- public class PointYAscending implements Comparator<Point> {
- public int compare(Point a, Point b) {
- {
- return Integer.compare(a.y, b.y);
- }
- }
- } // Y aflopend
- }
Add Comment
Please, Sign In to add comment