So this is what I’m following… I can select a point that already exists and show intent to place a new Segment. This action completes, however the p2 does not render indicating an issue with how this is handled.
If I select that same point on the initial segment and attempt to draw a new Segment again, an error is thrown this time for – this.p2.equals is not a function
#handleMouseDown
if (event.button == 0) { // left-click
if (this.hovered) {
this.#select(this.hovered);
this.dragging = true;
return;
}
this.graph.addPoint(this.mouse);
this.#select(this.mouse); //
this.hovered = this.mouse; //
}
If I comment out the two lines indicated by // then no Point or Segments are drawn, as expected… but also no errors either.
My thought was that the error has to come from this section of code as it initializes and finalizes the segments.
#select(point) {
console.log(point instanceof Point)
if (this.selected instanceof Point) {
this.graph.tryAddSegment(new Segment(this.selected, point));
}
this.selected = point;
}
So I move on to the next portion… this accurately determines if the mouse location has a point at that spot… however, no Point is drawn.
tryAddPoint(point) {
if (!this.containsPoint(point)) {
this.addPoint(point);
return true;
}
return false;
}
So I continue to the next portion of the call… at this time all I’ve been able to figure out is that the parameter “point” is an object, whose construct.name is string.
addPoint(point) {
if (point instanceof Point) {
this.points.push(point);
} else {
// console.error('Invalid object attempted to be added as a point:', point);
}
}
So … how do I ensure that each point is in fact an instance of Point, so as to clear the safeguard in addPoint?
Segment: equals: segment =>
Segment {p1: Point, p2: {…}}
p1: Point {x: 300, y: 200}
p2: {x: 425, y: 197}