You are here

protected function SvgIconBuilder::getLength in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Layout/Icon/SvgIconBuilder.php \Drupal\Core\Layout\Icon\SvgIconBuilder::getLength()

Gets the height or width of a region.

Parameters

int $number_of_regions: The total number of regions.

int $length: The total height or width of the icon.

int $stroke_width: The width of the region borders.

int $padding: The padding between regions.

Return value

float|int The height or width of a region.

1 call to SvgIconBuilder::getLength()
SvgIconBuilder::calculateSvgValues in core/lib/Drupal/Core/Layout/Icon/SvgIconBuilder.php
Calculates the dimensions and offsets of all regions.

File

core/lib/Drupal/Core/Layout/Icon/SvgIconBuilder.php, line 229

Class

SvgIconBuilder
Builds SVG layout icons.

Namespace

Drupal\Core\Layout\Icon

Code

protected function getLength($number_of_regions, $length, $stroke_width, $padding) {
  if ($number_of_regions === 0) {
    return 0;
  }

  // Half of the stroke width is drawn outside the dimensions.
  $total_stroke = $number_of_regions * $stroke_width;

  // Padding does not precede the first region.
  $total_padding = ($number_of_regions - 1) * $padding;

  // Divide the remaining length by the number of regions.
  return ($length - $total_padding - $total_stroke) / $number_of_regions;
}