# Class Coordinate

java.lang.Object
jspecview.common.Coordinate

Direct Known Subclasses:
  `Annotation`

public class Coordinate extends Object
The `Coordinate` class stores the x and y values of a coordinate.

Author:
  Debbie-Ann Facey, Khari A. Bryan, Prof Robert J. Lancashire

## Constructor Summary

Constructors
Constructor
Description
`Coordinate()`
Constructor

## Method Summary

Modifier and Type
Method
Description
`static void`
`applyScale(Coordinate[] xyCoords, double xScale, double yScale)`
Apply the scale factor to the coordinates
`Coordinate`
`copy()`
Returns a new coordinate that has the same x and y values of this coordinate
`static double`
`deltaX(double last, double first, int numPoints)`
Returns the Delta X value
`boolean`
`equals(Coordinate coord)`
Indicates whether some other Coordinate is equal to this one
`static double`
`findXForPeakNearest(Coordinate[] xyCoords, double x, boolean isMin)`
`static double`
`getMaxX(Lst<Spectrum> spectra, ViewData vd)`
Returns the maximum x value value from an array of arrays of `Coordinate`s.
`static double`
`getMaxX(Coordinate[] coords, int start, int end)`
Returns the minimum x value of an array of `Coordinate`s
`static double`
`getMaxY(Coordinate[] coords, int start, int end)`
Returns the maximum y value of an array of `Coordinate`s
`static double`
`getMaxYUser(Lst<Spectrum> spectra, ViewData vd)`
Returns the maximum y value value from an array of arrays of `Coordinate`s.
`static double`
`getMinX(Lst<Spectrum> spectra, ViewData vd)`
Returns the minimum x value value from an array of arrays of `Coordinate`s.
`static double`
`getMinX(Coordinate[] coords, int start, int end)`
Returns the minimum x value of an array of `Coordinate`s
`static double`
`getMinY(Coordinate[] coords, int start, int end)`
Returns the minimum y value of an array of `Coordinate`s
`static double`
`getMinYUser(Lst<Spectrum> spectra, ViewData vd)`
Returns the minimum y value value from an array of arrays of `Coordinate`s.
`static int`
`getNearestIndexForX(Coordinate[] xyCoords, double xPt)`
`static double`
`getNearestXWithYAbove(Coordinate[] xyCoords, double x, double y, boolean inverted, boolean andGreaterThanX)`
discovers nearest peak left or right of x that is above threshold y
`double`
`getXVal()`
Returns the x value of the coordinate
`double`
`getYVal()`
Returns the y value of the coordinate
`static double`
`getYValueAt(Coordinate[] xyCoords, double xPt)`
`static boolean`
`isYInRange(Coordinate[] xyCoords, double min, double max)`
Determines if the y values of a spectrum are in a certain range
`static Coordinate[]`
`normalise(Coordinate[] xyCoords, double min, double max)`
Normalises the y values of a spectrum to a certain range
`static double`
`parabolicInterpolation(Coordinate[] xyCoords, int pt)`
see https://ccrma.stanford.edu/~jos/sasp/Quadratic_Interpolation_Spectral_Peaks.html
`static Coordinate[]`
`parseDSV(String dataPoints, double xFactor, double yFactor)`
Parses data stored in x, y format
`static void`
`removeScale(Coordinate[] xyCoords, double xScale, double yScale)`
Removes the scale factor from the coordinates
`static Coordinate[]`
`reverse(Coordinate[] x)`
`Coordinate`
`set(double x, double y)`
Constructor
`void`
`setXVal(double val)`
Sets the x value of the coordinate
`void`
`setYVal(double val)`
Sets the y value of the coordinate
`static void`
`shiftX(Coordinate[] xyCoords, double dx)`
`String`
`toString()`
Overides Objects toString() method

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### Coordinate

public Coordinate()
Constructor

## Method Details

### set

public Coordinate set(double x, double y)
Constructor

Parameters:
  `x` - the x value
  `y` - the y value
Returns:
  this

### getXVal

public double getXVal()
Returns the x value of the coordinate

Returns:
  the x value of the coordinate

### getYVal

public double getYVal()
Returns the y value of the coordinate

Returns:
  the y value of the coordinate

### setXVal

public void setXVal(double val)
Sets the x value of the coordinate

Parameters:
  `val` - the x value

### setYVal

public void setYVal(double val)
Sets the y value of the coordinate

Parameters:
  `val` - the y value

### copy

public Coordinate copy()
Returns a new coordinate that has the same x and y values of this coordinate

Returns:
  Returns a new coordinate that has the same x and y values of this coordinate

### equals

public boolean equals(Coordinate coord)
Indicates whether some other Coordinate is equal to this one

Parameters:
  `coord` - the reference coordinate
Returns:
  true if the coordinates are equal, false otherwise

### toString

public String toString()
Overides Objects toString() method

Overrides:
  `toString` in class `Object`
Returns:
  the String representation of this coordinate

### isYInRange

public static boolean isYInRange(Coordinate[] xyCoords, double min, double max)
Determines if the y values of a spectrum are in a certain range

Parameters:
  `xyCoords` -
  `min` -
  `max` -
Returns:
  true is in range, otherwise false

### normalise

public static Coordinate[] normalise(Coordinate[] xyCoords, double min, double max)
Normalises the y values of a spectrum to a certain range

Parameters:
  `xyCoords` -
  `min` -
  `max` -
Returns:
  array of normalised coordinates

### reverse

public static Coordinate[] reverse(Coordinate[] x)

### parseDSV

public static Coordinate[] parseDSV(String dataPoints, double xFactor, double yFactor)
Parses data stored in x, y format

Parameters:
  `dataPoints` - the data as string
  `xFactor` - the factor to apply to x values
  `yFactor` - the factor to apply to y values
Returns:
  an array of `Coordinate`s

### deltaX

public static double deltaX(double last, double first, int numPoints)
Returns the Delta X value

Parameters:
  `last` - the last x value
  `first` - the first x value
  `numPoints` - the number of data points
Returns:
  the Delta X value

### removeScale

public static void removeScale(Coordinate[] xyCoords, double xScale, double yScale)
Removes the scale factor from the coordinates

Parameters:
  `xyCoords` - the array of coordinates
  `xScale` - the scale for the x values
  `yScale` - the scale for the y values

### applyScale

public static void applyScale(Coordinate[] xyCoords, double xScale, double yScale)
Apply the scale factor to the coordinates

Parameters:
  `xyCoords` - the array of coordinates
  `xScale` - the scale for the x values
  `yScale` - the scale for the y values

### getMinX

public static double getMinX(Coordinate[] coords, int start, int end)
Returns the minimum x value of an array of `Coordinate`s

Parameters:
  `coords` - the coordinates
  `start` - the starting index
  `end` - the ending index
Returns:
  the maximum x value of an array of `Coordinate`s

### getMinX

public static double getMinX(Lst<Spectrum> spectra, ViewData vd)
Returns the minimum x value value from an array of arrays of `Coordinate`s.

Parameters:
  `spectra` -
  `vd` -
Returns:
  the minimum x value value from an array of arrays of `Coordinate`s

### getMaxX

public static double getMaxX(Coordinate[] coords, int start, int end)
Returns the minimum x value of an array of `Coordinate`s

Parameters:
  `coords` - the coordinates
  `start` - the starting index
  `end` - the ending index
Returns:
  the minimum x value of an array of `Coordinate`s

### getMaxX

public static double getMaxX(Lst<Spectrum> spectra, ViewData vd)
Returns the maximum x value value from an array of arrays of `Coordinate`s.

Parameters:
  `spectra` -
  `vd` -
Returns:
  the maximum x value value from an array of arrays of `Coordinate`s

### getMinY

public static double getMinY(Coordinate[] coords, int start, int end)
Returns the minimum y value of an array of `Coordinate`s

Parameters:
  `coords` - the coordinates
  `start` - the starting index
  `end` - the ending index
Returns:
  the minimum y value of an array of `Coordinate`s

### getMinYUser

public static double getMinYUser(Lst<Spectrum> spectra, ViewData vd)
Returns the minimum y value value from an array of arrays of `Coordinate`s.

Parameters:
  `spectra` -
  `vd` -
Returns:
  the minimum y value value from an array of arrays of `Coordinate`s

### getMaxY

public static double getMaxY(Coordinate[] coords, int start, int end)
Returns the maximum y value of an array of `Coordinate`s

Parameters:
  `coords` - the coordinates
  `start` - the starting index
  `end` - the ending index
Returns:
  the maximum y value of an array of `Coordinate`s

### getMaxYUser

public static double getMaxYUser(Lst<Spectrum> spectra, ViewData vd)
Returns the maximum y value value from an array of arrays of `Coordinate`s.

Parameters:
  `spectra` -
  `vd` -
Returns:
  the maximum y value value from an array of arrays of `Coordinate`s

### getYValueAt

public static double getYValueAt(Coordinate[] xyCoords, double xPt)

### getNearestIndexForX

public static int getNearestIndexForX(Coordinate[] xyCoords, double xPt)

### findXForPeakNearest

public static double findXForPeakNearest(Coordinate[] xyCoords, double x, boolean isMin)

### parabolicInterpolation

public static double parabolicInterpolation(Coordinate[] xyCoords, int pt)
see https://ccrma.stanford.edu/~jos/sasp/Quadratic_Interpolation_Spectral_Peaks.html

Parameters:
  `xyCoords` -
  `pt` -
Returns:
  center

### shiftX

public static void shiftX(Coordinate[] xyCoords, double dx)

### getNearestXWithYAbove

public static double getNearestXWithYAbove(Coordinate[] xyCoords, double x, double y, boolean inverted, boolean andGreaterThanX)
discovers nearest peak left or right of x that is above threshold y

Parameters:
  `xyCoords` -
  `x` -
  `y` -
  `inverted` -
  `andGreaterThanX` -
Returns:
  interpolated x value or NaN