Can we assign Rect to a Part for its placement and Size

Hi i am computing intersection of parts and want to highlight the area of intersection. For that i want to create a node at the point of intersection which will highlight the area. Since intersectRect gives Rect in return can i directly assign it a node which will be used to highlight that area.

I am using following code for getting the intersect and setting the node but i want to give it the dimensions of rect.

var r = node.actualBounds.copy();
var intersect = r.intersectRect(otherNode.actualBounds.copy());
var model = diagram.model;
var nodeData = {loc: go.Point.stringify(intersect.center), color:"lightgreen" };
model.addNodeData(nodeData);

it is also not resulting the added node in exact center of the intersection.

That depends on the template you are using for showing those intersections. Since you have not set the category of the model data, the diagram will use the same template being used for all of your other node data. I suggest that you define a template for these intersections. Maybe:

myDiagram.nodeTemplateMap.add("Intersection",
  $(go.Part,
    new go.Binding("position", "pos", go.Point.parse),
    new go.Binding("desiredSize", "size", go.Size.parse),
    new go.Binding("background", "color")
  ));

And the data would need to include { category: "Intersection", size:"..." }.

This design assumes that you want those Intersection objects in your model. Is that actually desired in your case? Perhaps those intersections are really meant to be temporary and are not meant to be saved in the model. If that is the case, no such data should be added to the model and there is no reason to have that template.

Yes you are right it only needs to be added temporarily will need to remove it once the node is deselected.
Do we have deselect event?

In a template, set https://gojs.net/latest/api/symbols/Part.html#selectionChanged to be called whenever Part.isSelected changes value.

For a diagram, https://gojs.net/latest/intro/events.html#ChangedSelection is raised after a command or tool has changed the Diagram.selection collection.

For temporary Parts, I would not bother with changing the model and using templates. Just create the Parts that you want and call Diagram.add and remove, just as some tools do.

Ok, will try this out.