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

/*
Copyright (C) 2015 Johan Mattsson

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 3 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.
*/

#include "birdfont.h"
#include <glib.h>
#include <glib-object.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <gee.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

enum  {
	BIRD_FONT_INTERSECTION_0_PROPERTY,
	BIRD_FONT_INTERSECTION_NUM_PROPERTIES
};
static GParamSpec* bird_font_intersection_properties[BIRD_FONT_INTERSECTION_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	BIRD_FONT_INTERSECTION_LIST_0_PROPERTY,
	BIRD_FONT_INTERSECTION_LIST_NUM_PROPERTIES
};
static GParamSpec* bird_font_intersection_list_properties[BIRD_FONT_INTERSECTION_LIST_NUM_PROPERTIES];

static gpointer bird_font_intersection_parent_class = NULL;
static gpointer bird_font_intersection_list_parent_class = NULL;

static void bird_font_intersection_finalize (GObject * obj);
static GType bird_font_intersection_get_type_once (void);
static void bird_font_intersection_list_finalize (GObject * obj);
static GType bird_font_intersection_list_get_type_once (void);

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

BirdFontIntersection*
bird_font_intersection_construct (GType object_type,
                                  BirdFontEditPoint* point,
                                  BirdFontPath* path,
                                  BirdFontEditPoint* other_point,
                                  BirdFontPath* other_path)
{
	BirdFontIntersection * self = NULL;
	BirdFontEditPoint* _tmp0_;
	BirdFontPath* _tmp1_;
	BirdFontEditPoint* _tmp2_;
	BirdFontPath* _tmp3_;
	g_return_val_if_fail (point != NULL, NULL);
	g_return_val_if_fail (path != NULL, NULL);
	g_return_val_if_fail (other_point != NULL, NULL);
	g_return_val_if_fail (other_path != NULL, NULL);
	self = (BirdFontIntersection*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (point);
	_g_object_unref0 (self->point);
	self->point = _tmp0_;
	_tmp1_ = _g_object_ref0 (path);
	_g_object_unref0 (self->path);
	self->path = _tmp1_;
	_tmp2_ = _g_object_ref0 (other_point);
	_g_object_unref0 (self->other_point);
	self->other_point = _tmp2_;
	_tmp3_ = _g_object_ref0 (other_path);
	_g_object_unref0 (self->other_path);
	self->other_path = _tmp3_;
	return self;
}

BirdFontIntersection*
bird_font_intersection_new (BirdFontEditPoint* point,
                            BirdFontPath* path,
                            BirdFontEditPoint* other_point,
                            BirdFontPath* other_path)
{
	return bird_font_intersection_construct (BIRD_FONT_TYPE_INTERSECTION, point, path, other_point, other_path);
}

BirdFontIntersection*
bird_font_intersection_construct_empty (GType object_type)
{
	BirdFontIntersection * self = NULL;
	BirdFontEditPoint* _tmp0_;
	BirdFontPath* _tmp1_;
	BirdFontEditPoint* _tmp2_;
	BirdFontPath* _tmp3_;
	self = (BirdFontIntersection*) g_object_new (object_type, NULL);
	_tmp0_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_g_object_unref0 (self->point);
	self->point = _tmp0_;
	_tmp1_ = bird_font_path_new ();
	_g_object_unref0 (self->path);
	self->path = _tmp1_;
	_tmp2_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	_g_object_unref0 (self->other_point);
	self->other_point = _tmp2_;
	_tmp3_ = bird_font_path_new ();
	_g_object_unref0 (self->other_path);
	self->other_path = _tmp3_;
	return self;
}

BirdFontIntersection*
bird_font_intersection_new_empty (void)
{
	return bird_font_intersection_construct_empty (BIRD_FONT_TYPE_INTERSECTION);
}

BirdFontPath*
bird_font_intersection_get_other_path (BirdFontIntersection* self,
                                       BirdFontPath* p)
{
	BirdFontPath* _tmp0_;
	BirdFontPath* _tmp3_;
	BirdFontPath* _tmp6_;
	BirdFontPath* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (p != NULL, NULL);
	_tmp0_ = self->path;
	if (p == _tmp0_) {
		BirdFontPath* _tmp1_;
		BirdFontPath* _tmp2_;
		_tmp1_ = self->other_path;
		_tmp2_ = _g_object_ref0 (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->other_path;
	if (p == _tmp3_) {
		BirdFontPath* _tmp4_;
		BirdFontPath* _tmp5_;
		_tmp4_ = self->path;
		_tmp5_ = _g_object_ref0 (_tmp4_);
		result = _tmp5_;
		return result;
	}
	g_warning ("Intersection.vala:53: %s", "Wrong intersection.");
	_tmp6_ = bird_font_path_new ();
	result = _tmp6_;
	return result;
}

BirdFontEditPoint*
bird_font_intersection_get_point (BirdFontIntersection* self,
                                  BirdFontPath* p)
{
	BirdFontPath* _tmp0_;
	BirdFontPath* _tmp3_;
	BirdFontEditPoint* _tmp6_;
	BirdFontEditPoint* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (p != NULL, NULL);
	_tmp0_ = self->path;
	if (p == _tmp0_) {
		BirdFontEditPoint* _tmp1_;
		BirdFontEditPoint* _tmp2_;
		_tmp1_ = self->point;
		_tmp2_ = _g_object_ref0 (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->other_path;
	if (p == _tmp3_) {
		BirdFontEditPoint* _tmp4_;
		BirdFontEditPoint* _tmp5_;
		_tmp4_ = self->other_point;
		_tmp5_ = _g_object_ref0 (_tmp4_);
		result = _tmp5_;
		return result;
	}
	g_warning ("Intersection.vala:66: Wrong intersection.");
	_tmp6_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	result = _tmp6_;
	return result;
}

BirdFontEditPoint*
bird_font_intersection_get_other_point (BirdFontIntersection* self,
                                        BirdFontPath* p)
{
	BirdFontPath* _tmp0_;
	BirdFontPath* _tmp3_;
	BirdFontEditPoint* _tmp6_;
	BirdFontEditPoint* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (p != NULL, NULL);
	_tmp0_ = self->path;
	if (p == _tmp0_) {
		BirdFontEditPoint* _tmp1_;
		BirdFontEditPoint* _tmp2_;
		_tmp1_ = self->other_point;
		_tmp2_ = _g_object_ref0 (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->other_path;
	if (p == _tmp3_) {
		BirdFontEditPoint* _tmp4_;
		BirdFontEditPoint* _tmp5_;
		_tmp4_ = self->point;
		_tmp5_ = _g_object_ref0 (_tmp4_);
		result = _tmp5_;
		return result;
	}
	g_warning ("Intersection.vala:79: Wrong intersection.");
	_tmp6_ = bird_font_edit_point_new ((gdouble) 0, (gdouble) 0, BIRD_FONT_POINT_TYPE_NONE);
	result = _tmp6_;
	return result;
}

static gchar*
double_to_string (gdouble self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp1__length1;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = G_ASCII_DTOSTR_BUF_SIZE;
	_tmp2_ = g_ascii_dtostr (_tmp1_, (gint) G_ASCII_DTOSTR_BUF_SIZE, self);
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	result = _tmp4_;
	return result;
}

gchar*
bird_font_intersection_to_string (BirdFontIntersection* self)
{
	BirdFontEditPoint* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	BirdFontEditPoint* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	BirdFontEditPoint* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	BirdFontEditPoint* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->point;
	_tmp1_ = double_to_string (_tmp0_->x);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->point;
	_tmp4_ = double_to_string (_tmp3_->y);
	_tmp5_ = _tmp4_;
	_tmp6_ = self->other_point;
	_tmp7_ = double_to_string (_tmp6_->x);
	_tmp8_ = _tmp7_;
	_tmp9_ = self->other_point;
	_tmp10_ = double_to_string (_tmp9_->y);
	_tmp11_ = _tmp10_;
	_tmp12_ = g_strconcat (_tmp2_, ", ", _tmp5_, " & ", _tmp8_, ", ", _tmp11_, NULL);
	_tmp13_ = _tmp12_;
	_g_free0 (_tmp11_);
	_g_free0 (_tmp8_);
	_g_free0 (_tmp5_);
	_g_free0 (_tmp2_);
	result = _tmp13_;
	return result;
}

static void
bird_font_intersection_class_init (BirdFontIntersectionClass * klass,
                                   gpointer klass_data)
{
	bird_font_intersection_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_intersection_finalize;
}

static void
bird_font_intersection_instance_init (BirdFontIntersection * self,
                                      gpointer klass)
{
	self->done = FALSE;
	self->self_intersection = FALSE;
}

static void
bird_font_intersection_finalize (GObject * obj)
{
	BirdFontIntersection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_INTERSECTION, BirdFontIntersection);
	_g_object_unref0 (self->point);
	_g_object_unref0 (self->other_point);
	_g_object_unref0 (self->path);
	_g_object_unref0 (self->other_path);
	G_OBJECT_CLASS (bird_font_intersection_parent_class)->finalize (obj);
}

static GType
bird_font_intersection_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontIntersectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_intersection_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontIntersection), 0, (GInstanceInitFunc) bird_font_intersection_instance_init, NULL };
	GType bird_font_intersection_type_id;
	bird_font_intersection_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontIntersection", &g_define_type_info, 0);
	return bird_font_intersection_type_id;
}

GType
bird_font_intersection_get_type (void)
{
	static volatile gsize bird_font_intersection_type_id__once = 0;
	if (g_once_init_enter (&bird_font_intersection_type_id__once)) {
		GType bird_font_intersection_type_id;
		bird_font_intersection_type_id = bird_font_intersection_get_type_once ();
		g_once_init_leave (&bird_font_intersection_type_id__once, bird_font_intersection_type_id);
	}
	return bird_font_intersection_type_id__once;
}

BirdFontIntersectionList*
bird_font_intersection_list_construct (GType object_type)
{
	BirdFontIntersectionList * self = NULL;
	self = (BirdFontIntersectionList*) g_object_new (object_type, NULL);
	return self;
}

BirdFontIntersectionList*
bird_font_intersection_list_new (void)
{
	return bird_font_intersection_list_construct (BIRD_FONT_TYPE_INTERSECTION_LIST);
}

BirdFontIntersection*
bird_font_intersection_list_get_point (BirdFontIntersectionList* self,
                                       BirdFontEditPoint* ep,
                                       gboolean* other)
{
	gboolean _vala_other = FALSE;
	gchar* _tmp15_;
	gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	gchar* _tmp19_;
	gchar* _tmp20_;
	BirdFontIntersection* _tmp21_;
	BirdFontIntersection* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (ep != NULL, NULL);
	_vala_other = FALSE;
	{
		GeeArrayList* _i_list = NULL;
		GeeArrayList* _tmp0_;
		gint _i_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _i_index = 0;
		_tmp0_ = self->points;
		_i_list = _tmp0_;
		_tmp1_ = _i_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_i_size = _tmp3_;
		_i_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontIntersection* i = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			BirdFontIntersection* _tmp9_;
			BirdFontEditPoint* _tmp10_;
			_i_index = _i_index + 1;
			_tmp4_ = _i_index;
			_tmp5_ = _i_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _i_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _i_index);
			i = (BirdFontIntersection*) _tmp7_;
			_tmp9_ = i;
			_tmp10_ = _tmp9_->other_point;
			if (_tmp10_ == ep) {
				_tmp8_ = TRUE;
			} else {
				BirdFontIntersection* _tmp11_;
				BirdFontEditPoint* _tmp12_;
				_tmp11_ = i;
				_tmp12_ = _tmp11_->point;
				_tmp8_ = _tmp12_ == ep;
			}
			if (G_LIKELY (_tmp8_)) {
				BirdFontIntersection* _tmp13_;
				BirdFontEditPoint* _tmp14_;
				_tmp13_ = i;
				_tmp14_ = _tmp13_->other_point;
				_vala_other = _tmp14_ == ep;
				result = i;
				if (other) {
					*other = _vala_other;
				}
				return result;
			}
			_g_object_unref0 (i);
		}
	}
	_tmp15_ = double_to_string (ep->x);
	_tmp16_ = _tmp15_;
	_tmp17_ = double_to_string (ep->y);
	_tmp18_ = _tmp17_;
	_tmp19_ = g_strconcat ("No intersection found for point (", _tmp16_, ", ", _tmp18_, ").\n", NULL);
	_tmp20_ = _tmp19_;
	g_warning ("Intersection.vala:103: %s", _tmp20_);
	_g_free0 (_tmp20_);
	_g_free0 (_tmp18_);
	_g_free0 (_tmp16_);
	_tmp21_ = bird_font_intersection_new_empty ();
	result = _tmp21_;
	if (other) {
		*other = _vala_other;
	}
	return result;
}

gboolean
bird_font_intersection_list_has_point (BirdFontIntersectionList* self,
                                       BirdFontEditPoint* ep)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (ep != NULL, FALSE);
	{
		GeeArrayList* _i_list = NULL;
		GeeArrayList* _tmp0_;
		gint _i_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _i_index = 0;
		_tmp0_ = self->points;
		_i_list = _tmp0_;
		_tmp1_ = _i_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_i_size = _tmp3_;
		_i_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontIntersection* i = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			BirdFontIntersection* _tmp9_;
			BirdFontEditPoint* _tmp10_;
			_i_index = _i_index + 1;
			_tmp4_ = _i_index;
			_tmp5_ = _i_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _i_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _i_index);
			i = (BirdFontIntersection*) _tmp7_;
			_tmp9_ = i;
			_tmp10_ = _tmp9_->other_point;
			if (_tmp10_ == ep) {
				_tmp8_ = TRUE;
			} else {
				BirdFontIntersection* _tmp11_;
				BirdFontEditPoint* _tmp12_;
				_tmp11_ = i;
				_tmp12_ = _tmp11_->point;
				_tmp8_ = _tmp12_ == ep;
			}
			if (_tmp8_) {
				result = TRUE;
				_g_object_unref0 (i);
				return result;
			}
			_g_object_unref0 (i);
		}
	}
	result = FALSE;
	return result;
}

static void
bird_font_intersection_list_class_init (BirdFontIntersectionListClass * klass,
                                        gpointer klass_data)
{
	bird_font_intersection_list_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_intersection_list_finalize;
}

static void
bird_font_intersection_list_instance_init (BirdFontIntersectionList * self,
                                           gpointer klass)
{
	GeeArrayList* _tmp0_;
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_INTERSECTION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->points = _tmp0_;
}

static void
bird_font_intersection_list_finalize (GObject * obj)
{
	BirdFontIntersectionList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_INTERSECTION_LIST, BirdFontIntersectionList);
	_g_object_unref0 (self->points);
	G_OBJECT_CLASS (bird_font_intersection_list_parent_class)->finalize (obj);
}

static GType
bird_font_intersection_list_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontIntersectionListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_intersection_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontIntersectionList), 0, (GInstanceInitFunc) bird_font_intersection_list_instance_init, NULL };
	GType bird_font_intersection_list_type_id;
	bird_font_intersection_list_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontIntersectionList", &g_define_type_info, 0);
	return bird_font_intersection_list_type_id;
}

GType
bird_font_intersection_list_get_type (void)
{
	static volatile gsize bird_font_intersection_list_type_id__once = 0;
	if (g_once_init_enter (&bird_font_intersection_list_type_id__once)) {
		GType bird_font_intersection_list_type_id;
		bird_font_intersection_list_type_id = bird_font_intersection_list_get_type_once ();
		g_once_init_leave (&bird_font_intersection_list_type_id__once, bird_font_intersection_list_type_id);
	}
	return bird_font_intersection_list_type_id__once;
}

