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 Summary
Constructors Constructor Description IntVector(int x, int y)
-
Method Summary
Modifier and Type Method Description DoubleVector
asDoubleVector()
Returns aDoubleVector
object that represents the same vector represented by thisIntVector
object.long
crossProduct(IntVector other)
Returns the cross product of this vector and the given vector.long
dotProduct(IntVector other)
Returns the dot product of this vector and the given vector.boolean
equals(IntVector other)
int
getX()
int
getY()
boolean
isCollinearWith(IntVector other)
Returns whether this vector is collinear with the given vector.IntVector
scale(double xFactor, double yFactor)
Returns the vector obtained by multiplying this vector's X coordinate by factorxFactor
and its Y coordinate by factoryFactor
.
-
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
- Preconditions:
other != null
- Postconditions:
result == (getX() == other.getX() && getY() == other.getY())
-
crossProduct
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
Returns the vector obtained by multiplying this vector's X coordinate by factorxFactor
and its Y coordinate by factoryFactor
. -
isCollinearWith
Returns whether this vector is collinear with the given vector.- Preconditions:
other != null
- Postconditions:
result == (this.crossProduct(other) == 0)
-
dotProduct
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
Returns aDoubleVector
object that represents the same vector represented by thisIntVector
object.- Postconditions:
result != null
-