/* LinkTypeRounded.c generated by valac 0.56.19, the Vala compiler
 * generated from LinkTypeRounded.vala, do not modify */

/*
* Copyright (c) 2018-2026 (https://github.com/phase1geo/Minder)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <cairo-gobject.h>
#include <float.h>
#include <math.h>
#include <glib/gi18n-lib.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_LINK_TYPE (link_type_get_type ())
#define LINK_TYPE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LINK_TYPE, LinkType))
#define IS_LINK_TYPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LINK_TYPE))
#define LINK_TYPE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_LINK_TYPE, LinkTypeIface))

typedef struct _LinkType LinkType;
typedef struct _LinkTypeIface LinkTypeIface;

#define TYPE_NODE (node_get_type ())
#define NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NODE, Node))
#define NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NODE, NodeClass))
#define IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NODE))
#define IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NODE))
#define NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NODE, NodeClass))

typedef struct _Node Node;
typedef struct _NodeClass NodeClass;

#define TYPE_LINK_TYPE_ROUNDED (link_type_rounded_get_type ())
#define LINK_TYPE_ROUNDED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_LINK_TYPE_ROUNDED, LinkTypeRounded))
#define LINK_TYPE_ROUNDED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_LINK_TYPE_ROUNDED, LinkTypeRoundedClass))
#define IS_LINK_TYPE_ROUNDED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_LINK_TYPE_ROUNDED))
#define IS_LINK_TYPE_ROUNDED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_LINK_TYPE_ROUNDED))
#define LINK_TYPE_ROUNDED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_LINK_TYPE_ROUNDED, LinkTypeRoundedClass))

typedef struct _LinkTypeRounded LinkTypeRounded;
typedef struct _LinkTypeRoundedClass LinkTypeRoundedClass;
typedef struct _LinkTypeRoundedPrivate LinkTypeRoundedPrivate;
enum  {
	LINK_TYPE_ROUNDED_0_PROPERTY,
	LINK_TYPE_ROUNDED_NUM_PROPERTIES
};
static GParamSpec* link_type_rounded_properties[LINK_TYPE_ROUNDED_NUM_PROPERTIES];
typedef enum  {
	NODE_SIDE_LEFT = 1,
	NODE_SIDE_TOP = 2,
	NODE_SIDE_RIGHT = 4,
	NODE_SIDE_BOTTOM = 8
} NodeSide;

#define TYPE_NODE_SIDE (node_side_get_type ())

#define TYPE_STYLE (style_get_type ())
#define STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_STYLE, Style))
#define STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_STYLE, StyleClass))
#define IS_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_STYLE))
#define IS_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_STYLE))
#define STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_STYLE, StyleClass))

typedef struct _Style Style;
typedef struct _StyleClass StyleClass;
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
#define _style_unref0(var) ((var == NULL) ? NULL : (var = (style_unref (var), NULL)))

struct _LinkTypeIface {
	GTypeInterface parent_iface;
	gchar* (*name) (LinkType* self);
	gchar* (*display_name) (LinkType* self);
	gchar* (*light_icon_name) (LinkType* self);
	gchar* (*dark_icon_name) (LinkType* self);
	void (*draw) (LinkType* self, cairo_t* ctx, Node* from_node, Node* to_node, gdouble from_x, gdouble from_y, gdouble to_x, gdouble to_y, gdouble* fx, gdouble* fy, gdouble* tx, gdouble* ty);
};

struct _LinkTypeRounded {
	GObject parent_instance;
	LinkTypeRoundedPrivate * priv;
};

struct _LinkTypeRoundedClass {
	GObjectClass parent_class;
};

static gpointer link_type_rounded_parent_class = NULL;
static LinkTypeIface * link_type_rounded_link_type_parent_iface = NULL;

VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
VALA_EXTERN GType link_type_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LinkType, g_object_unref)
VALA_EXTERN GType link_type_rounded_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (LinkTypeRounded, g_object_unref)
VALA_EXTERN LinkTypeRounded* link_type_rounded_new (void);
VALA_EXTERN LinkTypeRounded* link_type_rounded_construct (GType object_type);
static gchar* link_type_rounded_real_name (LinkType* base);
static gchar* link_type_rounded_real_display_name (LinkType* base);
static gchar* link_type_rounded_real_light_icon_name (LinkType* base);
static gchar* link_type_rounded_real_dark_icon_name (LinkType* base);
VALA_EXTERN GType node_side_get_type (void) G_GNUC_CONST ;
static void link_type_rounded_adjust_mid (LinkTypeRounded* self,
                                   Node* parent,
                                   NodeSide child_side,
                                   gdouble from_a,
                                   gdouble to_a,
                                   gdouble from_b,
                                   gdouble to_b,
                                   gdouble radius,
                                   gdouble* mid,
                                   gdouble* rnd_a,
                                   gdouble* rnd_b);
VALA_EXTERN gdouble link_type_adjust_mid_by (LinkType* self,
                                 Node* parent,
                                 NodeSide child_side);
static void link_type_rounded_real_draw (LinkType* base,
                                  cairo_t* ctx,
                                  Node* from_node,
                                  Node* to_node,
                                  gdouble from_x,
                                  gdouble from_y,
                                  gdouble to_x,
                                  gdouble to_y,
                                  gdouble* tailx,
                                  gdouble* taily,
                                  gdouble* tipx,
                                  gdouble* tipy);
VALA_EXTERN NodeSide node_get_side (Node* self);
VALA_EXTERN gboolean node_side_horizontal (NodeSide self);
VALA_EXTERN gpointer style_ref (gpointer instance);
VALA_EXTERN void style_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_style (const gchar* name,
                              const gchar* nick,
                              const gchar* blurb,
                              GType object_type,
                              GParamFlags flags);
VALA_EXTERN void value_set_style (GValue* value,
                      gpointer v_object);
VALA_EXTERN void value_take_style (GValue* value,
                       gpointer v_object);
VALA_EXTERN gpointer value_get_style (const GValue* value);
VALA_EXTERN GType style_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Style, style_unref)
VALA_EXTERN Style* node_get_style (Node* self);
VALA_EXTERN gdouble link_type_adjust_a (LinkType* self,
                            Style* style);
VALA_EXTERN gdouble link_type_adjust_tip (LinkType* self,
                              Style* style);
VALA_EXTERN gint* style_get_branch_radius (Style* self);
static gint* _int_dup (gint* self);
VALA_EXTERN gchar* link_type_name (LinkType* self);
VALA_EXTERN gchar* link_type_display_name (LinkType* self);
VALA_EXTERN gchar* link_type_light_icon_name (LinkType* self);
VALA_EXTERN gchar* link_type_dark_icon_name (LinkType* self);
VALA_EXTERN void link_type_draw (LinkType* self,
                     cairo_t* ctx,
                     Node* from_node,
                     Node* to_node,
                     gdouble from_x,
                     gdouble from_y,
                     gdouble to_x,
                     gdouble to_y,
                     gdouble* fx,
                     gdouble* fy,
                     gdouble* tx,
                     gdouble* ty);
static GType link_type_rounded_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

LinkTypeRounded*
link_type_rounded_construct (GType object_type)
{
	LinkTypeRounded * self = NULL;
	self = (LinkTypeRounded*) g_object_new (object_type, NULL);
	return self;
}

LinkTypeRounded*
link_type_rounded_new (void)
{
	return link_type_rounded_construct (TYPE_LINK_TYPE_ROUNDED);
}

static gchar*
link_type_rounded_real_name (LinkType* base)
{
	LinkTypeRounded * self;
	gchar* _tmp0_;
	gchar* result;
	self = (LinkTypeRounded*) base;
	_tmp0_ = g_strdup ("rounded");
	result = _tmp0_;
	return result;
}

static gchar*
link_type_rounded_real_display_name (LinkType* base)
{
	LinkTypeRounded * self;
	gchar* _tmp0_;
	gchar* result;
	self = (LinkTypeRounded*) base;
	_tmp0_ = g_strdup (_ ("Rounded"));
	result = _tmp0_;
	return result;
}

static gchar*
link_type_rounded_real_light_icon_name (LinkType* base)
{
	LinkTypeRounded * self;
	gchar* _tmp0_;
	gchar* result;
	self = (LinkTypeRounded*) base;
	_tmp0_ = g_strdup ("minder-link-rounded-light-symbolic");
	result = _tmp0_;
	return result;
}

static gchar*
link_type_rounded_real_dark_icon_name (LinkType* base)
{
	LinkTypeRounded * self;
	gchar* _tmp0_;
	gchar* result;
	self = (LinkTypeRounded*) base;
	_tmp0_ = g_strdup ("minder-link-rounded-dark-symbolic");
	result = _tmp0_;
	return result;
}

static void
link_type_rounded_adjust_mid (LinkTypeRounded* self,
                              Node* parent,
                              NodeSide child_side,
                              gdouble from_a,
                              gdouble to_a,
                              gdouble from_b,
                              gdouble to_b,
                              gdouble radius,
                              gdouble* mid,
                              gdouble* rnd_a,
                              gdouble* rnd_b)
{
	gdouble _vala_mid = 0.0;
	gdouble _vala_rnd_a = 0.0;
	gdouble _vala_rnd_b = 0.0;
	gdouble _tmp0_ = 0.0;
	gdouble _tmp1_ = 0.0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (parent != NULL);
	_vala_mid = ((from_a + to_a) / 2) + link_type_adjust_mid_by ((LinkType*) self, parent, child_side);
	if (from_a < to_a) {
		_tmp0_ = _vala_mid + radius;
	} else {
		_tmp0_ = _vala_mid - radius;
	}
	_vala_rnd_a = _tmp0_;
	if (from_b < to_b) {
		gdouble _tmp2_ = 0.0;
		if ((to_b - radius) < from_b) {
			_tmp2_ = from_b;
		} else {
			_tmp2_ = to_b - radius;
		}
		_tmp1_ = _tmp2_;
	} else {
		gdouble _tmp3_ = 0.0;
		if ((to_b + radius) > from_b) {
			_tmp3_ = from_b;
		} else {
			_tmp3_ = to_b + radius;
		}
		_tmp1_ = _tmp3_;
	}
	_vala_rnd_b = _tmp1_;
	if (mid) {
		*mid = _vala_mid;
	}
	if (rnd_a) {
		*rnd_a = _vala_rnd_a;
	}
	if (rnd_b) {
		*rnd_b = _vala_rnd_b;
	}
}

static gpointer
_style_ref0 (gpointer self)
{
	return self ? style_ref (self) : NULL;
}

static gint*
_int_dup (gint* self)
{
	gint* dup;
	dup = g_new0 (gint, 1);
	memcpy (dup, self, sizeof (gint));
	return dup;
}

static gpointer
__int_dup0 (gpointer self)
{
	return self ? _int_dup (self) : NULL;
}

static void
link_type_rounded_real_draw (LinkType* base,
                             cairo_t* ctx,
                             Node* from_node,
                             Node* to_node,
                             gdouble from_x,
                             gdouble from_y,
                             gdouble to_x,
                             gdouble to_y,
                             gdouble* tailx,
                             gdouble* taily,
                             gdouble* tipx,
                             gdouble* tipy)
{
	LinkTypeRounded * self;
	gdouble _vala_tailx = 0.0;
	gdouble _vala_taily = 0.0;
	gdouble _vala_tipx = 0.0;
	gdouble _vala_tipy = 0.0;
	NodeSide side = 0;
	NodeSide _tmp0_;
	NodeSide _tmp1_;
	gboolean horizontal = FALSE;
	Style* fstyle = NULL;
	Style* _tmp2_;
	Style* _tmp3_;
	Style* _tmp4_;
	Style* tstyle = NULL;
	Style* _tmp5_;
	Style* _tmp6_;
	Style* _tmp7_;
	gdouble adj_a = 0.0;
	Style* _tmp8_;
	gdouble adj_t = 0.0;
	Style* _tmp9_;
	gint* radius = NULL;
	Style* _tmp10_;
	Style* _tmp11_;
	gint* _tmp12_;
	gint* _tmp13_;
	gint* _tmp14_;
	self = (LinkTypeRounded*) base;
	g_return_if_fail (ctx != NULL);
	g_return_if_fail (from_node != NULL);
	g_return_if_fail (to_node != NULL);
	_tmp0_ = node_get_side (to_node);
	_tmp1_ = _tmp0_;
	side = _tmp1_;
	horizontal = node_side_horizontal (side);
	_tmp2_ = node_get_style (from_node);
	_tmp3_ = _tmp2_;
	_tmp4_ = _style_ref0 (_tmp3_);
	fstyle = _tmp4_;
	_tmp5_ = node_get_style (to_node);
	_tmp6_ = _tmp5_;
	_tmp7_ = _style_ref0 (_tmp6_);
	tstyle = _tmp7_;
	_tmp8_ = tstyle;
	adj_a = link_type_adjust_a ((LinkType*) self, _tmp8_);
	_tmp9_ = tstyle;
	adj_t = link_type_adjust_tip ((LinkType*) self, _tmp9_);
	_tmp10_ = node_get_style (from_node);
	_tmp11_ = _tmp10_;
	_tmp12_ = style_get_branch_radius (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = __int_dup0 (_tmp13_);
	radius = _tmp14_;
	_vala_tipy = (gdouble) 0;
	_vala_tipx = _vala_tipy;
	switch (side) {
		case NODE_SIDE_LEFT:
		{
			to_x = to_x + adj_a;
			_vala_tipx = to_x - adj_t;
			_vala_tipy = to_y;
			break;
		}
		case NODE_SIDE_RIGHT:
		{
			to_x = to_x - adj_a;
			_vala_tipx = to_x + adj_t;
			_vala_tipy = to_y;
			break;
		}
		case NODE_SIDE_TOP:
		{
			to_y = to_y + adj_a;
			_vala_tipy = to_y - adj_t;
			_vala_tipx = to_x;
			break;
		}
		case NODE_SIDE_BOTTOM:
		{
			to_y = to_y - adj_a;
			_vala_tipy = to_y + adj_t;
			_vala_tipx = to_x;
			break;
		}
		default:
		break;
	}
	cairo_move_to (ctx, from_x, from_y);
	if (horizontal) {
		gdouble mid_x = 0.0;
		gdouble rnd_x = 0.0;
		gdouble rnd_y = 0.0;
		gint* _tmp15_;
		gdouble _tmp16_ = 0.0;
		gdouble _tmp17_ = 0.0;
		gdouble _tmp18_ = 0.0;
		_tmp15_ = radius;
		link_type_rounded_adjust_mid (self, from_node, side, from_x, to_x, from_y, to_y, *_tmp15_, &_tmp16_, &_tmp17_, &_tmp18_);
		mid_x = _tmp16_;
		rnd_x = _tmp17_;
		rnd_y = _tmp18_;
		_vala_tailx = mid_x;
		_vala_taily = to_y;
		cairo_line_to (ctx, mid_x, from_y);
		cairo_line_to (ctx, mid_x, rnd_y);
		cairo_curve_to (ctx, mid_x, rnd_y, mid_x, to_y, rnd_x, to_y);
		cairo_line_to (ctx, to_x, to_y);
	} else {
		gdouble mid_y = 0.0;
		gdouble rnd_y = 0.0;
		gdouble rnd_x = 0.0;
		gint* _tmp19_;
		gdouble _tmp20_ = 0.0;
		gdouble _tmp21_ = 0.0;
		gdouble _tmp22_ = 0.0;
		_tmp19_ = radius;
		link_type_rounded_adjust_mid (self, from_node, side, from_y, to_y, from_x, to_x, *_tmp19_, &_tmp20_, &_tmp21_, &_tmp22_);
		mid_y = _tmp20_;
		rnd_y = _tmp21_;
		rnd_x = _tmp22_;
		_vala_tailx = to_x;
		_vala_taily = mid_y;
		cairo_line_to (ctx, from_x, mid_y);
		cairo_line_to (ctx, rnd_x, mid_y);
		cairo_curve_to (ctx, rnd_x, mid_y, to_x, mid_y, to_x, rnd_y);
		cairo_line_to (ctx, to_x, to_y);
	}
	cairo_stroke (ctx);
	_g_free0 (radius);
	_style_unref0 (tstyle);
	_style_unref0 (fstyle);
	if (tailx) {
		*tailx = _vala_tailx;
	}
	if (taily) {
		*taily = _vala_taily;
	}
	if (tipx) {
		*tipx = _vala_tipx;
	}
	if (tipy) {
		*tipy = _vala_tipy;
	}
}

static void
link_type_rounded_class_init (LinkTypeRoundedClass * klass,
                              gpointer klass_data)
{
	link_type_rounded_parent_class = g_type_class_peek_parent (klass);
}

static void
link_type_rounded_link_type_interface_init (LinkTypeIface * iface,
                                            gpointer iface_data)
{
	link_type_rounded_link_type_parent_iface = g_type_interface_peek_parent (iface);
	iface->name = (gchar* (*) (LinkType*)) link_type_rounded_real_name;
	iface->display_name = (gchar* (*) (LinkType*)) link_type_rounded_real_display_name;
	iface->light_icon_name = (gchar* (*) (LinkType*)) link_type_rounded_real_light_icon_name;
	iface->dark_icon_name = (gchar* (*) (LinkType*)) link_type_rounded_real_dark_icon_name;
	iface->draw = (void (*) (LinkType*, cairo_t*, Node*, Node*, gdouble, gdouble, gdouble, gdouble, gdouble*, gdouble*, gdouble*, gdouble*)) link_type_rounded_real_draw;
}

static void
link_type_rounded_instance_init (LinkTypeRounded * self,
                                 gpointer klass)
{
}

static GType
link_type_rounded_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (LinkTypeRoundedClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) link_type_rounded_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (LinkTypeRounded), 0, (GInstanceInitFunc) link_type_rounded_instance_init, NULL };
	static const GInterfaceInfo link_type_info = { (GInterfaceInitFunc) link_type_rounded_link_type_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType link_type_rounded_type_id;
	link_type_rounded_type_id = g_type_register_static (G_TYPE_OBJECT, "LinkTypeRounded", &g_define_type_info, 0);
	g_type_add_interface_static (link_type_rounded_type_id, TYPE_LINK_TYPE, &link_type_info);
	return link_type_rounded_type_id;
}

GType
link_type_rounded_get_type (void)
{
	static volatile gsize link_type_rounded_type_id__once = 0;
	if (g_once_init_enter (&link_type_rounded_type_id__once)) {
		GType link_type_rounded_type_id;
		link_type_rounded_type_id = link_type_rounded_get_type_once ();
		g_once_init_leave (&link_type_rounded_type_id__once, link_type_rounded_type_id);
	}
	return link_type_rounded_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

