Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
}
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) {
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)
}