This examples extends the previous one by including two viewports:
The algorithm for calculating the intersect area between two rectangles has been taken from this Math Stackexchange discussion.
xxxxxxxxxx
<html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-selection-multi.v0.4.min.js"></script>
<link rel="stylesheet" href="index.css">
<title>Main object recognizer</title>
</head>
<body>
<svg></svg>
<script src="index.js"></script>
</body>
</html>
https://d3js.org/d3.v4.min.js
https://d3js.org/d3-selection-multi.v0.4.min.js