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.void
addListener
(javafx.beans.InvalidationListener listener) void
addListener
(javafx.beans.value.ChangeListener<? super ViewModelPoint> listener) double
angle
(ViewModelPoint other) Calculate the angle between two points (as vectors)void
bind
(javafx.beans.value.ObservableValue<? extends ViewModelPoint> observable) void
bindBidirectional
(javafx.beans.property.Property<ViewModelPoint> other) copy()
Get a copy of the point.double
distance()
Get the magnitude of the point.double
dot
(ViewModelPoint other) Calculate the dot product between this and another point (as if they are vectors).boolean
getBean()
getName()
getValue()
double
getX()
Get the x-coordinate value of the view model pointjavafx.beans.property.DoubleProperty
Get the x-coordinate property of the view model point.double
getY()
Get the y-coordinate value of the view model pointjavafx.beans.property.DoubleProperty
Get the y-coordinate property of the view model point.int
hashCode()
boolean
isBound()
multiply
(ViewModelPoint other) Vector-multiplication function for two points.Get a normalized vector of this point.void
removeListener
(javafx.beans.InvalidationListener listener) void
removeListener
(javafx.beans.value.ChangeListener<? super ViewModelPoint> listener) scale
(float scalar) Vector-multiplication function for view model points.void
setValue
(ViewModelPoint value) void
snapToGrid
(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 valuesvoid
unbind()
void
unbindBidirectional
(javafx.beans.property.Property<ViewModelPoint> other) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods 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:
getBean
in interfacejavafx.beans.property.ReadOnlyProperty<ViewModelPoint>
-
getName
- Specified by:
getName
in interfacejavafx.beans.property.ReadOnlyProperty<ViewModelPoint>
-
addListener
- Specified by:
addListener
in interfacejavafx.beans.value.ObservableValue<ViewModelPoint>
-
removeListener
- Specified by:
removeListener
in interfacejavafx.beans.value.ObservableValue<ViewModelPoint>
-
getValue
- Specified by:
getValue
in interfacejavafx.beans.value.ObservableValue<ViewModelPoint>
- Specified by:
getValue
in interfacejavafx.beans.value.WritableValue<ViewModelPoint>
-
addListener
public void addListener(javafx.beans.InvalidationListener listener) - Specified by:
addListener
in interfacejavafx.beans.Observable
-
removeListener
public void removeListener(javafx.beans.InvalidationListener listener) - Specified by:
removeListener
in interfacejavafx.beans.Observable
-
setValue
- Specified by:
setValue
in interfacejavafx.beans.value.WritableValue<ViewModelPoint>
-
bind
- Specified by:
bind
in interfacejavafx.beans.property.Property<ViewModelPoint>
-
unbind
public void unbind()- Specified by:
unbind
in interfacejavafx.beans.property.Property<ViewModelPoint>
-
isBound
public boolean isBound()- Specified by:
isBound
in interfacejavafx.beans.property.Property<ViewModelPoint>
-
bindBidirectional
- Specified by:
bindBidirectional
in interfacejavafx.beans.property.Property<ViewModelPoint>
-
unbindBidirectional
- Specified by:
unbindBidirectional
in interfacejavafx.beans.property.Property<ViewModelPoint>
-
equals
-
hashCode
public int hashCode()
-