Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client-data/js/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ function messageForTool(message) {
else Tools.pendingMessages[name].push(message);
}

if (message.tool !== 'Hand' && message.deltax != null && message.deltay != null) {
if (message.tool !== 'Hand' && message.transform != null) {
//this message has special info for the mover
messageForTool({ tool: 'Hand', type: 'update', deltax: message.deltax || 0, deltay: message.deltay || 0, id: message.id });
messageForTool({ tool: 'Hand', type: 'update', transform: message.transform, id: message.id});
}
}

Expand Down Expand Up @@ -685,8 +685,8 @@ Tools.svg.height.baseVal.value = document.body.clientHeight;


(function () {
let pos = {top: 0, scroll:0};
let menu = document.getElementById("menu");
var pos = {top: 0, scroll:0};
var menu = document.getElementById("menu");
function menu_mousedown(evt) {
pos = {
top: menu.scrollTop,
Expand All @@ -696,7 +696,7 @@ Tools.svg.height.baseVal.value = document.body.clientHeight;
document.addEventListener("mouseup", menu_mouseup);
}
function menu_mousemove(evt) {
const dy = evt.clientY - pos.scroll;
var dy = evt.clientY - pos.scroll;
menu.scrollTop = pos.top - dy;
}
function menu_mouseup(evt) {
Expand Down
54 changes: 43 additions & 11 deletions client-data/js/intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,48 @@ if (!SVGGraphicsElement.prototype.transformedBBox || !SVGGraphicsElement.prototy
[pointInTransformedBBox,
transformedBBoxIntersects] = (function () {

let applyTransform = function (m,t) {
var get_transform_matrix = function (elem) {
// Returns the first translate or transform matrix or makes one
var transform = null;
for (var i = 0; i < elem.transform.baseVal.numberOfItems; ++i) {
var baseVal = elem.transform.baseVal[i];
// quick tests showed that even if one changes only the fields e and f or uses createSVGTransformFromMatrix
// the brower may add a SVG_TRANSFORM_MATRIX instead of a SVG_TRANSFORM_TRANSLATE
if (baseVal.type === SVGTransform.SVG_TRANSFORM_MATRIX) {
transform = baseVal;
break;
}
}
if (transform == null) {
transform = elem.transform.baseVal.createSVGTransformFromMatrix(Tools.svg.createSVGMatrix());
elem.transform.baseVal.appendItem(transform);
}
return transform.matrix;
}

var transformRelative = function (m,t) {
return [
m.a*t[0]+m.c*t[1],
m.b*t[0]+m.d*t[1]
]
}

var transformAbsolute = function (m,t) {
return [
m.a*t[0]+m.c*t[1]+m.e,
m.b*t[0]+m.d*t[1]+m.f
]
}

SVGGraphicsElement.prototype.transformedBBox = function (scale=1) {
bbox = this.getBBox();
tmatrix = this.getCTM();
tmatrix = get_transform_matrix(this);
tmatrix.e /= scale;
tmatrix.f /= scale;
return {
r: [bbox.x + tmatrix.e/scale, bbox.y + tmatrix.f/scale],
a: applyTransform(tmatrix,[bbox.width/scale,0]),
b: applyTransform(tmatrix,[0,bbox.height/scale])
r: transformAbsolute(tmatrix,[bbox.x/scale,bbox.y/scale]),
a: transformRelative(tmatrix,[bbox.width/scale,0]),
b: transformRelative(tmatrix,[0,bbox.height/scale])
}
}

Expand All @@ -52,15 +80,17 @@ if (!SVGGraphicsElement.prototype.transformedBBox || !SVGGraphicsElement.prototy
width: this.width.baseVal.value,
height: this.height.baseVal.value
};
tmatrix = this.getCTM();
tmatrix = get_transform_matrix(this);
tmatrix.e /= scale;
tmatrix.f /= scale;
return {
r: [bbox.x + tmatrix.e/scale, bbox.y + tmatrix.f/scale],
a: applyTransform(tmatrix,[bbox.width/scale,0]),
b: applyTransform(tmatrix,[0,bbox.height/scale])
r: transformAbsolute(tmatrix,[bbox.x/scale,bbox.y/scale]),
a: transformRelative(tmatrix,[bbox.width/scale,0]),
b: transformRelative(tmatrix,[0,bbox.height/scale])
}
}

let pointInTransformedBBox = function ([x,y],{r,a,b}) {
var pointInTransformedBBox = function ([x,y],{r,a,b}) {
var d = [x-r[0],y-r[1]];
var idet = (a[0]*b[1]-a[1]*b[0]);
var c1 = (d[0]*b[1]-d[1]*b[0]) / idet;
Expand All @@ -79,7 +109,9 @@ if (!SVGGraphicsElement.prototype.transformedBBox || !SVGGraphicsElement.prototy
[bbox_b.r[0] + bbox_b.b[0], bbox_b.r[1] + bbox_b.b[1]],
[bbox_b.r[0] + bbox_b.a[0] + bbox_b.b[0], bbox_b.r[1] + bbox_b.a[1] + bbox_b.b[1]]
]
return corners.every(corner=>pointInTransformedBBox(corner,bbox_a))
return corners.every(function(corner) {
return pointInTransformedBBox(corner, bbox_a);
})
}

SVGGraphicsElement.prototype.transformedBBoxIntersects= function (bbox) {
Expand Down
5 changes: 5 additions & 0 deletions client-data/tools/hand/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions client-data/tools/hand/duplicate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading