mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-12 07:43:11 +00:00
"Collapse" few var statements.
This commit is contained in:
parent
36416e65a3
commit
ca0df1bd15
3 changed files with 37 additions and 30 deletions
|
|
@ -28,13 +28,13 @@
|
|||
};
|
||||
|
||||
Intersection.intersectLineLine = function (a1, a2, b1, b2) {
|
||||
var result;
|
||||
var ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x);
|
||||
var ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x);
|
||||
var u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
|
||||
var result,
|
||||
ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x),
|
||||
ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x),
|
||||
u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
|
||||
if (u_b != 0) {
|
||||
var ua = ua_t / u_b;
|
||||
var ub = ub_t / u_b;
|
||||
var ua = ua_t / u_b,
|
||||
ub = ub_t / u_b;
|
||||
if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) {
|
||||
result = new Intersection("Intersection");
|
||||
result.points.push(new Point(a1.x + ua * (a2.x - a1.x), a1.y + ua * (a2.y - a1.y)));
|
||||
|
|
@ -55,12 +55,14 @@
|
|||
};
|
||||
|
||||
Intersection.intersectLinePolygon = function(a1,a2,points){
|
||||
var result = new Intersection("No Intersection");
|
||||
var length = points.length;
|
||||
var result = new Intersection("No Intersection"),
|
||||
length = points.length;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
var b1 = points[i];
|
||||
var b2 = points[(i+1) % length];
|
||||
var inter = Intersection.intersectLineLine(a1, a2, b1, b2);
|
||||
var b1 = points[i],
|
||||
b2 = points[(i+1) % length],
|
||||
inter = Intersection.intersectLineLine(a1, a2, b1, b2);
|
||||
|
||||
result.appendPoints(inter.points);
|
||||
}
|
||||
if (result.points.length > 0) {
|
||||
|
|
@ -70,12 +72,14 @@
|
|||
};
|
||||
|
||||
Intersection.intersectPolygonPolygon = function (points1, points2) {
|
||||
var result = new Intersection("No Intersection");
|
||||
var length = points1.length;
|
||||
var result = new Intersection("No Intersection"),
|
||||
length = points1.length;
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
var a1 = points1[i];
|
||||
var a2 = points1[(i+1) % length];
|
||||
var inter = Intersection.intersectLinePolygon(a1, a2, points2);
|
||||
var a1 = points1[i],
|
||||
a2 = points1[(i+1) % length],
|
||||
inter = Intersection.intersectLinePolygon(a1, a2, points2);
|
||||
|
||||
result.appendPoints(inter.points);
|
||||
}
|
||||
if (result.points.length > 0) {
|
||||
|
|
@ -85,15 +89,16 @@
|
|||
};
|
||||
|
||||
Intersection.intersectPolygonRectangle = function (points, r1, r2) {
|
||||
var min = r1.min(r2);
|
||||
var max = r1.max(r2);
|
||||
var topRight = new Point(max.x, min.y);
|
||||
var bottomLeft = new Point(min.x, max.y);
|
||||
var inter1 = Intersection.intersectLinePolygon(min, topRight, points);
|
||||
var inter2 = Intersection.intersectLinePolygon(topRight, max, points);
|
||||
var inter3 = Intersection.intersectLinePolygon(max, bottomLeft, points);
|
||||
var inter4 = Intersection.intersectLinePolygon(bottomLeft, min, points);
|
||||
var result = new Intersection("No Intersection");
|
||||
var min = r1.min(r2),
|
||||
max = r1.max(r2),
|
||||
topRight = new Point(max.x, min.y),
|
||||
bottomLeft = new Point(min.x, max.y),
|
||||
inter1 = Intersection.intersectLinePolygon(min, topRight, points),
|
||||
inter2 = Intersection.intersectLinePolygon(topRight, max, points),
|
||||
inter3 = Intersection.intersectLinePolygon(max, bottomLeft, points),
|
||||
inter4 = Intersection.intersectLinePolygon(bottomLeft, min, points),
|
||||
result = new Intersection("No Intersection");
|
||||
|
||||
result.appendPoints(inter1.points);
|
||||
result.appendPoints(inter2.points);
|
||||
result.appendPoints(inter3.points);
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@
|
|||
return new Point(this.x + (that.x - this.x) * t, this.y + (that.y - this.y) * t);
|
||||
},
|
||||
distanceFrom: function (that) {
|
||||
var dx = this.x - that.x;
|
||||
var dy = this.y - that.y;
|
||||
var dx = this.x - that.x,
|
||||
dy = this.y - that.y;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
},
|
||||
min: function (that) {
|
||||
|
|
@ -111,8 +111,8 @@
|
|||
this.y = that.y;
|
||||
},
|
||||
swap: function (that) {
|
||||
var x = this.x;
|
||||
var y = this.y;
|
||||
var x = this.x,
|
||||
y = this.y;
|
||||
this.x = that.x;
|
||||
this.y = that.y;
|
||||
that.x = x;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
var Canvas = this.Canvas || (this.Canvas = { });
|
||||
|
||||
if (Canvas.util) return;
|
||||
if (Canvas.util) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
|
|
|
|||
Loading…
Reference in a new issue