Class GridPoint_2
java.lang.Object
Jcg.geometry.GridPoint_2
- All Implemented Interfaces:
Comparable<Point_>,Point_
A class for representing a 2D point on an integer grid.
- Author:
- Luca Castelli Aleardi (Ecole Polytechnique, december 2022)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInitialize an empty pointGridPoint_2(int x, int y) Initialize an integer point having coordinates (x, y)GridPoint_2(int x, int y, int index) Initialize an integer point having coordinates (x, y), and with a given indexMake a copy of a point q -
Method Summary
Modifier and TypeMethodDescriptionvoidbarycenter(Point_[] points) Set the current point as the barycenter of an array of pointsstatic booleanccw(GridPoint_2 A, GridPoint_2 B, GridPoint_2 C) intcompareCartesian(Point_ o, int i) Compare the i-th coordinate of two pointsintCompare two points (lexicographic order on coordinates)static booleancrossing(GridPoint_2 A, GridPoint_2 B, GridPoint_2 C, GridPoint_2 D) static booleancrossingRect(GridPoint_2 A, GridPoint_2 B, GridPoint_2 C, GridPoint_2 D) intReturn the dimension of the spacedoublebooleanCheck whether the current point is equal to point 'o'.getCartesian(int dim) Return the d-th coordinate of the pointintgetIndex()Return the indexintgetX()Return the x-coordinateintgetY()Return the y-coordinateinthashCode()static GridPoint_2linearCombination(GridPoint_2[] points, Number[] coefficients) Return a new point defined by the linear combination of the input points, with respect to the given input coefficientsvoidlinearCombination(Point_[] points, Number[] coefficients) Set the current point to be the linear combination of the input points, with respect to the given input coefficientsReturn the integer grid vector (p-q), where q is the current point
Warning: q is assumed to be an integer GridPoint_2voidsetCartesian(int dim, Number x) Set the d-th coordinate of the pointvoidsetIndex(int index) Set the indexvoidSet the coordinates of the current point to be (0, 0)voidSet the x-coordinatevoidSet the y-coordinateReturn the square of the Euclidean distance between the current point 'this' and a point psum(GridVector_2 v) toString()Return a string (representation of the point)voidTranslate the current point of the vector o
-
Field Details
-
index
public int indexan integer useful for indexing this point: for instance, 'index' can be the number of a vertex -
x
public int xinteger coordinates of the point on the grid -
y
public int yinteger coordinates of the point on the grid
-
-
Constructor Details
-
GridPoint_2
public GridPoint_2()Initialize an empty point -
GridPoint_2
public GridPoint_2(int x, int y) Initialize an integer point having coordinates (x, y) -
GridPoint_2
public GridPoint_2(int x, int y, int index) Initialize an integer point having coordinates (x, y), and with a given index -
GridPoint_2
Make a copy of a point q
-
-
Method Details
-
getIndex
public int getIndex()Return the index -
getX
public int getX()Return the x-coordinate -
getY
public int getY()Return the y-coordinate -
setIndex
public void setIndex(int index) Set the index -
setX
Set the x-coordinate -
setY
Set the y-coordinate -
translateOf
Translate the current point of the vector o- Specified by:
translateOfin interfacePoint_
-
equals
-
hashCode
-
distanceFrom
-
squareDistance
Return the square of the Euclidean distance between the current point 'this' and a point p- Specified by:
squareDistancein interfacePoint_
-
barycenter
Set the current point as the barycenter of an array of points- Specified by:
barycenterin interfacePoint_
-
linearCombination
Set the current point to be the linear combination of the input points, with respect to the given input coefficients- Specified by:
linearCombinationin interfacePoint_
-
linearCombination
Return a new point defined by the linear combination of the input points, with respect to the given input coefficients -
toString
-
dimension
-
getCartesian
Return the d-th coordinate of the point- Specified by:
getCartesianin interfacePoint_- Parameters:
dim- the d-th coordinate of the point:
dim=0 for x-coordinate, dim=1 for y-coordinate
-
setCartesian
Set the d-th coordinate of the point- Specified by:
setCartesianin interfacePoint_- Parameters:
dim- the d-th coordinate of the point:
dim=0 for x-coordinate, dim=1 for y-coordinate
-
setOrigin
-
minus
Return the integer grid vector (p-q), where q is the current point
Warning: q is assumed to be an integer GridPoint_2 -
ccw
- Returns:
- true if CAB is a positive angle
-
crossing
- Returns:
- true if segments AB and CD intersect
-
crossingRect
- Returns:
- true if segment AB intersects with rectangle defined by C and D
-
sum
-
compareTo
Compare two points (lexicographic order on coordinates)- Specified by:
compareToin interfaceComparable<Point_>- Parameters:
q- the point to compare to the current point (this)- Returns:
- -1 if the current point is smaller (with respect to lexicographic order) to the point q; it returns 0 is the two points have equal coordinates. It returns 1 otherwise.
-
compareCartesian
Compare the i-th coordinate of two points- Specified by:
compareCartesianin interfacePoint_- Parameters:
o- the point to comparei- the i-th coordinate to compare- Returns:
- -1 if the i-th coordinate of the current point this is smaller then i-th coordinate of point o, return 0 if both points have the same i-th coordinate, and return 1 otherwise
-