Skip to content

Commit

Permalink
new entrances temp backup 4 (squash proposed)
Browse files Browse the repository at this point in the history
  • Loading branch information
stellarator committed Mar 3, 2016
1 parent 1f99dc2 commit ff33e2b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
50 changes: 21 additions & 29 deletions src/DGEntrance/src/DGEntrance2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ DG.Entrance.Arrow2 = DG.Polyline.extend({
_points: shape.points,
_endings: shape.endings,
_drawings: shape.drawings,
_paths: {},
points: {},
drawings: {}
};
Expand Down Expand Up @@ -90,61 +89,54 @@ DG.Entrance.Arrow2 = DG.Polyline.extend({
_endings = this._shape._endings[zoom],
_drawings = this._shape._drawings[zoom],
i, end = _points.length - 1,
path, angles, width, lastSeg,
path, points, angles, width, lastSeg,
x, y, lp, fp;

// 'path' will contain projected and translated vectors for shape path
this._shape._paths[zoom] = this._transform.getTranslatedPath(zoom);
path = this._shape._paths[zoom].map(function (el) { return el.slice(); });
path = this._transform.getTranslatedPath(zoom);

// 'angles' array will contain angles between vectors
angles = this._transform.getAngles();

// Do some preparations
lp = _points[end];
width = Math.abs(lp[1]);

lastSeg = {
arrow: Math.abs(lp[0]),
path: Math.abs(path[1][0])
};
// TODO: Check for short last seg (less than arrow shape)
lastSeg = Math.abs(lp[0]) + width + 5 - Math.abs(path[1][0]);
if (lastSeg > 0) {
// Last path segment is shorter than arrow, we'll have to displace arrow

}

// Main construction cycle
this._getStrokePoints(path, angles, width, this._transform.getEmptyPoints());
points = this._getStrokePoints(path, angles, width, this._transform.getEmptyPoints());

// Construct endings


},

_getStrokePoints: function (path, angles, width, points) {
var i, v, len, x, dx;
_getStrokePoints: function (path, angles, width, points, endings) {
var i, v, len, dir, x, dx;

for (i = 0, len = angles.length; i < len; i++) {
x = path[i + 1][0];
dx = width * angles[i].cot;
if (angles[i].sin < 0) {
points[i * 2][0] = x + dx;
points[i * 2 + 1][0] = x - dx;
} else {
points[i * 2][0] = x - dx;
points[i * 2 + 1][0] = x + dx;
}
points[i * 2][0] = x + dx;
points[i * 2][1] = -width;
points[i * 2 + 1][0] = x - dx;
points[i * 2 + 1][1] = width;

v = this._transform._rotate([[dx, 0]], angles[i]);

path = this._transform.translate(path, angles[i], [v[0] + x, v[1]]);
points = this._transform.translate(points, angles[i], [v[0] + x, v[1]]);
path = this._transform.transRate(path, angles[i], [x, 0]);
points = this._transform.transRate(points, angles[i], [x, 0]);
}
dx = path[i + 2][0];

dx = path[i + 1][0];
points[i * 2][0] = dx;
points[i * 2][1] = -width;
points[i * 2 + 1][0] = dx;
points[i * 2 + 1][1] = width;
return this._transform._unRotate(points, angles.fullAngle);

return this._transform.transRate(points, angles.fullAngle, path[0]);
}
});

Expand Down Expand Up @@ -269,9 +261,9 @@ DG.Entrance.Arrow.SHAPE = {
transform = new DG.TransformByVector([[0, 0], [0, 0]]);

for (scale = 0.9, i = shapeZoom - 1; i > minZoom; i--, scale -= 0.1) {
DG.Entrance.Arrow.points[i] = transform._scale(points, scale);
DG.Entrance.Arrow.endings[i] = transform._scale(endings, scale);
DG.Entrance.Arrow.drawings[i] = drawings;
DG.Entrance.Arrow.SHAPE.points[i] = transform._scale(points, scale);
DG.Entrance.Arrow.SHAPE.endings[i] = transform._scale(endings, scale);
DG.Entrance.Arrow.SHAPE.drawings[i] = drawings;
}
})();

Expand Down
32 changes: 25 additions & 7 deletions src/DGEntrance/src/DGTransformByVector.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ DG.TransformByVector.prototype = {
return _ring;
},

_translate: function (ring, x, y) {
var dx, dy, _ring = [];

if (typeof x === 'number') {
dx = x; dy = y;
} else {
dx = x[0]; dy = x[1]; // 'x' is vector object [x, y]
}
for (var j = 0, len = ring.length; j < len; j++) {
x = ring[j][0] + dx;
y = ring[j][1] + dy;
_ring.push([x, y]);
}
return _ring;
},

_getAngle: function (x, y, z) {
var l, sp, x1, y1, x2, y2;

Expand Down Expand Up @@ -180,8 +196,8 @@ DG.extend(DG.TransformShape.prototype, {
// Exclude angle from vectors array
this._excludeVector(i);
} else {
angle.cot = (1 + angle.cos) / absSin; // This is half ∢α cotangent
angle.dir = angle.sin < 0 ? 1 : -1; // TODO: Check this!
// This is half ∢α cotangent, sign describes angle direction and used to shortcut stroke calculations
angle.cot = (1 + angle.cos) / absSin * (angle.sin < 0 ? 1 : -1); // TODO: Check this!
angles.push(angle);

cos = fullAngle.cos * angle.cos - fullAngle.sin * angle.sin;
Expand All @@ -191,7 +207,9 @@ DG.extend(DG.TransformShape.prototype, {
}
}

// Used in final stroke points translation
angles.fullAngle = fullAngle;
//angles.fullAngle = {cos: fullAngle.cos, sin: -fullAngle.sin};
return angles;
},

Expand Down Expand Up @@ -224,7 +242,7 @@ DG.extend(DG.TransformShape.prototype, {
return result;
},

translate: function (ring, angle, vector) {
transRate: function (ring, angle, vector) {
var cos = angle.cos,
sin = angle.sin,
dx = vector[0],
Expand All @@ -233,10 +251,10 @@ DG.extend(DG.TransformShape.prototype, {
_ring = [];

for (var j = 0, len = ring.length; j < len; j++) {
rx = ring[j][0];
ry = ring[j][1];
x = rx * cos - ry * sin + dx;
y = rx * sin + ry * cos + dy;
rx = ring[j][0] - dx;
ry = ring[j][1] - dy;
x = rx * cos - ry * sin;
y = rx * sin + ry * cos;
_ring.push([x, y]);
}
return _ring;
Expand Down

0 comments on commit ff33e2b

Please sign in to comment.