Geo path relative coordinates

Hi,

End goal don’t want to create a part using polygon drawing tool which can overlap on each other hence on creation I want to check if the bounds intersect with any other existing part.

Currently when I am getting a geo for Polygon Drawing it is always giving geo path in respect to current rectangle selection and not in respect to its placement in diagram. Hence it always has 0,0 starting coordinates. I want to calculate the bounds of the part that will be created how can I do that.
Currently I have modified the polygon drawing tool to throw part created event so that I can get the part created so I can get it’s detail as it doesn’t has an override like dragCreating tool for insert part which gives the bound of the part being created.

And if I get the node using the getNodeForKey at this time the part is not completed and it doesn’t give correct actualBounds.

It seems to me that you want to modify the PolygonDrawingTool.doMouseDown and doMouseMove methods to make sure the Point being used, this.diagram.lastInput.documentPoint, is not in any existing Part. Is that correct?

So I suppose you could ignore such mouse events by making them no-ops if this.diagram.findPartAt(this.diagram.lastInput.documentPoint) !== null.

Not just the point but the line drawn by that points also because there can be scenarios where point is outside but line which will combine those points will be overlapping a part.

Then you will also have to see if that line segment intersects with any segment of any shape. You can call https://gojs.net/latest/api/symbols/Diagram.html#findPartsIn to restrict the number of Parts/Shapes to check.

But this is restricting the diagram on basis of rectangle but I want to achieve it for a polygon and not the rect which is containing it.
Can we do it on the basis of the points some how? And how to get the points of a part which is being used to create it.

What I mentioned above does not check for the intersection of rectangles, but the intersection of polygonal edges.

I’m assuming that none of the existing parts will be moving about or changing size or geometry during the drawing tool’s operation. Thus it should suffice that the tool check each segment of the new part as it is drawn.

But it takes rect in the parameter.

You mean Diagram.findPartsIn? Yes, that is an optimization to reduce the number of Parts whose geometries you need to check for intersection. There’s no point in checking the edges of polygons that are far away from where the user is drawing.

How can I get the points that make a part?

Parts do not have points. Shape.geometry is a Geometry that does have points. When doing line segment intersection tests, you’ll find it easier to shift the test points into the coordinate system of the geometry, rather than the other way around.

But that geometry always starts from 0,0 and not the actual coordinates it has on diagram. How can I transform it into diagram relative geo.

Also since part is not fully created at the time event is raised the actualBounds are incorrect and most of the time it has Nan values. Is there any way I can get actual bounds so that I can get the rect for findPartsIn.
image

I guess I’m not being clear. The question is whether or not a particular line segment, a proposed straight line between two points in document coordinates, intersects with any edge of any polygon of any existing Part.

So the calculation does not involve the currently-being-drawn temporary Part.

Call those two points p1 and p2. You can find all of the Parts that might intersect with the straight line between p1 and p2 with this expression: myDiagram.findPartsIn(new go.Rect(p1, p2), true).

Then for each of those Parts, if it is not the temporary Part being drawn, you get its Shape’s Geometry. For each such Geometry, you iterate over the PathSegments of its PathFigures to get all of the edges of the geometry. (Don’t forget any closing segments.) Convert the p1 and p2 points to the local coordinate system of the geometry by calling https://gojs.net/latest/api/symbols/GraphObject.html#getLocalPoint. Then you can perform the quick check to see if the segment intersects with each segment of the polygon.

A post was split to a new topic: Custom Diagram Event

Hi Walter I have overridden the add point method and tried the myDiagram.findPartsIn(new go.Rect(p1, p2), true) but it is not giving me any parts that are being crossed by the 2 point line.

…Correction it’s working.