Class BezierPathConverter
- java.lang.Object
-
- ch.sahits.game.openpatrician.display.service.BezierPathConverter
-
- All Implemented Interfaces:
IPathConverter
public class BezierPathConverter extends java.lang.Object implements IPathConverter
Create a Bezier path based on a set of points. The implementation is based on work described in http://devmag.org.za/2011/06/23/bzier-path-algorithms/- Author:
- Andi Hotz, (c) Sahits GmbH, 2016 Created on Jan 05, 2016
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
BezierPathConverter.Distances
-
Field Summary
Fields Modifier and Type Field Description private Date
date
private PathInterpolatorMap
interpolators
private IMapImageServiceFacade
mapImageService
private MapService
mapService
private TravellingVessels
vessels
-
Constructor Summary
Constructors Constructor Description BezierPathConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<javafx.geometry.Point2D>
applyScale(java.util.List<javafx.geometry.Point2D> pointedPath, double scale)
long
calculateDuration(INavigableVessel vessel, PathInterpolator interpolator, double fraction)
Calculate the duration of the travel in milliseconds in real time for the specified fraction of the total distanceprivate BezierPath
convertToPathModel(java.util.List<javafx.geometry.Point2D> points)
java.util.Optional<javafx.scene.shape.Path>
createPath(INavigableVessel vessel, java.util.List<javafx.geometry.Point2D> pointedPath, double scale)
Create a path shape out of a list of points.(package private) java.util.List<javafx.geometry.Point2D>
interpolate(java.util.List<javafx.geometry.Point2D> segmentPoints, float scale)
Calculate the controlpoints for a given list of points on the curve.java.util.List<javafx.geometry.Point2D>
reduceLinePoints(java.util.List<javafx.geometry.Point2D> initialPoints)
Reduce the number of points that are needed to describe the path.
-
-
-
Field Detail
-
mapImageService
@Autowired private IMapImageServiceFacade mapImageService
-
vessels
@Autowired private TravellingVessels vessels
-
interpolators
@Autowired private PathInterpolatorMap interpolators
-
date
@Autowired private Date date
-
mapService
@Autowired private MapService mapService
-
-
Method Detail
-
createPath
public java.util.Optional<javafx.scene.shape.Path> createPath(INavigableVessel vessel, java.util.List<javafx.geometry.Point2D> pointedPath, double scale)
Description copied from interface:IPathConverter
Create a path shape out of a list of points. When the path is created the vessel will be added to the TravellingVessels container.- Specified by:
createPath
in interfaceIPathConverter
- Parameters:
vessel
- vessel that is traveling the path.pointedPath
- input points.scale
- scaling that is used on the path due to the sacle of the map.- Returns:
- shape representing a path if the vessels owner is a human player. Otherwise the path is not needed.
-
calculateDuration
public long calculateDuration(INavigableVessel vessel, PathInterpolator interpolator, double fraction)
Description copied from interface:IPathConverter
Calculate the duration of the travel in milliseconds in real time for the specified fraction of the total distance- Specified by:
calculateDuration
in interfaceIPathConverter
- Parameters:
vessel
- that is travelinginterpolator
- used to hold the path informationfraction
- value between [0,1]. 1 means that the whole distance is traveled.- Returns:
- real time duration of the travel in milliseconds.
-
applyScale
private java.util.List<javafx.geometry.Point2D> applyScale(java.util.List<javafx.geometry.Point2D> pointedPath, double scale)
-
interpolate
java.util.List<javafx.geometry.Point2D> interpolate(java.util.List<javafx.geometry.Point2D> segmentPoints, float scale)
Calculate the controlpoints for a given list of points on the curve.- Parameters:
segmentPoints
- List of points that make up the curvescale
- to be used for the length of the handles- Returns:
- List of controlpoints including the points on the line.
-
convertToPathModel
private BezierPath convertToPathModel(java.util.List<javafx.geometry.Point2D> points)
-
reduceLinePoints
public java.util.List<javafx.geometry.Point2D> reduceLinePoints(java.util.List<javafx.geometry.Point2D> initialPoints)
Reduce the number of points that are needed to describe the path. Points that do not change the direction of the path can be eliminated if:- The distance to the last point left is larger than the distance to the shore
- Specified by:
reduceLinePoints
in interfaceIPathConverter
- Parameters:
initialPoints
- initial point of the line- Returns:
- list of points making up the path
-
-