You are here

protected function WktGenerator::ddGenerate in Geofield 8

Helper to generate DD coordinates.

Parameters

int $min: The minimum value available to return.

int $max: The minimum value available to return.

bool $int: Force to return an integer value. Defaults to FALSE.

Return value

float|int The coordinate component.

6 calls to WktGenerator::ddGenerate()
WktGenerator::generateLinestring in src/WktGenerator.php
Generates a linestring components array.
WktGenerator::generateMultilinestring in src/WktGenerator.php
Generates a multilinestring coordinates.
WktGenerator::generateMultipoint in src/WktGenerator.php
Generates a multipoint coordinates.
WktGenerator::generateMultipolygon in src/WktGenerator.php
Generates a multipolygon coordinates.
WktGenerator::generatePolygon in src/WktGenerator.php
Generates a polygon components array.

... See full list

File

src/WktGenerator.php, line 23

Class

WktGenerator
Helper class that generates WKT format geometries.

Namespace

Drupal\geofield

Code

protected function ddGenerate($min, $max, $int = FALSE) {
  $func = 'rand';
  if (function_exists('mt_rand')) {
    $func = 'mt_rand';
  }
  $number = $func($min, $max);
  if ($int || $number === $min || $number === $max) {
    return $number;
  }
  $decimals = $func(1, pow(10, 5)) / pow(10, 5);
  return round($number + $decimals, 5);
}