PageSourceSearch

https://sciencevsmagic.net/tiles/js/regular/v2.js

js sciencevsmagic.net collected 2026-09-24 10:22:25 UTC 2,744 bytes, 128 lines download raw bytes

1modules.v2=(function(){
2	'use strict';
3	var v2={};
4	//needs my math library
5	var math=modules.math;
6	v2.v2=function(x,y){//a vector2
7		return {x:x||0,y:y||0};
8	};
9	v2.clone=function(v){
10		return {x:v.x,y:v.y};
11	};
12	v2.pythag=function(v){//distance covered by a vector
13		return Math.sqrt(v.x*v.x+v.y*v.y);
14	};
15	v2.minus=function(va,vb){//new vector, va-vb
16		return v2.v2(va.x-vb.x,va.y-vb.y);
17	};
18	v2.between=function(va,vb){
19		return v2.minus(vb,va);
20	};
21	v2.add=function(va,vb){//new vector, va-vb
22		return v2.v2(va.x+vb.x,va.y+vb.y);
23	};
24	v2.distance=function(va,vb){//straight line distance between two vectors
25		return v2.pythag(v2.minus(vb,va));
26	};
27	v2.mult=function(v,s){//new vector, v*s
28		return v2.v2(v.x*s,v.y*s);
29	};
30	v2.divide=function(v,s){
31		return v2.mult(v,1/s);
32	};
33	v2.invert=function(v){
34		return v2.v2(-v.x,-v.y);
35	};
36	v2.length=function(v){//length of the vector from 0,0
37		return math.pythag(v.x,v.y);
38	};
39	v2.normalise=function(v){
40		return v2.divide(v,v2.length(v));
41	};
42	v2.direction=function(o,to){
43		return Math.atan2(to.y-o.y,to.x-o.x);
44	};
45	v2.indirection=function(a,d){
46		return {x:Math.cos(a)*d,y:Math.sin(a)*d};
47	};
48	v2.round=function(v){
49		v.x=Math.round(v.x);
50		v.y=Math.round(v.y);
51		return v;
52	};
53	v2.set=function(a,b){//set the values of a to the values of b.
54		a.x=b.x;
55		a.y=b.y;
56		return a;
57	};
58	v2.lerp=function(a,b,s){//returns a point s-way between a and b.
59		return {x:math.lerp(a.x,b.x,s),y:math.lerp(a.y,b.y,s)};
60	};
61	v2.dot=function(a,b){
62		return a.x*b.x + a.y*b.y;
63	};
64	v2.cross=function(a,b,c){
65		return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
66	};
67	v2.rotate=function(a,angle){
68		var v={};
69		var cos=Math.cos(angle);
70		var sin=Math.sin(angle);
71		v.x=a.x*cos-a.y*sin;
72		v.y=a.y*cos+a.x*sin;
73		return v;
74	};
75	v2.rotatesquare=function(a){
76		return {x:a.y,y:-a.x};
77	};
78	v2.transform=function(a,spec){
79		var v=v2.clone(a);
80		if (spec.r){
81			v=v2.mult(v,spec.r);
82		}
83		if (spec.a){
84			v=v2.rotate(v,spec.a);
85		}
86		if (spec.x){
87			v.x+=spec.x;
88		}
89		if (spec.y){
90			v.y+=spec.y;
91		}
92		return v;
93	};
94	v2.boundingbox=function(points){
95		var box={
96			x0:points[0].x,
97			x1:points[0].x,
98			y0:points[0].y,
99			y1:points[0].y
100		};
101		var i;
102		var point;
103		for (i=1;i<points.length;i++){
104			point=points[i];
105			box.x0=Math.min(point.x,box.x0);
106			box.x1=Math.max(point.x,box.x1);
107			box.y0=Math.min(point.y,box.y0);
108			box.y1=Math.max(point.y,box.y1);
109		}
110		box.w=box.x1-box.x0;
111		box.h=box.y1-box.y0;
112		box.x=box.x0+box.w/2;
113		box.y=box.y0+box.h/2;
114		return box;
115	};
116	v2.average=function(points){
117		var totalx=0;
118		var totaly=0;
119		var i=0;
120		while(i<points.length){
121			totalx+=points[i].x;
122			totaly+=points[i].y;
123			i++;
124		}
125		return {x:totalx/points.length,y:totaly/points.length};
126	};
127	return v2;
128}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.