diff --git a/.idea/misc.xml b/.idea/misc.xml index ecfa09c0da8e44958b2dddfe063bbfd6fab43ae6..b173c63a0bb2501ec3fc057688744baa05083fdc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="UTF-8"?> <project version="4"> <component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="MavenProjectsManager"> diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/src/main/java/edu/ntnu/stud/model/Vector2D.java b/src/main/java/edu/ntnu/stud/model/Vector2D.java new file mode 100644 index 0000000000000000000000000000000000000000..89148ac454dbf8a302a529e110a49b6f84b7ac2f --- /dev/null +++ b/src/main/java/edu/ntnu/stud/model/Vector2D.java @@ -0,0 +1,67 @@ +package edu.ntnu.stud.model; + +/** + * Class representing a 2D vector. + */ +public class Vector2D { + + /** + * The x0 component of the vector. + */ + private double x0; + + /** + * The x1 component of the vector. + */ + private double x1; + + /** + * Create a new 2D vector. + * + * @param x0 The x0 component of the vector. + * @param x1 The x1 component of the vector. + */ + public Vector2D(double x0, double x1) { + this.x0 = x0; + this.x1 = x1; + } + + /** + * Get the x0 component of the vector. + * + * @return The x0 component of the vector. + */ + public double getX0() { + return x0; + } + + /** + * Get the x1 component of the vector. + * + * @return The x1 component of the vector. + */ + public double getX1() { + return x1; + } + + /** + * Add another vector to this vector. + * + * @param other The other vector to add. + * @return A new vector that is the sum of this vector and the other vector. + */ + public Vector2D add(Vector2D other) { + return new Vector2D(x0 + other.x0, x1 + other.x1); + } + + /** + * Subtract another vector from this vector. + * + * @param other The other vector to subtract. + * @return A new vector that is the difference between this vector and the other vector. + */ + public Vector2D subtract(Vector2D other) { + return new Vector2D(x0 - other.x0, x1 - other.x1); + } + +}