-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.js
More file actions
77 lines (76 loc) · 1.49 KB
/
test2.js
File metadata and controls
77 lines (76 loc) · 1.49 KB
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
function Vector(x,y)
{
this.x=x;
this.y=y;
}
Vector.prototype.plus = function(v)
{
var elem={};
elem.x=this.x+v.x;
elem.y=this.y+v.y;
return elem;
}
Vector.prototype.minus = function(v)
{
var elem={};
elem.x=this.x-v.x;
elem.y=this.y-v.y;
return elem;
}
Vector.prototype.times = function(number)
{
var elem={};
elem.x=this.x*number;
elem.y=this.y*number;
return elem;
}
//преобразование в веб-методы
exports.sumOfTwoVectors = function(x1,y1,x2,y2)
{
try
{
x1 = parseInt(x1);
x2 = parseInt(x2);
y1 = parseInt(y1);
y2 = parseInt(y2);
}
catch(error)
{
return null;
}
var vector1 = new Vector(x1,y1);
var vector2 = new Vector(x2,y2);
return vector1.plus(vector2);
}
exports.diffOfTwoVectors = function(x1,y1,x2,y2)
{
try
{
x1 = parseInt(x1);
x2 = parseInt(x2);
y1 = parseInt(y1);
y2 = parseInt(y2);
}
catch(error)
{
return null;
}
var vector1 = new Vector(x1,y1);
var vector2 = new Vector(x2,y2);
return vector1.minus(vector2);
}
exports.compositionOfTwoVectors = function(x1,y1,times)
{
try
{
x1 = parseInt(x1);
y1 = parseInt(y1);
times = parseInt(times);
}
catch(error)
{
return null;
}
var vector1 = new Vector(x1,y1);
return vector1.times(times);
}