/// <summary> /// Returns a grid point at the given point. /// Assumes the point is within the bounds of the grid. /// </summary> /// <param name="point"></param> /// <returns></returns> public GridPoint2d GridPointAtUnsafe(Vec2d point) { GridPoint2d result = new GridPoint2d(); GridPointAtUnsafe(point, result); return(result); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <returns></returns> public Vec2d CoordinateAt(GridPoint2d point) { var corners = point.Corners; var weights = point.Weights; var sum = new Vec2d(); for (int i = 0; i < 4; i++) { sum += CoordinateAt(corners[i]) * weights[i]; } return(sum); }
/// <summary> /// Returns a grid point at the given point. /// Assumes the point is within the bounds of the grid. /// </summary> /// <param name="point"></param> /// <param name="result"></param> public void GridPointAtUnsafe(Vec2d point, GridPoint2d result) { point = ToGridSpace(point); result.SetWeights( zMath.Fract(point.X, out int i0), zMath.Fract(point.Y, out int j0) ); j0 *= _nx; int i1 = i0 + 1; int j1 = j0 + _nx; var corners = result.Corners; corners[0] = i0 + j0; corners[1] = i1 + j0; corners[2] = i0 + j1; corners[3] = i1 + j1; }
/// <summary> /// Returns a grid point at the given point. /// </summary> /// <param name="point"></param> /// <param name="result"></param> public void GridPointAt(Vec2d point, GridPoint2d result) { point = ToGridSpace(point); result.SetWeights( zMath.Fract(point.X, out int i0), zMath.Fract(point.Y, out int j0) ); int i1 = WrapX(i0 + 1); int j1 = WrapY(j0 + 1) * _nx; i0 = WrapX(i0); j0 = WrapY(j0) * _nx; var corners = result.Corners; corners[0] = i0 + j0; corners[1] = i1 + j0; corners[2] = i0 + j1; corners[3] = i1 + j1; }
/// <inheritdoc /> public sealed override double ValueAt(GridPoint2d point) { return(FieldUtil.ValueAt(Values, point.Corners, point.Weights)); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="amount"></param> public static void IncrementAt(this GridField2d <Vec2d> field, GridPoint2d point, Vec2d amount) { FieldUtil.IncrementAt(field, point.Corners, point.Weights, amount); }
/// <summary> /// /// </summary> /// <param name="point"></param> /// <param name="value"></param> public static void SetAt(this GridField2d <Vec2d> field, GridPoint2d point, Vec2d value) { FieldUtil.SetAt(field, point.Corners, point.Weights, value); }