How to use the nudged.estimate function in nudged

To help you get started, we’ve selected a few nudged examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taataa / tapspace / lib / Touchable / Manager.js View on Github external
n = domain.length
    for (k in prevPointers) {
      if (prevPointers.hasOwnProperty(k) && nextPointers.hasOwnProperty(k)) {
        totalTravel += Math.abs(prevPointers[k][0] - nextPointers[k][0]) / n
        totalTravel += Math.abs(prevPointers[k][1] - nextPointers[k][1]) / n
      }
    }

    // Compute current position of the pivot on the plane.
    // Pivot will be undefined if mode has no pivot but enables translation.
    pivot = toRawPivot(self.mode, self.plane)
    // Get current nudged-compatible transformation type string
    type = utils.convertToTransformationType(mode)

    // Estimate optimal transformation
    tr = nudged.estimate(type, domain, range, pivot)

    // Apply the transformation to plane. We also
    // memorize the new pointers for the next onMove call.
    // We want to memorize only their relative location on the plane.
    // This way transformations of the view and parents between
    // onMove calls become part of the resulting transformation.
    // Note that transformBy emits 'transformed' that might eventually
    // cause transformations in the space. Therefore we should do all
    // coordinate-plane conversions before transformBy to avoid weird bugs.
    if (self.view === self.plane) {
      // Somehow we do not need the following line with views:
      // pointersOnItem = multiplyLeft(nextPointersOnItem, tr)
      // If we use the line, everything shakes.
      pointersOnItem = nextPointersOnItem
      // Shortcut for:
      //   itr = new tapspace.geom.ITransform(tr, plane)
github taataa / tapspace / lib / SpaceTransform.js View on Github external
var normPivot
  if (typeof pivot !== 'undefined') {
    normPivot = pivot.toPointOn(plane)
  }

  // Allow single points
  if (domain.hasOwnProperty('_T')) { domain = [domain] }
  if (range.hasOwnProperty('_T')) { range = [range] }

  // Convert all SpacePoints onto the plane and to arrays
  var normDomain = SpaceTransform.normalizeToPoints(domain, plane)
  var normRange = SpaceTransform.normalizeToPoints(range, plane)

  // Then compute optimal transformation on the plane
  var T = nudged.estimate(type, normDomain, normRange, normPivot)
  return new SpaceTransform(plane, T)
}
github taataa / tapspace / lib / Touchable / Recognizer.js View on Github external
n = domain.length
    for (k in prevPointers) {
      if (prevPointers.hasOwnProperty(k) && nextPointers.hasOwnProperty(k)) {
        totalTravel += Math.abs(prevPointers[k][0] - nextPointers[k][0]) / n
        totalTravel += Math.abs(prevPointers[k][1] - nextPointers[k][1]) / n
      }
    }

    // Compute current position of the pivot on the plane.
    // Pivot will be undefined if mode has no pivot but enables translation.
    pivot = toRawPivot(mode, sourceItem)
    // Get current nudged-compatible transformation type string
    type = utils.convertToTransformationType(mode)

    // Estimate optimal transformation
    tr = nudged.estimate(type, domain, range, pivot)

    // Apply the transformation to targetItem. We also
    // memorize the new pointers for the next onMove call.
    // We want to memorize only their relative location on the source item.
    // This way transformations of the view and parents between
    // onMove calls become part of the resulting transformation.
    // Note that transformBy emits 'transformed' that might eventually
    // cause transformations in the space. Therefore we should do all
    // coordinate-plane conversions before transformBy to avoid weird bugs.

    itr = new ITransform(tr, sourceItem)

    if (typeof targetItem === 'function') {
      pointersOnItem = nextPointersOnItem
      targetItem(itr)
    } else if (view === targetItem) {
github taataa / tapspace / lib / geom / ITransform.js View on Github external
if (range.hasOwnProperty('_vec')) {
    range = [range]
  } else if (range.hasOwnProperty('_p')) {
    range = range.toArray()
  }

  // Convert all IVectors onto the plane and to arrays
  var piv2arr = function (iv) {
    return [iv._vec.x, iv._vec.y]
  }
  normDomain = domain.map(piv2arr)
  normRange = range.map(piv2arr)

  // Then compute optimal transformation on the plane
  tr = nudged.estimate(type, normDomain, normRange, normPivot)
  return new ITransform(tr)
}

nudged

Affine transformation estimator e.g. for multi-touch gestures and calibration

MIT
Latest version published 1 month ago

Package Health Score

70 / 100
Full package analysis