/* AnimatorPositions.c generated by valac 0.56.19, the Vala compiler
 * generated from AnimatorPositions.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 <glib.h>
#include <float.h>
#include <math.h>
#include <string.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_ANIMATOR_POSITIONS (animator_positions_get_type ())
#define ANIMATOR_POSITIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_ANIMATOR_POSITIONS, AnimatorPositions))
#define ANIMATOR_POSITIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_ANIMATOR_POSITIONS, AnimatorPositionsClass))
#define IS_ANIMATOR_POSITIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_ANIMATOR_POSITIONS))
#define IS_ANIMATOR_POSITIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_ANIMATOR_POSITIONS))
#define ANIMATOR_POSITIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_ANIMATOR_POSITIONS, AnimatorPositionsClass))

typedef struct _AnimatorPositions AnimatorPositions;
typedef struct _AnimatorPositionsClass AnimatorPositionsClass;
typedef struct _AnimatorPositionsPrivate AnimatorPositionsPrivate;

#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;
enum  {
	ANIMATOR_POSITIONS_0_PROPERTY,
	ANIMATOR_POSITIONS_NUM_PROPERTIES
};
static GParamSpec* animator_positions_properties[ANIMATOR_POSITIONS_NUM_PROPERTIES];
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
typedef enum  {
	NODE_MODE_NONE = 0,
	NODE_MODE_CURRENT,
	NODE_MODE_SELECTED,
	NODE_MODE_EDITABLE,
	NODE_MODE_ATTACHABLE,
	NODE_MODE_DROPPABLE,
	NODE_MODE_HIGHLIGHTED
} NodeMode;

#define TYPE_NODE_MODE (node_mode_get_type ())

struct _AnimatorPositions {
	GObject parent_instance;
	AnimatorPositionsPrivate * priv;
};

struct _AnimatorPositionsClass {
	GObjectClass parent_class;
};

struct _AnimatorPositionsPrivate {
	GArray* _old_x;
	GArray* _old_y;
	GArray* _new_x;
	GArray* _new_y;
	GArray* _node;
};

static gint AnimatorPositions_private_offset;
static gpointer animator_positions_parent_class = NULL;

VALA_EXTERN GType animator_positions_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (AnimatorPositions, g_object_unref)
VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
VALA_EXTERN AnimatorPositions* animator_positions_new (GArray* nodes,
                                           gboolean exclude_selected);
VALA_EXTERN AnimatorPositions* animator_positions_construct (GType object_type,
                                                 GArray* nodes,
                                                 gboolean exclude_selected);
static void _g_free0_ (gpointer var);
static void _vala_gdouble_free_function_content_of (gpointer data);
static void _g_object_unref0_ (gpointer var);
static void _vala_Node_free_function_content_of (gpointer data);
static void animator_positions_gather_old_positions (AnimatorPositions* self,
                                              Node* n,
                                              gboolean exclude_selected);
static gboolean animator_positions_is_excluded (AnimatorPositions* self,
                                         Node* n,
                                         gboolean exclude_selected);
VALA_EXTERN GType node_mode_get_type (void) G_GNUC_CONST ;
VALA_EXTERN NodeMode node_get_mode (Node* self);
VALA_EXTERN gboolean node_mode_is_selected (NodeMode self);
VALA_EXTERN gdouble node_get_posx (Node* self);
static gdouble* _double_dup (gdouble* self);
VALA_EXTERN gdouble node_get_posy (Node* self);
VALA_EXTERN gboolean node_traversable (Node* self);
VALA_EXTERN GArray* node_children (Node* self);
VALA_EXTERN void animator_positions_gather_new_positions (AnimatorPositions* self);
VALA_EXTERN guint animator_positions_length (AnimatorPositions* self);
VALA_EXTERN gdouble animator_positions_old_x (AnimatorPositions* self,
                                  gint index);
VALA_EXTERN gdouble animator_positions_old_y (AnimatorPositions* self,
                                  gint index);
VALA_EXTERN gdouble animator_positions_new_x (AnimatorPositions* self,
                                  gint index);
VALA_EXTERN gdouble animator_positions_new_y (AnimatorPositions* self,
                                  gint index);
VALA_EXTERN Node* animator_positions_node (AnimatorPositions* self,
                               gint index);
static void animator_positions_finalize (GObject * obj);
static GType animator_positions_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
animator_positions_get_instance_private (AnimatorPositions* self)
{
	return G_STRUCT_MEMBER_P (self, AnimatorPositions_private_offset);
}

static void
_g_free0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_free (var), NULL));
}

static void
_vala_gdouble_free_function_content_of (gpointer data)
{
	gdouble* self;
	self = *((gdouble**) data);
	_g_free0_ (self);
}

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static void
_vala_Node_free_function_content_of (gpointer data)
{
	Node* self;
	self = *((Node**) data);
	_g_object_unref0_ (self);
}

AnimatorPositions*
animator_positions_construct (GType object_type,
                              GArray* nodes,
                              gboolean exclude_selected)
{
	AnimatorPositions * self = NULL;
	GArray* _tmp0_;
	GArray* _tmp1_;
	GArray* _tmp2_;
	GArray* _tmp3_;
	GArray* _tmp4_;
	g_return_val_if_fail (nodes != NULL, NULL);
	self = (AnimatorPositions*) g_object_new (object_type, NULL);
	_tmp0_ = g_array_new (TRUE, TRUE, sizeof (gdouble*));
	g_array_set_clear_func (_tmp0_, (GDestroyNotify) _vala_gdouble_free_function_content_of);
	_g_array_unref0 (self->priv->_old_x);
	self->priv->_old_x = _tmp0_;
	_tmp1_ = g_array_new (TRUE, TRUE, sizeof (gdouble*));
	g_array_set_clear_func (_tmp1_, (GDestroyNotify) _vala_gdouble_free_function_content_of);
	_g_array_unref0 (self->priv->_old_y);
	self->priv->_old_y = _tmp1_;
	_tmp2_ = g_array_new (TRUE, TRUE, sizeof (gdouble*));
	g_array_set_clear_func (_tmp2_, (GDestroyNotify) _vala_gdouble_free_function_content_of);
	_g_array_unref0 (self->priv->_new_x);
	self->priv->_new_x = _tmp2_;
	_tmp3_ = g_array_new (TRUE, TRUE, sizeof (gdouble*));
	g_array_set_clear_func (_tmp3_, (GDestroyNotify) _vala_gdouble_free_function_content_of);
	_g_array_unref0 (self->priv->_new_y);
	self->priv->_new_y = _tmp3_;
	_tmp4_ = g_array_new (TRUE, TRUE, sizeof (Node*));
	g_array_set_clear_func (_tmp4_, (GDestroyNotify) _vala_Node_free_function_content_of);
	_g_array_unref0 (self->priv->_node);
	self->priv->_node = _tmp4_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp5_ = FALSE;
			_tmp5_ = TRUE;
			while (TRUE) {
				Node* _tmp7_;
				if (!_tmp5_) {
					gint _tmp6_;
					_tmp6_ = i;
					i = _tmp6_ + 1;
				}
				_tmp5_ = FALSE;
				if (!(((guint) i) < nodes->len)) {
					break;
				}
				_tmp7_ = g_array_index (nodes, Node*, (guint) i);
				animator_positions_gather_old_positions (self, _tmp7_, exclude_selected);
			}
		}
	}
	return self;
}

AnimatorPositions*
animator_positions_new (GArray* nodes,
                        gboolean exclude_selected)
{
	return animator_positions_construct (TYPE_ANIMATOR_POSITIONS, nodes, exclude_selected);
}

static gboolean
animator_positions_is_excluded (AnimatorPositions* self,
                                Node* n,
                                gboolean exclude_selected)
{
	gboolean _tmp0_ = FALSE;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (n != NULL, FALSE);
	if (exclude_selected) {
		NodeMode _tmp1_;
		NodeMode _tmp2_;
		_tmp1_ = node_get_mode (n);
		_tmp2_ = _tmp1_;
		_tmp0_ = node_mode_is_selected (_tmp2_);
	} else {
		_tmp0_ = FALSE;
	}
	result = _tmp0_;
	return result;
}

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

static gpointer
__double_dup0 (gpointer self)
{
	return self ? _double_dup (self) : NULL;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
animator_positions_gather_old_positions (AnimatorPositions* self,
                                         Node* n,
                                         gboolean exclude_selected)
{
	gboolean excluded = FALSE;
	gboolean _tmp10_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (n != NULL);
	excluded = animator_positions_is_excluded (self, n, exclude_selected);
	if (!excluded) {
		GArray* _tmp0_;
		gdouble _tmp1_;
		gdouble _tmp2_;
		gdouble* _tmp3_;
		GArray* _tmp4_;
		gdouble _tmp5_;
		gdouble _tmp6_;
		gdouble* _tmp7_;
		GArray* _tmp8_;
		Node* _tmp9_;
		_tmp0_ = self->priv->_old_x;
		_tmp1_ = node_get_posx (n);
		_tmp2_ = _tmp1_;
		_tmp3_ = __double_dup0 (&_tmp2_);
		g_array_append_val (_tmp0_, _tmp3_);
		_tmp4_ = self->priv->_old_y;
		_tmp5_ = node_get_posy (n);
		_tmp6_ = _tmp5_;
		_tmp7_ = __double_dup0 (&_tmp6_);
		g_array_append_val (_tmp4_, _tmp7_);
		_tmp8_ = self->priv->_node;
		_tmp9_ = _g_object_ref0 (n);
		g_array_append_val (_tmp8_, _tmp9_);
	}
	if (node_traversable (n)) {
		gboolean _tmp11_ = FALSE;
		if (!excluded) {
			_tmp11_ = TRUE;
		} else {
			NodeMode _tmp12_;
			NodeMode _tmp13_;
			_tmp12_ = node_get_mode (n);
			_tmp13_ = _tmp12_;
			_tmp11_ = _tmp13_ == NODE_MODE_SELECTED;
		}
		_tmp10_ = _tmp11_;
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp14_ = FALSE;
				_tmp14_ = TRUE;
				while (TRUE) {
					GArray* _tmp16_;
					GArray* _tmp17_;
					gboolean _tmp18_;
					GArray* _tmp19_;
					GArray* _tmp20_;
					Node* _tmp21_;
					if (!_tmp14_) {
						gint _tmp15_;
						_tmp15_ = i;
						i = _tmp15_ + 1;
					}
					_tmp14_ = FALSE;
					_tmp16_ = node_children (n);
					_tmp17_ = _tmp16_;
					_tmp18_ = !(((guint) i) < _tmp17_->len);
					_g_array_unref0 (_tmp17_);
					if (_tmp18_) {
						break;
					}
					_tmp19_ = node_children (n);
					_tmp20_ = _tmp19_;
					_tmp21_ = g_array_index (_tmp20_, Node*, (guint) i);
					animator_positions_gather_old_positions (self, _tmp21_, exclude_selected);
					_g_array_unref0 (_tmp20_);
				}
			}
		}
	}
}

void
animator_positions_gather_new_positions (AnimatorPositions* self)
{
	g_return_if_fail (self != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GArray* _tmp2_;
				GArray* _tmp3_;
				GArray* _tmp4_;
				Node* _tmp5_;
				gdouble _tmp6_;
				gdouble _tmp7_;
				gdouble* _tmp8_;
				GArray* _tmp9_;
				GArray* _tmp10_;
				Node* _tmp11_;
				gdouble _tmp12_;
				gdouble _tmp13_;
				gdouble* _tmp14_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->_node;
				if (!(((guint) i) < _tmp2_->len)) {
					break;
				}
				_tmp3_ = self->priv->_new_x;
				_tmp4_ = self->priv->_node;
				_tmp5_ = g_array_index (_tmp4_, Node*, (guint) i);
				_tmp6_ = node_get_posx (_tmp5_);
				_tmp7_ = _tmp6_;
				_tmp8_ = __double_dup0 (&_tmp7_);
				g_array_append_val (_tmp3_, _tmp8_);
				_tmp9_ = self->priv->_new_y;
				_tmp10_ = self->priv->_node;
				_tmp11_ = g_array_index (_tmp10_, Node*, (guint) i);
				_tmp12_ = node_get_posy (_tmp11_);
				_tmp13_ = _tmp12_;
				_tmp14_ = __double_dup0 (&_tmp13_);
				g_array_append_val (_tmp9_, _tmp14_);
			}
		}
	}
}

guint
animator_positions_length (AnimatorPositions* self)
{
	GArray* _tmp0_;
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = self->priv->_node;
	result = _tmp0_->len;
	return result;
}

gdouble
animator_positions_old_x (AnimatorPositions* self,
                          gint index)
{
	GArray* _tmp0_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->_old_x;
	result = *g_array_index (_tmp0_, gdouble*, (guint) index);
	return result;
}

gdouble
animator_positions_old_y (AnimatorPositions* self,
                          gint index)
{
	GArray* _tmp0_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->_old_y;
	result = *g_array_index (_tmp0_, gdouble*, (guint) index);
	return result;
}

gdouble
animator_positions_new_x (AnimatorPositions* self,
                          gint index)
{
	GArray* _tmp0_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->_new_x;
	result = *g_array_index (_tmp0_, gdouble*, (guint) index);
	return result;
}

gdouble
animator_positions_new_y (AnimatorPositions* self,
                          gint index)
{
	GArray* _tmp0_;
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	_tmp0_ = self->priv->_new_y;
	result = *g_array_index (_tmp0_, gdouble*, (guint) index);
	return result;
}

Node*
animator_positions_node (AnimatorPositions* self,
                         gint index)
{
	GArray* _tmp0_;
	Node* _tmp1_;
	Node* _tmp2_;
	Node* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_node;
	_tmp1_ = g_array_index (_tmp0_, Node*, (guint) index);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	result = _tmp2_;
	return result;
}

static void
animator_positions_class_init (AnimatorPositionsClass * klass,
                               gpointer klass_data)
{
	animator_positions_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &AnimatorPositions_private_offset);
	G_OBJECT_CLASS (klass)->finalize = animator_positions_finalize;
}

static void
animator_positions_instance_init (AnimatorPositions * self,
                                  gpointer klass)
{
	self->priv = animator_positions_get_instance_private (self);
}

static void
animator_positions_finalize (GObject * obj)
{
	AnimatorPositions * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_ANIMATOR_POSITIONS, AnimatorPositions);
	_g_array_unref0 (self->priv->_old_x);
	_g_array_unref0 (self->priv->_old_y);
	_g_array_unref0 (self->priv->_new_x);
	_g_array_unref0 (self->priv->_new_y);
	_g_array_unref0 (self->priv->_node);
	G_OBJECT_CLASS (animator_positions_parent_class)->finalize (obj);
}

static GType
animator_positions_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (AnimatorPositionsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) animator_positions_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AnimatorPositions), 0, (GInstanceInitFunc) animator_positions_instance_init, NULL };
	GType animator_positions_type_id;
	animator_positions_type_id = g_type_register_static (G_TYPE_OBJECT, "AnimatorPositions", &g_define_type_info, 0);
	AnimatorPositions_private_offset = g_type_add_instance_private (animator_positions_type_id, sizeof (AnimatorPositionsPrivate));
	return animator_positions_type_id;
}

GType
animator_positions_get_type (void)
{
	static volatile gsize animator_positions_type_id__once = 0;
	if (g_once_init_enter (&animator_positions_type_id__once)) {
		GType animator_positions_type_id;
		animator_positions_type_id = animator_positions_get_type_once ();
		g_once_init_leave (&animator_positions_type_id__once, animator_positions_type_id);
	}
	return animator_positions_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;
}

