Blame view

node_modules/zrender/lib/core/vector.js 2.45 KB
bd028579   易尊强   2/28
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  export function create(x, y) {
      if (x == null) {
          x = 0;
      }
      if (y == null) {
          y = 0;
      }
      return [x, y];
  }
  export function copy(out, v) {
      out[0] = v[0];
      out[1] = v[1];
      return out;
  }
  export function clone(v) {
      return [v[0], v[1]];
  }
  export function set(out, a, b) {
      out[0] = a;
      out[1] = b;
      return out;
  }
  export function add(out, v1, v2) {
      out[0] = v1[0] + v2[0];
      out[1] = v1[1] + v2[1];
      return out;
  }
  export function scaleAndAdd(out, v1, v2, a) {
      out[0] = v1[0] + v2[0] * a;
      out[1] = v1[1] + v2[1] * a;
      return out;
  }
  export function sub(out, v1, v2) {
      out[0] = v1[0] - v2[0];
      out[1] = v1[1] - v2[1];
      return out;
  }
  export function len(v) {
      return Math.sqrt(lenSquare(v));
  }
  export var length = len;
  export function lenSquare(v) {
      return v[0] * v[0] + v[1] * v[1];
  }
  export var lengthSquare = lenSquare;
  export function mul(out, v1, v2) {
      out[0] = v1[0] * v2[0];
      out[1] = v1[1] * v2[1];
      return out;
  }
  export function div(out, v1, v2) {
      out[0] = v1[0] / v2[0];
      out[1] = v1[1] / v2[1];
      return out;
  }
  export function dot(v1, v2) {
      return v1[0] * v2[0] + v1[1] * v2[1];
  }
  export function scale(out, v, s) {
      out[0] = v[0] * s;
      out[1] = v[1] * s;
      return out;
  }
  export function normalize(out, v) {
      var d = len(v);
      if (d === 0) {
          out[0] = 0;
          out[1] = 0;
      }
      else {
          out[0] = v[0] / d;
          out[1] = v[1] / d;
      }
      return out;
  }
  export function distance(v1, v2) {
      return Math.sqrt((v1[0] - v2[0]) * (v1[0] - v2[0])
          + (v1[1] - v2[1]) * (v1[1] - v2[1]));
  }
  export var dist = distance;
  export function distanceSquare(v1, v2) {
      return (v1[0] - v2[0]) * (v1[0] - v2[0])
          + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  }
  export var distSquare = distanceSquare;
  export function negate(out, v) {
      out[0] = -v[0];
      out[1] = -v[1];
      return out;
  }
  export function lerp(out, v1, v2, t) {
      out[0] = v1[0] + t * (v2[0] - v1[0]);
      out[1] = v1[1] + t * (v2[1] - v1[1]);
      return out;
  }
  export function applyTransform(out, v, m) {
      var x = v[0];
      var y = v[1];
      out[0] = m[0] * x + m[2] * y + m[4];
      out[1] = m[1] * x + m[3] * y + m[5];
      return out;
  }
  export function min(out, v1, v2) {
      out[0] = Math.min(v1[0], v2[0]);
      out[1] = Math.min(v1[1], v2[1]);
      return out;
  }
  export function max(out, v1, v2) {
      out[0] = Math.max(v1[0], v2[0]);
      out[1] = Math.max(v1[1], v2[1]);
      return out;
  }