Java algorithm to fly over areaKruskal's algorithm in JavaArea Calculator in JavaJava Quicksort...

Is Social Media Science Fiction?

Why do we use polarized capacitor?

What is the offset in a seaplane's hull?

How to make payment on the internet without leaving a money trail?

Is there a minimum number of transactions in a block?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

Why is the design of haulage companies so “special”?

Copenhagen passport control - US citizen

DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?

Download, install and reboot computer at night if needed

Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?

How can bays and straits be determined in a procedurally generated map?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Is there a familial term for apples and pears?

Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).

How does one intimidate enemies without having the capacity for violence?

Can Medicine checks be used, with decent rolls, to completely mitigate the risk of death from ongoing damage?

Motorized valve interfering with button?

What defenses are there against being summoned by the Gate spell?

Is it possible to do 50 km distance without any previous training?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Prevent a directory in /tmp from being deleted

Circuitry of TV splitters



Java algorithm to fly over area


Kruskal's algorithm in JavaArea Calculator in JavaJava Quicksort AlgorithmImplementation of stackBubble sort algorithm in JavaGenetic algorithm in JavaAnytime algorithm in Javajava - A* search algorithmJava Pathfinding Lee AlgorithmA Java Iterable over multiple arrays






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1












$begingroup$


I have this algorithm that generates waypoints to fly over a specified area.
I would like to get some feedback to the coding inside the method, not about the structure of interfaces, I think this is pretty good here.
Despite any feedback is appreciated:)



public class RectangleWaypointGenerator implements WaypointGenerationAlgorithm {
public List<waypoints.Waypoint> addAutoGeneratedWaypoints(List<Waypoint> polygon_waypoints) {
List<Waypoint> waypoints = new ArrayList<>();
AreaTester tester = new GPSPolygonTester(polygon_waypoints);
GPSCoordinateCalculator coordinateCalculator = new GPSCoordinateCalculator();
CustomGPSMapper mapper = new CustomGPSMapper();

boolean finish = false;
String mode = "r";
Waypoint prev = polygon_waypoints.get(0);
double toRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());

double toUpRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(3).getPosition().getLatitude(), polygon_waypoints.get(3).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toUpLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(0).getPosition().getLatitude(), polygon_waypoints.get(0).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());
double distanceDown = mapper.distanceInKmBetweenGPSCoordinates(polygon_waypoints.get(2), polygon_waypoints.get(3));
double travelledDown = 0;
while (!finish) {
if (mode.equals("r")) {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15.0, toRight);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "l";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpRight);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
} else {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15, toLeft);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "r";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpLeft);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
}
if (travelledDown >= distanceDown) {
finish = true;
}
}

return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());
}
}









share|improve this question









$endgroup$








  • 1




    $begingroup$
    Why do you instantiate a new Waypoint for every WayPoint at the last line?
    $endgroup$
    – dustytrash
    Apr 2 at 13:16










  • $begingroup$
    that is just a mapping from an API Waypoint to my own waypoint that provides extended functionality for export operations. I know this looks weird:)
    $endgroup$
    – ItFreak
    Apr 2 at 13:21


















1












$begingroup$


I have this algorithm that generates waypoints to fly over a specified area.
I would like to get some feedback to the coding inside the method, not about the structure of interfaces, I think this is pretty good here.
Despite any feedback is appreciated:)



public class RectangleWaypointGenerator implements WaypointGenerationAlgorithm {
public List<waypoints.Waypoint> addAutoGeneratedWaypoints(List<Waypoint> polygon_waypoints) {
List<Waypoint> waypoints = new ArrayList<>();
AreaTester tester = new GPSPolygonTester(polygon_waypoints);
GPSCoordinateCalculator coordinateCalculator = new GPSCoordinateCalculator();
CustomGPSMapper mapper = new CustomGPSMapper();

boolean finish = false;
String mode = "r";
Waypoint prev = polygon_waypoints.get(0);
double toRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());

double toUpRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(3).getPosition().getLatitude(), polygon_waypoints.get(3).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toUpLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(0).getPosition().getLatitude(), polygon_waypoints.get(0).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());
double distanceDown = mapper.distanceInKmBetweenGPSCoordinates(polygon_waypoints.get(2), polygon_waypoints.get(3));
double travelledDown = 0;
while (!finish) {
if (mode.equals("r")) {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15.0, toRight);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "l";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpRight);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
} else {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15, toLeft);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "r";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpLeft);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
}
if (travelledDown >= distanceDown) {
finish = true;
}
}

return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());
}
}









share|improve this question









$endgroup$








  • 1




    $begingroup$
    Why do you instantiate a new Waypoint for every WayPoint at the last line?
    $endgroup$
    – dustytrash
    Apr 2 at 13:16










  • $begingroup$
    that is just a mapping from an API Waypoint to my own waypoint that provides extended functionality for export operations. I know this looks weird:)
    $endgroup$
    – ItFreak
    Apr 2 at 13:21














1












1








1





$begingroup$


I have this algorithm that generates waypoints to fly over a specified area.
I would like to get some feedback to the coding inside the method, not about the structure of interfaces, I think this is pretty good here.
Despite any feedback is appreciated:)



public class RectangleWaypointGenerator implements WaypointGenerationAlgorithm {
public List<waypoints.Waypoint> addAutoGeneratedWaypoints(List<Waypoint> polygon_waypoints) {
List<Waypoint> waypoints = new ArrayList<>();
AreaTester tester = new GPSPolygonTester(polygon_waypoints);
GPSCoordinateCalculator coordinateCalculator = new GPSCoordinateCalculator();
CustomGPSMapper mapper = new CustomGPSMapper();

boolean finish = false;
String mode = "r";
Waypoint prev = polygon_waypoints.get(0);
double toRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());

double toUpRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(3).getPosition().getLatitude(), polygon_waypoints.get(3).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toUpLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(0).getPosition().getLatitude(), polygon_waypoints.get(0).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());
double distanceDown = mapper.distanceInKmBetweenGPSCoordinates(polygon_waypoints.get(2), polygon_waypoints.get(3));
double travelledDown = 0;
while (!finish) {
if (mode.equals("r")) {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15.0, toRight);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "l";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpRight);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
} else {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15, toLeft);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "r";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpLeft);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
}
if (travelledDown >= distanceDown) {
finish = true;
}
}

return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());
}
}









share|improve this question









$endgroup$




I have this algorithm that generates waypoints to fly over a specified area.
I would like to get some feedback to the coding inside the method, not about the structure of interfaces, I think this is pretty good here.
Despite any feedback is appreciated:)



public class RectangleWaypointGenerator implements WaypointGenerationAlgorithm {
public List<waypoints.Waypoint> addAutoGeneratedWaypoints(List<Waypoint> polygon_waypoints) {
List<Waypoint> waypoints = new ArrayList<>();
AreaTester tester = new GPSPolygonTester(polygon_waypoints);
GPSCoordinateCalculator coordinateCalculator = new GPSCoordinateCalculator();
CustomGPSMapper mapper = new CustomGPSMapper();

boolean finish = false;
String mode = "r";
Waypoint prev = polygon_waypoints.get(0);
double toRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());

double toUpRight = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(3).getPosition().getLatitude(), polygon_waypoints.get(3).getPosition().getLongitude(),
polygon_waypoints.get(2).getPosition().getLatitude(), polygon_waypoints.get(2).getPosition().getLongitude());
double toUpLeft = coordinateCalculator.calculateAngleBetweenWaypoints(polygon_waypoints.get(0).getPosition().getLatitude(), polygon_waypoints.get(0).getPosition().getLongitude(),
polygon_waypoints.get(1).getPosition().getLatitude(), polygon_waypoints.get(1).getPosition().getLongitude());
double distanceDown = mapper.distanceInKmBetweenGPSCoordinates(polygon_waypoints.get(2), polygon_waypoints.get(3));
double travelledDown = 0;
while (!finish) {
if (mode.equals("r")) {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15.0, toRight);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "l";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpRight);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
} else {
double[] nextA = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 15, toLeft);
Waypoint next = new DefaultWaypoint(nextA[0], nextA[1]);
if (tester.isInsideArea(next)) {
waypoints.add(next);
prev = next;
} else {
mode = "r";
double[] nextB = coordinateCalculator.movePoint(prev.getPosition().getLatitude(), prev.getPosition().getLongitude(), 10, toUpLeft);
Waypoint next2 = new DefaultWaypoint(nextB[0], nextB[1]);
waypoints.add(next2);
travelledDown += mapper.distanceInKmBetweenGPSCoordinates(prev, next);
prev = next2;
}
}
if (travelledDown >= distanceDown) {
finish = true;
}
}

return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());
}
}






java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 2 at 7:18









ItFreakItFreak

1575




1575








  • 1




    $begingroup$
    Why do you instantiate a new Waypoint for every WayPoint at the last line?
    $endgroup$
    – dustytrash
    Apr 2 at 13:16










  • $begingroup$
    that is just a mapping from an API Waypoint to my own waypoint that provides extended functionality for export operations. I know this looks weird:)
    $endgroup$
    – ItFreak
    Apr 2 at 13:21














  • 1




    $begingroup$
    Why do you instantiate a new Waypoint for every WayPoint at the last line?
    $endgroup$
    – dustytrash
    Apr 2 at 13:16










  • $begingroup$
    that is just a mapping from an API Waypoint to my own waypoint that provides extended functionality for export operations. I know this looks weird:)
    $endgroup$
    – ItFreak
    Apr 2 at 13:21








1




1




$begingroup$
Why do you instantiate a new Waypoint for every WayPoint at the last line?
$endgroup$
– dustytrash
Apr 2 at 13:16




$begingroup$
Why do you instantiate a new Waypoint for every WayPoint at the last line?
$endgroup$
– dustytrash
Apr 2 at 13:16












$begingroup$
that is just a mapping from an API Waypoint to my own waypoint that provides extended functionality for export operations. I know this looks weird:)
$endgroup$
– ItFreak
Apr 2 at 13:21




$begingroup$
that is just a mapping from an API Waypoint to my own waypoint that provides extended functionality for export operations. I know this looks weird:)
$endgroup$
– ItFreak
Apr 2 at 13:21










2 Answers
2






active

oldest

votes


















2












$begingroup$

Without doing a full re-write:



Are the methods in your helper classes static? Are they used elsewhere? Can they be made static in their home class? You may want to statically import these helper classes if they are not holding state.



You have a lot of indirection (a.b.c()) fetching the same objects repeatedly - consider putting these in variables before you use them. this will clean up the code and might reveal another method you can extract



Is there any reason movePoint() cannot just return a Waypoint?



There is a lot of common code in the if and else clauses - can this be extracted as a single method that takes the single letter flag?



You can just assign the finishing condition check to the finish variable and get rid of the if clause.



Overall - try to aim for a top level method that 'describes the algorithm' then use subordinate methods to take care of sub-operations.






share|improve this answer








New contributor




Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$





















    1












    $begingroup$

    Instead of using a variable 'finish', put the condition inside the loop:



    do {
    ...
    } while (travelledDown >= distanceDown)


    Your modes of "r" and "l" aren't very descriptive. You should use an ENUM here (Or atleast rename r/l if you don't want an ENUM)



    public Enum Mode
    {
    LEFT("L"),
    RIGHT("R")
    }
    mode = Mode.RIGHT
    if (mode == Mode.RIGHT)


    The last line looks a little odd but you explained why. I'd suggest adding a comment in the code.



    //
    return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());


    'nextA nextB next1 next2' should be renamed to be more meaningful






    share|improve this answer








    New contributor




    dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$














      Your Answer





      StackExchange.ifUsing("editor", function () {
      return StackExchange.using("mathjaxEditing", function () {
      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
      });
      });
      }, "mathjax-editing");

      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "196"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216701%2fjava-algorithm-to-fly-over-area%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2












      $begingroup$

      Without doing a full re-write:



      Are the methods in your helper classes static? Are they used elsewhere? Can they be made static in their home class? You may want to statically import these helper classes if they are not holding state.



      You have a lot of indirection (a.b.c()) fetching the same objects repeatedly - consider putting these in variables before you use them. this will clean up the code and might reveal another method you can extract



      Is there any reason movePoint() cannot just return a Waypoint?



      There is a lot of common code in the if and else clauses - can this be extracted as a single method that takes the single letter flag?



      You can just assign the finishing condition check to the finish variable and get rid of the if clause.



      Overall - try to aim for a top level method that 'describes the algorithm' then use subordinate methods to take care of sub-operations.






      share|improve this answer








      New contributor




      Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      $endgroup$


















        2












        $begingroup$

        Without doing a full re-write:



        Are the methods in your helper classes static? Are they used elsewhere? Can they be made static in their home class? You may want to statically import these helper classes if they are not holding state.



        You have a lot of indirection (a.b.c()) fetching the same objects repeatedly - consider putting these in variables before you use them. this will clean up the code and might reveal another method you can extract



        Is there any reason movePoint() cannot just return a Waypoint?



        There is a lot of common code in the if and else clauses - can this be extracted as a single method that takes the single letter flag?



        You can just assign the finishing condition check to the finish variable and get rid of the if clause.



        Overall - try to aim for a top level method that 'describes the algorithm' then use subordinate methods to take care of sub-operations.






        share|improve this answer








        New contributor




        Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        $endgroup$
















          2












          2








          2





          $begingroup$

          Without doing a full re-write:



          Are the methods in your helper classes static? Are they used elsewhere? Can they be made static in their home class? You may want to statically import these helper classes if they are not holding state.



          You have a lot of indirection (a.b.c()) fetching the same objects repeatedly - consider putting these in variables before you use them. this will clean up the code and might reveal another method you can extract



          Is there any reason movePoint() cannot just return a Waypoint?



          There is a lot of common code in the if and else clauses - can this be extracted as a single method that takes the single letter flag?



          You can just assign the finishing condition check to the finish variable and get rid of the if clause.



          Overall - try to aim for a top level method that 'describes the algorithm' then use subordinate methods to take care of sub-operations.






          share|improve this answer








          New contributor




          Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          $endgroup$



          Without doing a full re-write:



          Are the methods in your helper classes static? Are they used elsewhere? Can they be made static in their home class? You may want to statically import these helper classes if they are not holding state.



          You have a lot of indirection (a.b.c()) fetching the same objects repeatedly - consider putting these in variables before you use them. this will clean up the code and might reveal another method you can extract



          Is there any reason movePoint() cannot just return a Waypoint?



          There is a lot of common code in the if and else clauses - can this be extracted as a single method that takes the single letter flag?



          You can just assign the finishing condition check to the finish variable and get rid of the if clause.



          Overall - try to aim for a top level method that 'describes the algorithm' then use subordinate methods to take care of sub-operations.







          share|improve this answer








          New contributor




          Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Apr 2 at 13:34









          JamieJamie

          213




          213




          New contributor




          Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Jamie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

























              1












              $begingroup$

              Instead of using a variable 'finish', put the condition inside the loop:



              do {
              ...
              } while (travelledDown >= distanceDown)


              Your modes of "r" and "l" aren't very descriptive. You should use an ENUM here (Or atleast rename r/l if you don't want an ENUM)



              public Enum Mode
              {
              LEFT("L"),
              RIGHT("R")
              }
              mode = Mode.RIGHT
              if (mode == Mode.RIGHT)


              The last line looks a little odd but you explained why. I'd suggest adding a comment in the code.



              //
              return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());


              'nextA nextB next1 next2' should be renamed to be more meaningful






              share|improve this answer








              New contributor




              dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.






              $endgroup$


















                1












                $begingroup$

                Instead of using a variable 'finish', put the condition inside the loop:



                do {
                ...
                } while (travelledDown >= distanceDown)


                Your modes of "r" and "l" aren't very descriptive. You should use an ENUM here (Or atleast rename r/l if you don't want an ENUM)



                public Enum Mode
                {
                LEFT("L"),
                RIGHT("R")
                }
                mode = Mode.RIGHT
                if (mode == Mode.RIGHT)


                The last line looks a little odd but you explained why. I'd suggest adding a comment in the code.



                //
                return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());


                'nextA nextB next1 next2' should be renamed to be more meaningful






                share|improve this answer








                New contributor




                dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                $endgroup$
















                  1












                  1








                  1





                  $begingroup$

                  Instead of using a variable 'finish', put the condition inside the loop:



                  do {
                  ...
                  } while (travelledDown >= distanceDown)


                  Your modes of "r" and "l" aren't very descriptive. You should use an ENUM here (Or atleast rename r/l if you don't want an ENUM)



                  public Enum Mode
                  {
                  LEFT("L"),
                  RIGHT("R")
                  }
                  mode = Mode.RIGHT
                  if (mode == Mode.RIGHT)


                  The last line looks a little odd but you explained why. I'd suggest adding a comment in the code.



                  //
                  return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());


                  'nextA nextB next1 next2' should be renamed to be more meaningful






                  share|improve this answer








                  New contributor




                  dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  $endgroup$



                  Instead of using a variable 'finish', put the condition inside the loop:



                  do {
                  ...
                  } while (travelledDown >= distanceDown)


                  Your modes of "r" and "l" aren't very descriptive. You should use an ENUM here (Or atleast rename r/l if you don't want an ENUM)



                  public Enum Mode
                  {
                  LEFT("L"),
                  RIGHT("R")
                  }
                  mode = Mode.RIGHT
                  if (mode == Mode.RIGHT)


                  The last line looks a little odd but you explained why. I'd suggest adding a comment in the code.



                  //
                  return waypoints.stream().map(p -> new waypoints.Waypoint(p)).collect(Collectors.toList());


                  'nextA nextB next1 next2' should be renamed to be more meaningful







                  share|improve this answer








                  New contributor




                  dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Apr 2 at 13:30









                  dustytrashdustytrash

                  2066




                  2066




                  New contributor




                  dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  dustytrash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Code Review Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      Use MathJax to format equations. MathJax reference.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216701%2fjava-algorithm-to-fly-over-area%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

                      How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

                      Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...