Class ViewModelPoint

java.lang.Object
dk.gtz.graphedit.viewmodel.ViewModelPoint
All Implemented Interfaces:
javafx.beans.Observable, javafx.beans.property.Property<ViewModelPoint>, javafx.beans.property.ReadOnlyProperty<ViewModelPoint>, javafx.beans.value.ObservableValue<ViewModelPoint>, javafx.beans.value.WritableValue<ViewModelPoint>

public class ViewModelPoint extends Object implements javafx.beans.property.Property<ViewModelPoint>
View model representation of a 2D point. Also contains vector-math functions, so it can also be used as a vector.
  • Constructor Details

    • ViewModelPoint

      public ViewModelPoint(ModelPoint point)
      Constructs a new view model point based on the provided model point
      Parameters:
      point - the model point to base on
    • ViewModelPoint

      public ViewModelPoint(double x, double y)
      Constructs a new view model point with the provided x and y coordinates
      Parameters:
      x - the x-coordinate value
      y - the y-coordinate value
    • ViewModelPoint

      public ViewModelPoint(javafx.beans.property.DoubleProperty x, javafx.beans.property.DoubleProperty y)
      Constructs a new view model point with the provided x and y coordinate properties
      Parameters:
      x - the x-coordinate property
      y - the y-coordinate property
    • ViewModelPoint

      public ViewModelPoint(javafx.beans.binding.DoubleBinding x, javafx.beans.binding.DoubleBinding y)
      Constructs a new view model point with the provided x and y coordinate property bindings
      Parameters:
      x - the x-coordinate property binding
      y - the y-coordinate property binding
  • Method Details

    • getX

      public double getX()
      Get the x-coordinate value of the view model point
      Returns:
      the underlying x-coordinate value
    • getY

      public double getY()
      Get the y-coordinate value of the view model point
      Returns:
      the underlying y-coordinate value
    • getXProperty

      public javafx.beans.property.DoubleProperty getXProperty()
      Get the x-coordinate property of the view model point. Useful for attaching eventlisteners
      Returns:
      the x-coordinate property
    • getYProperty

      public javafx.beans.property.DoubleProperty getYProperty()
      Get the y-coordinate property of the view model point. Useful for attaching eventlisteners
      Returns:
      the y-coordinate property
    • toModel

      public ModelPoint toModel()
      Constructs a new model point instance based on the current view model values
      Returns:
      a new model point instance
    • snapToGrid

      public void snapToGrid(ViewModelEditorSettings settings)
      Snap the position to the provided grid settings
      Parameters:
      settings - the view settings containing grid settings to snap to
    • subtract

      public ViewModelPoint subtract(ViewModelPoint other)
      Vector-subtraction function for view model points. Note: This does not modify the current values.
      Parameters:
      other - the values to subtract
      Returns:
      a new instance with the new subtracted coordinate values
    • add

      public ViewModelPoint add(ViewModelPoint other)
      Vector-addition function for view model points. Note: This does not modify the current values.
      Parameters:
      other - the values to add
      Returns:
      a new instance with the new added coordinate values
    • scale

      public ViewModelPoint scale(float scalar)
      Vector-multiplication function for view model points. Note: This does not modify the current values.
      Parameters:
      scalar - the value to scale the values with.
      Returns:
      a new instance with the new coordinate values.
    • dot

      public double dot(ViewModelPoint other)
      Calculate the dot product between this and another point (as if they are vectors).
      Parameters:
      other - The other point to dot.
      Returns:
      The dot product of this and the other point as a vector.
    • copy

      public ViewModelPoint copy()
      Get a copy of the point.
      Returns:
      A new viewmodel point.
    • multiply

      public ViewModelPoint multiply(ViewModelPoint other)
      Vector-multiplication function for two points. (x1 * x2, y1 * y2)
      Parameters:
      other - The other point to multiply with.
      Returns:
      A new instance with the new coordinate values.
    • angle

      public double angle(ViewModelPoint other)
      Calculate the angle between two points (as vectors)
      Parameters:
      other - The other point to compare with.
      Returns:
      The angle in degrees.
    • normalized

      public ViewModelPoint normalized()
      Get a normalized vector of this point.
      Returns:
      A new point with a magnitude of 1, but the same direction.
    • distance

      public double distance()
      Get the magnitude of the point.
      Returns:
      The distance from (0,0) to this point.
    • getBean

      public Object getBean()
      Specified by:
      getBean in interface javafx.beans.property.ReadOnlyProperty<ViewModelPoint>
    • getName

      public String getName()
      Specified by:
      getName in interface javafx.beans.property.ReadOnlyProperty<ViewModelPoint>
    • addListener

      public void addListener(javafx.beans.value.ChangeListener<? super ViewModelPoint> listener)
      Specified by:
      addListener in interface javafx.beans.value.ObservableValue<ViewModelPoint>
    • removeListener

      public void removeListener(javafx.beans.value.ChangeListener<? super ViewModelPoint> listener)
      Specified by:
      removeListener in interface javafx.beans.value.ObservableValue<ViewModelPoint>
    • getValue

      public ViewModelPoint getValue()
      Specified by:
      getValue in interface javafx.beans.value.ObservableValue<ViewModelPoint>
      Specified by:
      getValue in interface javafx.beans.value.WritableValue<ViewModelPoint>
    • addListener

      public void addListener(javafx.beans.InvalidationListener listener)
      Specified by:
      addListener in interface javafx.beans.Observable
    • removeListener

      public void removeListener(javafx.beans.InvalidationListener listener)
      Specified by:
      removeListener in interface javafx.beans.Observable
    • setValue

      public void setValue(ViewModelPoint value)
      Specified by:
      setValue in interface javafx.beans.value.WritableValue<ViewModelPoint>
    • bind

      public void bind(javafx.beans.value.ObservableValue<? extends ViewModelPoint> observable)
      Specified by:
      bind in interface javafx.beans.property.Property<ViewModelPoint>
    • unbind

      public void unbind()
      Specified by:
      unbind in interface javafx.beans.property.Property<ViewModelPoint>
    • isBound

      public boolean isBound()
      Specified by:
      isBound in interface javafx.beans.property.Property<ViewModelPoint>
    • bindBidirectional

      public void bindBidirectional(javafx.beans.property.Property<ViewModelPoint> other)
      Specified by:
      bindBidirectional in interface javafx.beans.property.Property<ViewModelPoint>
    • unbindBidirectional

      public void unbindBidirectional(javafx.beans.property.Property<ViewModelPoint> other)
      Specified by:
      unbindBidirectional in interface javafx.beans.property.Property<ViewModelPoint>
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object