com.simiacryptus.mindseye.pyramid.ValueSampler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mindseye-art Show documentation
Show all versions of mindseye-art Show documentation
Visual Neural Network Applications
/*
* Copyright (c) 2019 by Andrew Charneski.
*
* The author licenses this file to you under the
* Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance
* with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.simiacryptus.mindseye.pyramid;
import java.io.Serializable;
public interface ValueSampler extends Serializable {
double getValue(final double xf, final double yf, final int band);
default ValueSampler wrapped() {
return (xf, yf, band) -> {
while (xf < 0) xf += 1;
xf %= 1;
while (yf < 0) yf += 1;
yf %= 1;
return ValueSampler.this.getValue(xf, yf, band);
};
}
default ValueSampler zoom(double x, double y, double width, double height) {
return zoom(width, height).offset(x, y);
}
default ValueSampler zoom(double width, double height) {
return (xf, yf, band) -> ValueSampler.this.getValue(xf * width, yf * height, band);
}
default ValueSampler offset(double x, double y) {
return (xf, yf, band) -> ValueSampler.this.getValue(x + xf, y + yf, band);
}
default ValueSampler rotate(double angle) {
return (xf, yf, band) -> ValueSampler.this.getValue(
Math.cos(angle) * xf + Math.sin(angle) * yf,
Math.cos(angle) * yf - Math.sin(angle) * xf,
band
);
}
}