How to use the @antv/matrix-util.vec2.normalize function in @antv/matrix-util

To help you get started, we’ve selected a few @antv/matrix-util 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 antvis / G6 / src / util / path.ts View on Github external
export const getControlPoint = (
  startPoint: IPoint,
  endPoint: IPoint,
  percent: number = 0,
  offset: number = 0
): IPoint => {
  const point: IPoint = {
    x: (1 - percent) * startPoint.x + percent * endPoint.x,
    y: (1 - percent) * startPoint.y + percent * endPoint.y,
  };

  let tangent: number[] = [];
  vec2.normalize(tangent, [endPoint.x - startPoint.x, endPoint.x - startPoint.y]);

  if (tangent.length === 0) {
    tangent = [0, 0];
  }
  const perpendicular = [-tangent[1] * offset, tangent[0] * offset]; // 垂直向量
  point.x += perpendicular[0];
  point.y += perpendicular[1];
  return point;
};
github antvis / G2 / packages / component / src / axis / line.ts View on Github external
public getSideVector(offset) {
    const isVertical = this.get('isVertical');
    const factor = this.get('factor');
    // if (Util.isArray(offset)) {
    //   return offset.map(value => value * factor);
    // }
    if (!Util.isNumber(offset)) {
      return [0, 0];
    }
    const start = this.get('start');
    const end = this.get('end');
    const axisVector = this.getAxisVector();
    const normal = vec2.normalize([], axisVector);
    let direction = false;
    if ((isVertical && start.y < end.y) || (!isVertical && start.x > end.x)) {
      direction = true;
    }
    const verticalVector = vec2.vertical([], normal, direction);
    return vec2.scale([], verticalVector, offset * factor);
  }