Package dk.gtz.graphedit.viewmodel
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 Summary
ConstructorsConstructorDescriptionViewModelPoint(double x, double y) Constructs a new view model point with the provided x and y coordinatesViewModelPoint(ModelPoint point) Constructs a new view model point based on the provided model pointViewModelPoint(javafx.beans.binding.DoubleBinding x, javafx.beans.binding.DoubleBinding y) Constructs a new view model point with the provided x and y coordinate property bindingsViewModelPoint(javafx.beans.property.DoubleProperty x, javafx.beans.property.DoubleProperty y) Constructs a new view model point with the provided x and y coordinate properties -
Method Summary
Modifier and TypeMethodDescriptionadd(ViewModelPoint other) Vector-addition function for view model points.voidaddListener(javafx.beans.InvalidationListener listener) voidaddListener(javafx.beans.value.ChangeListener<? super ViewModelPoint> listener) doubleangle(ViewModelPoint other) Calculate the angle between two points (as vectors)voidbind(javafx.beans.value.ObservableValue<? extends ViewModelPoint> observable) voidbindBidirectional(javafx.beans.property.Property<ViewModelPoint> other) copy()Get a copy of the point.doubledistance()Get the magnitude of the point.doubledot(ViewModelPoint other) Calculate the dot product between this and another point (as if they are vectors).booleangetBean()getName()getValue()doublegetX()Get the x-coordinate value of the view model pointjavafx.beans.property.DoublePropertyGet the x-coordinate property of the view model point.doublegetY()Get the y-coordinate value of the view model pointjavafx.beans.property.DoublePropertyGet the y-coordinate property of the view model point.inthashCode()booleanisBound()multiply(ViewModelPoint other) Vector-multiplication function for two points.Get a normalized vector of this point.voidremoveListener(javafx.beans.InvalidationListener listener) voidremoveListener(javafx.beans.value.ChangeListener<? super ViewModelPoint> listener) scale(float scalar) Vector-multiplication function for view model points.voidsetValue(ViewModelPoint value) voidsnapToGrid(ViewModelEditorSettings settings) Snap the position to the provided grid settingssubtract(ViewModelPoint other) Vector-subtraction function for view model points.toModel()Constructs a new model point instance based on the current view model valuesvoidunbind()voidunbindBidirectional(javafx.beans.property.Property<ViewModelPoint> other) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javafx.beans.value.ObservableValue
flatMap, map, orElse, when
-
Constructor Details
-
ViewModelPoint
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 valuey- 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 propertyy- 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 bindingy- 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
Constructs a new model point instance based on the current view model values- Returns:
- a new model point instance
-
snapToGrid
Snap the position to the provided grid settings- Parameters:
settings- the view settings containing grid settings to snap to
-
subtract
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
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
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
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
Get a copy of the point.- Returns:
- A new viewmodel point.
-
multiply
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
Calculate the angle between two points (as vectors)- Parameters:
other- The other point to compare with.- Returns:
- The angle in degrees.
-
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
- Specified by:
getBeanin interfacejavafx.beans.property.ReadOnlyProperty<ViewModelPoint>
-
getName
- Specified by:
getNamein interfacejavafx.beans.property.ReadOnlyProperty<ViewModelPoint>
-
addListener
- Specified by:
addListenerin interfacejavafx.beans.value.ObservableValue<ViewModelPoint>
-
removeListener
- Specified by:
removeListenerin interfacejavafx.beans.value.ObservableValue<ViewModelPoint>
-
getValue
- Specified by:
getValuein interfacejavafx.beans.value.ObservableValue<ViewModelPoint>- Specified by:
getValuein interfacejavafx.beans.value.WritableValue<ViewModelPoint>
-
addListener
public void addListener(javafx.beans.InvalidationListener listener) - Specified by:
addListenerin interfacejavafx.beans.Observable
-
removeListener
public void removeListener(javafx.beans.InvalidationListener listener) - Specified by:
removeListenerin interfacejavafx.beans.Observable
-
setValue
- Specified by:
setValuein interfacejavafx.beans.value.WritableValue<ViewModelPoint>
-
bind
- Specified by:
bindin interfacejavafx.beans.property.Property<ViewModelPoint>
-
unbind
public void unbind()- Specified by:
unbindin interfacejavafx.beans.property.Property<ViewModelPoint>
-
isBound
public boolean isBound()- Specified by:
isBoundin interfacejavafx.beans.property.Property<ViewModelPoint>
-
bindBidirectional
- Specified by:
bindBidirectionalin interfacejavafx.beans.property.Property<ViewModelPoint>
-
unbindBidirectional
- Specified by:
unbindBidirectionalin interfacejavafx.beans.property.Property<ViewModelPoint>
-
equals
-
hashCode
public int hashCode()
-