Stackoverflow

How to get intersection area of two paths using Raphael

JavaScript

/**
 * @tag Stackoverflow
 */
var p1 = "M100 100 L100 400 L400 400 L400 100 Z",
    p2 = "M200 200 L200 500 L500 500 L500 200 Z";
   var  p3 = "M 200 237 L 337 237 L 337 236 L 337 327 L 337 327 L 474 327",
    p4 = "M 313 204 L 313 311 L 313 311 L 313 311 L 313 312 L 313 418";
var paper = new Raphael(0, 0, 800, 600);

paper.path(p1).attr({fill : "red", opacity : 1});
paper.path(p2).attr({fill : "blue", opacity : 0.5});

var points = Raphael.pathIntersection(p3, p4);
var w = points[1].x-points[0].x,
    h = points[0].y-points[1].y;
var group = paper.set();
group.push(paper.rect(510, 100, w, h).attr({fill: "yellow"}));
group.push(paper.text(610, 150, "The intersection area\nis drawn over here.\n \nWidth: " + w + "\nHeight: " + h));