examples/experimental/bezier/src/bezier-graph-layer.js
function computeControlPoint(source, target, direction, offset) {
  const midPoint = [(source[0] + target[0]) / 2, (source[1] + target[1]) / 2];
  const dx = target[0] - source[0];
  const dy = target[1] - source[1];
  const normal = [dy, -dx];
  const length = Math.sqrt(Math.pow(normal[0], 2.0) + Math.pow(normal[1], 2.0));
  const normalized = [normal[0] / length, normal[1] / length];
  return [
    midPoint[0] + normalized[0] * offset * direction,
    midPoint[1] + normalized[1] * offset * direction
  ];
}
function computeControlPoint(source, target, direction, offset) {
  const midPoint = [(source[0] + target[0]) / 2, (source[1] + target[1]) / 2];
  const dx = target[0] - source[0];
  const dy = target[1] - source[1];
  const normal = [dy, -dx];
  const length = Math.sqrt(Math.pow(normal[0], 2.0) + Math.pow(normal[1], 2.0));
  const normalized = [normal[0] / length, normal[1] / length];
  return [
    midPoint[0] + normalized[0] * offset * direction,
    midPoint[1] + normalized[1] * offset * direction
  ];
}
function computeControlPoint ( source , target , direction , offset ) { const midPoint = [ ( source [ 0 ] + target [ 0 ] ) / 2 , ( source [ 1 ] + target [ 1 ] ) / 2 ] ; const dx = target [ 0 ] - source [ 0 ] ; const dy = target [ 1 ] - source [ 1 ] ; const normal = [ dy , - dx ] ; const length = Math . sqrt ( Math . pow ( normal [ 0 ] , 2.0 ) + Math . pow ( normal [ 1 ] , 2.0 ) ) ; const normalized = [ normal [ 0 ] / length , normal [ 1 ] / length ] ; return [ midPoint [ 0 ] + normalized [ 0 ] * offset * direction , midPoint [ 1 ] + normalized [ 1 ] * offset * direction ] ; }
A helper function to compute the control point of a quadratic bezier curve
@param  {number[]} source  - the coordinates of source point, ex: [x, y, z]
@param  {number[]} target  - the coordinates of target point, ex: [x, y, z]
@param  {number} direction - the direction of the curve, 1 or -1
@param  {number} offset    - offset from the midpoint
@return {number[]}         - the coordinates of the control point
A helper function to compute the control point of a quadratic bezier curve