xxxxxxxxxx
65
class Connection {
constructor(cell1, cell2,weighted=false,weight=null) {
this.cell1 = cell1;
this.cell2 = cell2;
this.weight=weight;
this.flags = {
hover : false,
dragging : false,
highlighted:false,
weighted: weighted,
};
}
render() {
this.render_line();
}
render_line() {
stroke(0);
strokeWeight(2);
if (this.flags.hover) {
stroke(200, 0, 0);
strokeWeight(3);
}
if(this.flags.highlighted){
stroke(30,144,255);
strokeWeight(3);
}
if (this.flags.dragging) {
fill(100, 255, 255);
}
if(this.flags.weighted){
let d = int(dist(this.cell1.x, this.cell1.y, this.cell2.y, this.cell2.y));
this.weight=d;
push();
translate((this.cell1.x + this.cell2.x) / 2, (this.cell1.y + this.cell2.y) / 2);
rotate(atan2(this.cell2.y - this.cell1.y, this.cell2.x - this.cell1.x));
textSize(14);
text(nfc(d, 0), +5, -5);
pop();
}
line(this.cell1.x, this.cell1.y, this.cell2.x, this.cell2.y);
}
isInside(x, y) {
const d1 = dist(this.cell1.x, this.cell1.y, x, y);
const d2 = dist(this.cell2.x, this.cell2.y, x, y);
if (d1 <= this.cell1.radius || d2 <= this.cell2.radius) return false;
const length = dist(this.cell1.x, this.cell1.y, this.cell2.x, this.cell2.y);
const cond1 = (d1 + d2)-0.5 <= length;
const cond2 = (d1 + d2)+0.5 >= length;
return cond1 && cond2;
}
}