Skip to content

Commit

Permalink
(#10) add creation of Polygon2D from path2d
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasstarsz committed May 9, 2022
1 parent 962d951 commit c5fb785
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/tech/fastj/graphics/game/Polygon2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tech.fastj.graphics.Drawable;
import tech.fastj.graphics.util.DrawUtil;

import tech.fastj.systems.collections.Pair;
import tech.fastj.systems.control.Scene;
import tech.fastj.systems.control.SimpleManager;

Expand Down Expand Up @@ -141,6 +142,17 @@ public static Polygon2D fromPoints(Pointf[] points, Point[] altIndexes) {
return new Polygon2DBuilder(points, altIndexes, Drawable.DefaultShouldRender).build();
}

/**
* Creates a {@code Polygon2D} from the specified {@link Path2D.Float}.
*
* @param path {@code Path2D.Float} that defines the points from which to create a {@code Polygon2D}.
* @return The resulting {@code Polygon2D}.
*/
public static Polygon2D fromPath(Path2D.Float path) {
Pair<Pointf[], Point[]> pathMesh = DrawUtil.pointsOfPathWithAlt(path);
return new Polygon2DBuilder(pathMesh.getLeft(), pathMesh.getRight(), Drawable.DefaultShouldRender).build();
}

/**
* Gets the polygon's original point set.
*
Expand Down

0 comments on commit c5fb785

Please sign in to comment.