function getSnapOffset(event, axis, elementRegistry) {
  var context = event.context,
      shape = event.shape,
      gridSnappingContext = context.gridSnappingContext,
      snapLocation = gridSnappingContext.snapLocation,
      snapOffset = gridSnappingContext.snapOffset;

  // cache snap offset
  if (snapOffset && isNumber(snapOffset[ axis ])) {
    return snapOffset[ axis ];
  }

  if (!snapOffset) {
    snapOffset = gridSnappingContext.snapOffset = {};
  }

  if (!isNumber(snapOffset[ axis ])) {
    snapOffset[ axis ] = 0;
  }

  if (!shape) {
    return snapOffset[ axis ];
  }

  if (!elementRegistry.get(shape.id)) {

    if (isHorizontal(axis)) {
      snapOffset[ axis ] += shape[ axis ] + shape.width / 2;
    } else {
      snapOffset[ axis ] += shape[ axis ] + shape.height / 2;
    }
  }

  if (!snapLocation) {
    return snapOffset[ axis ];
  }

  if (axis === 'x') {
    if (/left/.test(snapLocation)) {
      snapOffset[ axis ] -= shape.width / 2;
    } else if (/right/.test(snapLocation)) {
      snapOffset[ axis ] += shape.width / 2;
    }
  } else {
    if (/top/.test(snapLocation)) {
      snapOffset[ axis ] -= shape.height / 2;
    } else if (/bottom/.test(snapLocation)) {
      snapOffset[ axis ] += shape.height / 2;
    }
  }

  return snapOffset[ axis ];
}
Get snap offset.
Offset is cached.

@param {Object} event
@param {string} axis
@param {ElementRegistry} elementRegistry

@return {number}