public ScalarField(ScalarField field, SGFunction function, bool needJ = true) { _data = new float[field.Size.Product()]; Grid = field.Grid; this.InvalidValue = field.InvalidValue; GridIndex indexIterator = new GridIndex(field.Size); foreach (GridIndex index in indexIterator) { float s = field[(int)index]; if (s == InvalidValue) { this[(int)index] = (float)InvalidValue; } else { Vector g = needJ ? field.SampleDerivative(index) : new Vec2(0, 0); this[(int)index] = function(s, g); } } }
public ScalarField(ScalarField field, SGFunction function, bool needJ = true) { _data = new float[field.Size.Product()]; Grid = field.Grid; this.InvalidValue = field.InvalidValue; GridIndex indexIterator = new GridIndex(field.Size); foreach (GridIndex index in indexIterator) { float s = field[(int)index]; if (s == InvalidValue) { this[(int)index] = (float)InvalidValue; } else { Vector g = needJ ? field.SampleDerivative(index) : new Vec2(0, 0); this[(int)index] = function(s, g); } } }