Skip to content

Commit

Permalink
Expose possibility to generate random value of given type
Browse files Browse the repository at this point in the history
and use min and max from default envelope settings when generating random points.
  • Loading branch information
burqen committed Aug 15, 2018
1 parent 63c4ba0 commit db08842
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
Expand Up @@ -244,6 +244,11 @@ public Value nextValue()
return randoms.nextValue();
}

public Value nextValue( RandomValues.Types type )
{
return randoms.nextValue( type );
}

// ============================
// Other utility methods
// ============================
Expand Down
Expand Up @@ -61,7 +61,7 @@
public class RandomValues
{

enum Types
public enum Types
{
BOOLEAN,
BYTE,
Expand Down Expand Up @@ -655,7 +655,21 @@ public TextValue nextTextValue( int minLength, int maxLength )
*/
public Value nextValue()
{
Types type = nextType();
return nextValue( nextType() );
}

/**
* Returns the next pseudorandom {@link Value} of given type
* <p>
* The length of strings will be governed by {@link Configuration#stringMinLength()} and
* {@link Configuration#stringMaxLength()} and
* the length of arrays will be governed by {@link Configuration#arrayMinLength()} and
* {@link Configuration#arrayMaxLength()}
*
* @return the next pseudorandom {@link Value} of given type
*/
public Value nextValue( Types type )
{
switch ( type )
{
case BOOLEAN:
Expand Down Expand Up @@ -1257,7 +1271,9 @@ public Value nextTemporalValue()
*/
public PointValue nextCartesianPoint()
{
return Values.pointValue( CoordinateReferenceSystem.Cartesian, generator.nextDouble(), generator.nextDouble() );
double x = randomCartesianCoordinate();
double y = randomCartesianCoordinate();
return Values.pointValue( CoordinateReferenceSystem.Cartesian, x, y );
}

/**
Expand All @@ -1267,8 +1283,10 @@ public PointValue nextCartesianPoint()
*/
public PointValue nextCartesian3DPoint()
{
return Values.pointValue( CoordinateReferenceSystem.Cartesian_3D, generator.nextDouble(),
generator.nextDouble(), generator.nextDouble() );
double x = randomCartesianCoordinate();
double y = randomCartesianCoordinate();
double z = randomCartesianCoordinate();
return Values.pointValue( CoordinateReferenceSystem.Cartesian_3D, x, y, z );
}

/**
Expand All @@ -1278,8 +1296,8 @@ public PointValue nextCartesian3DPoint()
*/
public PointValue nextGeographicPoint()
{
double longitude = generator.nextDouble() * 360.0 - 180.0;
double latitude = generator.nextDouble() * 180.0 - 90.0;
double longitude = randomLongitude();
double latitude = randomLatitude();
return Values.pointValue( CoordinateReferenceSystem.WGS84, longitude, latitude );
}

Expand All @@ -1290,10 +1308,36 @@ public PointValue nextGeographicPoint()
*/
public PointValue nextGeographic3DPoint()
{
double longitude = generator.nextDouble() * 360.0 - 180.0;
double latitude = generator.nextDouble() * 180.0 - 90.0;
return Values.pointValue( CoordinateReferenceSystem.WGS84_3D, longitude, latitude,
generator.nextDouble() * 10000 );
double longitude = randomLongitude();
double latitude = randomLatitude();
double z = randomCartesianCoordinate();
return Values.pointValue( CoordinateReferenceSystem.WGS84_3D, longitude, latitude, z );
}

private double randomLatitude()
{
double spatialDefaultMinLatitude = -90;
double spatialDefaultMaxLatitude = 90;
return doubleBetween( spatialDefaultMinLatitude, spatialDefaultMaxLatitude );
}

private double randomLongitude()
{
double spatialDefaultMinLongitude = -180;
double spatialDefaultMaxLongitude = 180;
return doubleBetween( spatialDefaultMinLongitude, spatialDefaultMaxLongitude );
}

private double randomCartesianCoordinate()
{
double spatialDefaultMinExtent = -1000000;
double spatialDefaultMaxExtent = 1000000;
return doubleBetween( spatialDefaultMinExtent, spatialDefaultMaxExtent );
}

private double doubleBetween( double min, double max )
{
return generator.nextDouble() * (max - min) + min;
}

/**
Expand Down

0 comments on commit db08842

Please sign in to comment.