Class 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
    • 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 distance
      private 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BezierPathConverter

        public BezierPathConverter()
    • 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 interface IPathConverter
        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 interface IPathConverter
        Parameters:
        vessel - that is traveling
        interpolator - used to hold the path information
        fraction - 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 curve
        scale - 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 interface IPathConverter
        Parameters:
        initialPoints - initial point of the line
        Returns:
        list of points making up the path