package umontreal.iro.lecuyer.hups;
/* *
* Title:
* Description:
* Copyright: Copyright (c)
* Company:
* @author
* @version 1.0
*/
import umontreal.iro.lecuyer.util.PrintfFormat;
/**
* This container class embodies a point set to which a
* Baker transformation is applied.
* It transforms each coordinate u into 2u if u <= 1/2
* and 2(1 - u) if u > 1/2.
*
*/
public class BakerTransformedPointSet extends ContainerPointSet {
/**
* Constructs a Baker-transformed point set from the given point set P.
*
* @param P point set for which we want a Baker-transfomed version
*
*
*/
public BakerTransformedPointSet (PointSet P) {
init (P);
}
public double getCoordinate (int i, int j) {
double u = P.getCoordinate (i, j);
if (u < 0.5) return 2.0 * u;
else return 2.0 * (1 - u);
}
public PointSetIterator iterator(){
return new BakerTransformedPointSetIterator();
}
public String toString() {
return "Baker transformed point set of: {" + PrintfFormat.NEWLINE
+ P.toString() + PrintfFormat.NEWLINE + "}";
}
/*
public String formatPoints() {
try {
return super.formatPoints();
}
catch (UnsupportedOperationException e) {
return "The values are Baker transformed for each coordinate:" +
PrintfFormat.NEWLINE + " {" +
P.formatPoints() + PrintfFormat.NEWLINE + "}";
}
}
*/
// ***************************************************************
protected class BakerTransformedPointSetIterator
extends ContainerPointSetIterator {
public double nextCoordinate() {
double u = innerIterator.nextCoordinate();
if (u < 0.5) return 2.0 * u;
else return 2.0 * (1.0 - u);
}
// Same as nextCoordinate.
public double nextDouble() {
double u = innerIterator.nextCoordinate();
if (u < 0.5) return 2.0 * u;
else return 2.0 * (1.0 - u);
}
public void nextCoordinates (double p[], int d) {
innerIterator.nextCoordinates (p, d);
for (int j = 0; j < d; j++)
if (p[j] < 0.5) p[j] *= 2.0;
else p[j] = 2.0 * (1.0 - p[j]);
}
public int nextPoint (double p[], int d) {
innerIterator.nextPoint (p, d);
for (int j = 0; j < d; j++)
if (p[j] < 0.5) p[j] *= 2.0;
else p[j] = 2.0 * (1.0 - p[j]);
return getCurPointIndex();
}
}
}
Ads help maintain this website.