little cleanup

This commit is contained in:
Ruben van de Ven 2020-12-17 12:12:37 +01:00
parent 5839059fd8
commit a56fac5bfd
2 changed files with 3 additions and 16 deletions

View file

@ -30,12 +30,6 @@ export function init(svgEl, crosshairXEl, crosshairYEl) {
let shapeEl = document.createElementNS('http://www.w3.org/2000/svg', 'path');
shapeEl.classList.add('rect');
let p1 = { 'x': mousedownEv.clientX - rect.left, 'y': mousedownEv.clientY - rect.top }
// shapeEl.setAttribute('x', p1.x);
// shapeEl.setAttribute('y', p1.y);
// shapeEl.setAttribute('width', 0);
// shapeEl.setAttribute('height', 0);
let d = getPathShapeBetweenPoints(p1, p1, segmentCount);
svgEl.appendChild(shapeEl);
shapeEl.setAttribute('d', d);

View file

@ -2,13 +2,7 @@
function getPathShapeBetweenPoints(p1, p2, corners) {
let d = `M ${p1.x},${p1.y} L `;
if(corners == 4){
// draw inbetween p1 & p2.
let minx = Math.min(p1.x, p2.x);
let miny = Math.min(p1.y, p2.y);
let maxx = Math.max(p1.x, p2.x);
let maxy = Math.max(p1.y, p2.y);
d += ` ${p1.x},${p2.y} ${p2.x},${p2.y} ${p2.x},${p1.y} ${p1.x},${p1.y} `;
}
else{
@ -19,7 +13,8 @@ function getPathShapeBetweenPoints(p1, p2, corners) {
const length = Math.sqrt(Math.pow(p1.x-p2.x,2)+ Math.pow(p1.y - p2.y, 2));
const segmentAngle = Math.PI * 2 / corners;
// we don't want
// TODO: can we find a way to draw not from the first 3 segments, but have the
// cursor span as many segment as possible
// const segmentsAngle = Math.floor(180/segmentAngle) * segmentAngle;
const radius = (length*.5)/Math.sin(segmentAngle);
@ -38,9 +33,7 @@ function getPathShapeBetweenPoints(p1, p2, corners) {
let startRot = Math.asin(sx / radius);
if(sy>0){startRot = -1 * startRot + Math.PI;}
// console.log(sx, radius, startRot);
// animI+= .1;
// console.log(sx, sy, startRot);
for (let a = 0; a < Math.PI*2; a += segmentAngle) {
let x = radius * Math.sin(a-startRot) + cx;
let y = radius * Math.cos(a-startRot) + cy;