Skip to content

Commit

Permalink
Improved exception handling and documentation, removed unused files
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyoung101 committed Jul 6, 2018
1 parent 47ee270 commit 6bdf894
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 5,758 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
/build/
.idea/

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
13 changes: 13 additions & 0 deletions jwalkable.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="jwalkable" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/out" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
28 changes: 21 additions & 7 deletions src/main/java/com/dongbat/walkable/PathHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@
import java.util.List;

/**
*
* Wrapper for hxDaedalus
* @author tao
*/
public class PathHelper {

private final Mesh mesh;
private final EntityAI entity;
private final PathFinder pathFinder;
private final Array path;

/**
* Constructs a PathFinder with the given world width and world height
* @param w the world width
* @param h the world height
*/
public PathHelper(float w, float h) {
mesh = RectMesh.buildRectangle(w, h);
entity = new EntityAI();
Expand All @@ -49,8 +53,7 @@ public Obstacle addPolyline(float[] vertices) {

public Obstacle addPolyline(float[] vertices, float x, float y) {
if (vertices.length < 4) {
System.out.println("Polylines must contain at least 2 points.");
return null;
throw new IllegalArgumentException("Polylines must contain at least 2 points.");
}
Obstacle object = new Obstacle();
Array array = new Array();
Expand Down Expand Up @@ -82,8 +85,7 @@ public Obstacle addPolygon(float[] vertices) {

public Obstacle addPolygon(float[] vertices, float x, float y) {
if (vertices.length < 6) {
System.out.println("Polygons must contain at least 3 points.");
return null;
throw new IllegalArgumentException("Polygons must contain at least 3 points.");
}
Obstacle object = new Obstacle();
Array array = new Array();
Expand Down Expand Up @@ -155,10 +157,13 @@ private void doFindPath(float fromX, float fromY, float toX, float toY, float ra
pathFinder.findPath(toX, toY, path);
} catch (Exception e) {
path.splice(0, path.length);
System.out.println(e.getMessage());
throw new PathfinderException(e);
}
}

/**
* @throws PathfinderException occasionally, if there's an internal problem in hxDaedalus
*/
public float[] findPath(float fromX, float fromY, float toX, float toY, float radius) {
doFindPath(fromX, fromY, toX, toY, radius);

Expand All @@ -170,6 +175,9 @@ public float[] findPath(float fromX, float fromY, float toX, float toY, float ra
return result;
}

/**
* @throws PathfinderException occasionally, if there's an internal problem in hxDaedalus
*/
public int findPath(float fromX, float fromY, float toX, float toY, float radius, float[] result) {
doFindPath(fromX, fromY, toX, toY, radius);

Expand All @@ -179,6 +187,9 @@ public int findPath(float fromX, float fromY, float toX, float toY, float radius
return path.length;
}

/**
* @throws PathfinderException occasionally, if there's an internal problem in hxDaedalus
*/
public void findPath(float fromX, float fromY, float toX, float toY, float radius, List<Float> result) {
doFindPath(fromX, fromY, toX, toY, radius);

Expand All @@ -188,6 +199,9 @@ public void findPath(float fromX, float fromY, float toX, float toY, float radiu
}
}

/**
* @throws PathfinderException occasionally, if there's an internal problem in hxDaedalus
*/
public void findPath(float fromX, float fromY, float toX, float toY, float radius, FloatArray result) {
doFindPath(fromX, fromY, toX, toY, radius);

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/dongbat/walkable/PathfinderException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017 Dong Bat Co.,Ltd..
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dongbat.walkable;

class PathfinderException extends RuntimeException {
PathfinderException(String s){
super(s);
}

PathfinderException(Exception e){
super(e);
}
}
33 changes: 0 additions & 33 deletions src/main/java/hxDaedalus/Main.java

This file was deleted.

Loading

0 comments on commit 6bdf894

Please sign in to comment.