Class GridCoordinate

java.lang.Object
cnuphys.magfield.GridCoordinate

public class GridCoordinate extends Object
This class holds the grid parameters for one direction. The constructor is provided the min, max and number of points (inclusive, i.e., including the end points) and the step is computed.
Version:
1.0
Author:
David Heddle, Nicole Schumacher
  • Constructor Summary

    Constructors
    Constructor
    Description
    GridCoordinate(String name, double min, double max, int numPoints)
    Construct a grid coordinate.
    GridCoordinate(String name, float min, float max, int numPoints)
    Construct a grid coordinate.
  • Method Summary

    Modifier and Type
    Method
    Description
    Make a clone of this grid coordinate
    double
    Get the computed coordinate spacing.
    double
    getFraction(double val)
    Get the fractional part for use in interpolation.
    int
    getIndex(double val)
    Returns an index [0..numPoints-2] such that the grid values index and index+1 enclose the value.
    double
    Get the maximum value of the grid coordinate.
    double
    getMax(int index)
    Get the maximum for a given index
    double
    Get the minimum value of the grid coordinate.
    double
    getMin(int index)
    Get the minimum for a given index
    Get the name of the coordinate
    int
    Get the number of points on the grid (including endpoints).
    int
    getRoundedIndex(double val)
    Gets the nearest index [0..numPoints-1] for nearest neighbor
    double
    getValue(int index)
    Get the value at a given index.
    double[]
    Get the values of the grid points
    boolean
    inRange(double q)
    Check whether a value is in range
    void
    Set the name of the grid coordinate.
    Create a string representation.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • GridCoordinate

      public GridCoordinate(String name, float min, float max, int numPoints)
      Construct a grid coordinate.
      Parameters:
      name - the name of the coordinate
      min - the minimum value
      max - the maximum value
      numPoints - the number of points (including ends)
    • GridCoordinate

      public GridCoordinate(String name, double min, double max, int numPoints)
      Construct a grid coordinate.
      Parameters:
      name - the name of the coordinate
      min - the minimum value
      max - the maximum value
      numPoints - the number of points (including ends)
  • Method Details

    • getValues

      public double[] getValues()
      Get the values of the grid points
      Returns:
      the values of the grid points
    • getRoundedIndex

      public int getRoundedIndex(double val)
      Gets the nearest index [0..numPoints-1] for nearest neighbor
      Parameters:
      val - the value
      Returns:
      the nearest index for nearest neighbor
    • getIndex

      public int getIndex(double val)
      Returns an index [0..numPoints-2] such that the grid values index and index+1 enclose the value. A return of 0 means the value is between min and min + delta; A return of numPoints-2 means the value is between max - delta and max. A return value of -1 indicates out of range.
      Parameters:
      val - the value to test
      Returns:
      an index [0..numPoints-2] such that the grid values index and index+1 enclose the value.
    • getValue

      public double getValue(int index)
      Get the value at a given index.
      Parameters:
      index - the index
      Returns:
      the value at that index.
    • toString

      public String toString()
      Create a string representation.
      Overrides:
      toString in class Object
      Returns:
      a string representation.
    • getNumPoints

      public int getNumPoints()
      Get the number of points on the grid (including endpoints).
      Returns:
      the number of points on the grid (including endpoints).
    • getDelta

      public double getDelta()
      Get the computed coordinate spacing.
      Returns:
      the coordinate spacing.
    • getFraction

      public double getFraction(double val)
      Get the fractional part for use in interpolation.
      Parameters:
      val - the value
      Returns:
      the fraction of spacing.
    • getMin

      public double getMin()
      Get the minimum value of the grid coordinate.
      Returns:
      the minimum value of the grid coordinate.
    • getMax

      public double getMax()
      Get the maximum value of the grid coordinate.
      Returns:
      the maximum value of the grid coordinate.
    • getName

      public String getName()
      Get the name of the coordinate
      Returns:
      the name of the coordinate
    • setName

      public void setName(String name)
      Set the name of the grid coordinate.
      Parameters:
      name - the name of the grid coordinate
    • getMin

      public double getMin(int index)
      Get the minimum for a given index
      Parameters:
      index - the index
      Returns:
      the min for the given index
    • getMax

      public double getMax(int index)
      Get the maximum for a given index
      Parameters:
      index - the index
      Returns:
      the max for the given index
    • inRange

      public boolean inRange(double q)
      Check whether a value is in range
      Parameters:
      q - the value
      Returns:
      true if the value is between min and max
    • clone

      public GridCoordinate clone()
      Make a clone of this grid coordinate
      Overrides:
      clone in class Object