// Copyright (c) 2012-2013, IGN France.
// Copyright (c) 2012-2024, Oslandia.
// Copyright (c) 2024-2026, SFCGAL team.
// SPDX-License-Identifier: LGPL-2.0-or-later

#include "SFCGAL/detail/polygonSetToMultiPolygon.h"

#include <CGAL/Polygon_with_holes_2.h>

#include <list>

namespace SFCGAL::detail {

auto
polygonSetToMultiPolygon(const CGAL::Polygon_set_2<Kernel> &polygonSet)
    -> std::unique_ptr<MultiPolygon>
{
  std::list<Polygon_with_holes_2> res;
  polygonSet.polygons_with_holes(std::back_inserter(res));

  auto result = std::make_unique<MultiPolygon>();

  for (auto &re : res) {
    result->addGeometry(std::make_unique<Polygon>(re));
  }

  return result;
}

} // namespace SFCGAL::detail
