This is a project from my career where one of my colleagues promised a client that we could calculate the area of polygons in an image using our marker tool in an AI application. The idea was that the client would annotate the image with category polygons, and we would show how much of the image is covered. Unfortunately, the problem turned out to involve university-level mathematics, like integrals, which I wasn't equipped to implement. My colleague had described it as an “easy peasy” task. Since it needed to run on the client side, I tried to find a JavaScript library — but found nothing. After a few minutes of desperation, I invented a basic heuristic algorithm, which I later named the Lehoczky heuristic algorithm .

But I wasn’t satisfied with the results and knew I could implement a more precise method. Eventually, I discovered the Shoelace formula , which can calculate the area of any polygon. However, the main challenge was handling intersecting polygons. So, I designed a group of algorithms to merge polygons into one. These also handle gaps and work regardless of whether the polygons are drawn clockwise or counterclockwise. This method can merge almost any group of polygons with minimal deviation. I named it the Lehoczky merging polygon algorithm .