all files / lib/features/modeling/cmd/helper/ AnchorsHelper.js

92.31% Statements 12/13
83.33% Branches 5/6
100% Functions 6/6
92.31% Lines 12/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63              42× 42×   42×           20× 20×   20×         31×         16×             47×                                   62×   62×       62×    
import {
  getNewAttachPoint
} from '../../../../util/AttachUtil';
 
 
export function getResizedSourceAnchor(connection, shape, oldBounds) {
 
  var waypoints = safeGetWaypoints(connection),
      oldAnchor = waypoints[0];
 
  return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
}
 
 
export function getResizedTargetAnchor(connection, shape, oldBounds) {
 
  var waypoints = safeGetWaypoints(connection),
      oldAnchor = waypoints[waypoints.length - 1];
 
  return getNewAttachPoint(oldAnchor.original || oldAnchor, oldBounds, shape);
}
 
 
export function getMovedSourceAnchor(connection, source, moveDelta) {
  return getResizedSourceAnchor(connection, source, substractPosition(source, moveDelta));
}
 
 
export function getMovedTargetAnchor(connection, target, moveDelta) {
  return getResizedTargetAnchor(connection, target, substractPosition(target, moveDelta));
}
 
 
// helpers //////////////////////
 
function substractPosition(bounds, delta) {
  return {
    x: bounds.x - delta.x,
    y: bounds.y - delta.y,
    width: bounds.width,
    height: bounds.height
  };
}
 
 
/**
 * Return waypoints of given connection; throw if non exists (should not happen!!).
 *
 * @param {Connection} connection
 *
 * @return {Array<Point>}
 */
function safeGetWaypoints(connection) {
 
  var waypoints = connection.waypoints;
 
  Iif (!waypoints.length) {
    throw new Error('connection#' + connection.id + ': no waypoints');
  }
 
  return waypoints;
}