Package drawit

Class IntVector

java.lang.Object
drawit.IntVector

public class IntVector
extends Object
An instance of this class represents a displacement in the two-dimensional plane.
Immutable
Any two calls of any zero-argument getter of this class on the same target object return equal values. (A getter is a method whose name starts with "get" or "is" followed by a capital letter.)
  • Constructor Details

    • IntVector

      public IntVector​(int x, int y)
      Mutates:
      this
      Postconditions:
      getX() == x
      getY() == y
  • Method Details

    • getX

      public int getX()
    • getY

      public int getY()
    • equals

      public boolean equals​(IntVector other)
      Preconditions:
      other != null
      Postconditions:
      result == (getX() == other.getX() && getY() == other.getY())
    • crossProduct

      public long crossProduct​(IntVector other)
      Returns the cross product of this vector and the given vector.
      Preconditions:
      other != null
      Postconditions:
      result == (long)getX() * other.getY() - (long)getY() * other.getX()
    • scale

      public IntVector scale​(double xFactor, double yFactor)
      Returns the vector obtained by multiplying this vector's X coordinate by factor xFactor and its Y coordinate by factor yFactor.
    • isCollinearWith

      public boolean isCollinearWith​(IntVector other)
      Returns whether this vector is collinear with the given vector.
      Preconditions:
      other != null
      Postconditions:
      result == (this.crossProduct(other) == 0)
    • dotProduct

      public long dotProduct​(IntVector other)
      Returns the dot product of this vector and the given vector.
      Preconditions:
      other != null
      Postconditions:
      result == (long)getX() * other.getX() + (long)getY() * other.getY()
    • asDoubleVector

      public DoubleVector asDoubleVector()
      Returns a DoubleVector object that represents the same vector represented by this IntVector object.
      Postconditions:
      result != null