// Generated by gmmproc 2.89.0 -- DO NOT MODIFY!


#include <glibmm.h>

#include <gskmm/path.h>
#include <gskmm/private/path_p.h>


/* Copyright (C) 2026 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#include <gskmm/stroke.h>

namespace
{
extern "C"
{
// Why static? Because non-static functions with C linkage get external linkage,
// even if they are defined in an anonymous namespace.
static gboolean Path_foreach_callback(GskPathOperation op, const graphene_point_t* pts,
  gsize n_pts, float weight, gpointer user_data)
{
  auto slot = static_cast<Gsk::Path::SlotForeach*>(user_data);
  std::vector<Gdk::Graphene::Point> cpp_pts;
  for (auto pt = pts; pt < pts+n_pts; ++pt)
    cpp_pts.emplace_back(const_cast<graphene_point_t*>(pt), true);

  return (*slot)(static_cast<Gsk::Path::Operation>(op), cpp_pts, weight);
}

static gboolean Path_intersection_callback(GskPath* path1, const GskPathPoint* point1,
  GskPath* path2, const GskPathPoint* point2, GskPathIntersection kind, gpointer user_data)
{
  auto slot = static_cast<Gsk::Path::SlotIntersection*>(user_data);
  auto cpp_path1 = Glib::wrap(path1, true);
  auto cpp_point1 = Glib::wrap(point1);
  auto cpp_path2 = Glib::wrap(path2, true);
  auto cpp_point2 = Glib::wrap(point2);

  return (*slot)(cpp_path1, cpp_point1, cpp_path2, cpp_point2,
    static_cast<Gsk::Path::Intersection>(kind));
}

} // extern "C"
} // anonymous namespace

namespace Gsk
{
std::optional<Gdk::Graphene::Rect> Path::get_bounds() const
{
  Gdk::Graphene::Rect bounds(0.0, 0.0, 0.0, 0.0);
  const bool result = gsk_path_get_bounds(const_cast<GskPath*>(gobj()), bounds.gobj());
  if (!result)
    return {};
  return bounds;
}

std::optional<Gdk::Graphene::Rect> Path::get_tight_bounds() const
{
  Gdk::Graphene::Rect bounds(0.0, 0.0, 0.0, 0.0);
  const bool result = gsk_path_get_tight_bounds(const_cast<GskPath*>(gobj()), bounds.gobj());
  if (!result)
    return {};
  return bounds;
}

std::optional<Gdk::Graphene::Rect> Path::get_stroke_bounds(const Stroke& stroke) const
{
  Gdk::Graphene::Rect bounds(0.0, 0.0, 0.0, 0.0);
  const bool result = gsk_path_get_stroke_bounds(const_cast<GskPath*>(gobj()),
    stroke.gobj(), bounds.gobj());
  if (!result)
    return {};
  return bounds;
}

std::optional<PathPoint> Path::get_start_point() const
{
  PathPoint point;
  const bool result = gsk_path_get_start_point(const_cast<GskPath*>(gobj()), point.gobj());
  if (!result)
    return {};
  return point;
}

std::optional<PathPoint> Path::get_end_point() const
{
  PathPoint result;
  const bool success = gsk_path_get_end_point(const_cast<GskPath*>(gobj()), result.gobj());
  if (!success)
    return {};
  return result;
}

std::optional<std::pair<PathPoint,float>> Path::get_closest_point(
  const Gdk::Graphene::Point& point, float threshold) const
{
  PathPoint result;
  float distance = 0.0;
  const bool success = gsk_path_get_closest_point(const_cast<GskPath*>(gobj()),
    point.gobj(), threshold, result.gobj(), &distance);
  if (!success)
    return {};
  return std::pair<PathPoint,float>{result, distance};
}

} // namespace Gsk

namespace
{
} // anonymous namespace

// static
GType Glib::Value<Gsk::Path::ForeachFlags>::value_type()
{
  return gsk_path_foreach_flags_get_type();
}

// static
GType Glib::Value<Gsk::Path::Intersection>::value_type()
{
  return gsk_path_intersection_get_type();
}

// static
GType Glib::Value<Gsk::Path::Operation>::value_type()
{
  return gsk_path_operation_get_type();
}


/* Why reinterpret_cast<Path*>(gobject) is needed:
 *
 * A Path instance is in fact always a GskPath instance.
 * Unfortunately, GskPath cannot be a member of Path,
 * because it is an opaque struct.  Also, the C interface does not provide
 * any hooks to install a destroy notification handler, thus we cannot
 * wrap it dynamically either.
 *
 * The cast works because Path does not have any member data, and
 * it is impossible to derive from it.  This is ensured by using final on the
 * class and by using = delete on the default constructor.
 */

namespace Glib
{

Glib::RefPtr<Gsk::Path> wrap(GskPath* object, bool take_copy)
{
  if(take_copy && object)
    gsk_path_ref(object);

  // See the comment at the top of this file, if you want to know why the cast works.
  return Glib::make_refptr_for_instance<Gsk::Path>(reinterpret_cast<Gsk::Path*>(object));
}

} // namespace Glib


namespace Gsk
{

void Path::reference() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  gsk_path_ref(reinterpret_cast<GskPath*>(const_cast<Path*>(this)));
}

void Path::unreference() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  gsk_path_unref(reinterpret_cast<GskPath*>(const_cast<Path*>(this)));
}

GskPath* Path::gobj()
{
  // See the comment at the top of this file, if you want to know why the cast works.
  return reinterpret_cast<GskPath*>(this);
}

const GskPath* Path::gobj() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  return reinterpret_cast<const GskPath*>(this);
}

GskPath* Path::gobj_copy() const
{
  // See the comment at the top of this file, if you want to know why the cast works.
  const auto gobject = reinterpret_cast<GskPath*>(const_cast<Path*>(this));
  gsk_path_ref(gobject);
  return gobject;
}


Glib::ustring Path::to_string() const
{
  return Glib::convert_return_gchar_ptr_to_ustring(gsk_path_to_string(const_cast<GskPath*>(gobj())));
}

Glib::RefPtr<Path> Path::parse(const Glib::ustring& string)
{
  return Glib::wrap(gsk_path_parse(string.c_str()));
}

void Path::to_cairo(const ::Cairo::RefPtr< ::Cairo::Context>& cr) const
{
  gsk_path_to_cairo(const_cast<GskPath*>(gobj()), ((cr) ? (cr)->cobj() : nullptr));
}

bool Path::is_empty() const
{
  return gsk_path_is_empty(const_cast<GskPath*>(gobj()));
}

bool Path::is_closed() const
{
  return gsk_path_is_closed(const_cast<GskPath*>(gobj()));
}

bool Path::in_fill(const Gdk::Graphene::Point& point, FillRule fill_rule) const
{
  return gsk_path_in_fill(const_cast<GskPath*>(gobj()), (point).gobj(), static_cast<GskFillRule>(fill_rule));
}

bool Path::get_next(PathPoint& point) const
{
  return gsk_path_get_next(const_cast<GskPath*>(gobj()), (point).gobj());
}

bool Path::get_previous(PathPoint& point) const
{
  return gsk_path_get_previous(const_cast<GskPath*>(gobj()), (point).gobj());
}

bool Path::foreach(ForeachFlags flags, const SlotForeach& slot)
{
  // Use the original slot (not a copy).
  auto slot_copy = const_cast<SlotForeach*>(&slot);

  return gsk_path_foreach(gobj(), static_cast<GskPathForeachFlags>(flags), &Path_foreach_callback, slot_copy);
}

bool Path::equal(const Glib::RefPtr<const Path>& path2) const
{
  return gsk_path_equal(const_cast<GskPath*>(gobj()), Glib::unwrap(path2));
}

bool Path::foreach_intersection(const Glib::RefPtr<const Path>& path2, const SlotIntersection& slot)
{
  // Use the original slot (not a copy).
  auto slot_copy = const_cast<SlotIntersection*>(&slot);

  return gsk_path_foreach_intersection(gobj(), const_cast<GskPath*>(Glib::unwrap(path2)), &Path_intersection_callback, slot_copy);
}


} // namespace Gsk


