/* gcalc-units.c generated by valac 0.56.3, the Vala compiler
 * generated from gcalc-units.vala, do not modify */

/* gcalc-units.vala
 *
 * Copyright (C) 2022  Daniel Espinosa <esodan@gmail.com>
 *
 * 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/>.
 *
 * Authors:
 *      Daniel Espinosa <esodan@gmail.com>
 */

#include "gcalc/gcalc.h"
#include <glib.h>
#include <glib-object.h>
#include "gcalc.h"

enum  {
	GCALC_UNIT_CONVERTER_0_PROPERTY,
	GCALC_UNIT_CONVERTER_NUM_PROPERTIES
};
static GParamSpec* gcalc_unit_converter_properties[GCALC_UNIT_CONVERTER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

static gpointer gcalc_unit_converter_parent_class = NULL;

static GType gcalc_unit_converter_get_type_once (void);

static GType
gcalc_angle_unit_get_type_once (void)
{
	static const GEnumValue values[] = {{GCALC_ANGLE_UNIT_RADIANS, "GCALC_ANGLE_UNIT_RADIANS", "radians"}, {GCALC_ANGLE_UNIT_DEGREES, "GCALC_ANGLE_UNIT_DEGREES", "degrees"}, {GCALC_ANGLE_UNIT_GRADIANS, "GCALC_ANGLE_UNIT_GRADIANS", "gradians"}, {0, NULL, NULL}};
	GType gcalc_angle_unit_type_id;
	gcalc_angle_unit_type_id = g_enum_register_static ("GCalcAngleUnit", values);
	return gcalc_angle_unit_type_id;
}

GType
gcalc_angle_unit_get_type (void)
{
	static volatile gsize gcalc_angle_unit_type_id__once = 0;
	if (g_once_init_enter (&gcalc_angle_unit_type_id__once)) {
		GType gcalc_angle_unit_type_id;
		gcalc_angle_unit_type_id = gcalc_angle_unit_get_type_once ();
		g_once_init_leave (&gcalc_angle_unit_type_id__once, gcalc_angle_unit_type_id);
	}
	return gcalc_angle_unit_type_id__once;
}

GCalcMathConstant*
gcalc_unit_converter_angle (GCalcMathConstant* c,
                            GCalcAngleUnit ori,
                            GCalcAngleUnit dst)
{
	GCalcConstant* rc = NULL;
	GCalcConstant* _tmp0_;
	GCalcMathConstant* pi = NULL;
	GCalcMathConstant* _tmp1_;
	GCalcConstant* _tmp2_;
	GCalcMathConstant* _tmp3_;
	GCalcConstant* _tmp4_;
	GCalcConstant* _tmp5_;
	GCalcMathConstant* _tmp6_;
	GCalcMathConstant* _tmp7_;
	gboolean _tmp8_;
	gboolean _tmp18_ = FALSE;
	gboolean _tmp26_ = FALSE;
	gboolean _tmp34_ = FALSE;
	gboolean _tmp43_ = FALSE;
	GCalcMathConstant* result;
	g_return_val_if_fail (c != NULL, NULL);
	_tmp0_ = gcalc_constant_new_assign (c);
	rc = _tmp0_;
	if (ori == dst) {
		result = (GCalcMathConstant*) rc;
		return result;
	}
	_tmp1_ = gcalc_calculator_pi ();
	pi = _tmp1_;
	_tmp2_ = rc;
	_tmp3_ = pi;
	_tmp4_ = gcalc_constant_new_double (2.0);
	_tmp5_ = _tmp4_;
	_tmp6_ = gcalc_math_constant_multiply (_tmp3_, (GCalcMathConstant*) _tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = gcalc_calculator_gt ((GCalcMathConstant*) _tmp2_, _tmp7_);
	_g_object_unref0 (_tmp7_);
	_g_object_unref0 (_tmp5_);
	if (_tmp8_) {
		GCalcMathConstant* t = NULL;
		GCalcConstant* _tmp9_;
		GCalcMathConstant* _tmp10_;
		GCalcMathConstant* _tmp11_;
		GCalcConstant* _tmp12_;
		GCalcMathConstant* _tmp13_;
		GCalcMathConstant* _tmp14_;
		GCalcMathConstant* _tmp15_;
		GCalcMathConstant* _tmp16_;
		GCalcMathConstant* _tmp17_;
		_tmp9_ = rc;
		_tmp10_ = pi;
		_tmp11_ = gcalc_math_constant_divide ((GCalcMathConstant*) _tmp9_, _tmp10_);
		t = _tmp11_;
		_tmp12_ = rc;
		_tmp13_ = pi;
		_tmp14_ = t;
		_tmp15_ = gcalc_math_constant_multiply (_tmp13_, _tmp14_);
		_tmp16_ = _tmp15_;
		_tmp17_ = gcalc_math_constant_subtract ((GCalcMathConstant*) _tmp12_, _tmp16_);
		_g_object_unref0 (rc);
		rc = G_TYPE_CHECK_INSTANCE_CAST (_tmp17_, GCALC_TYPE_CONSTANT, GCalcConstant);
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (t);
	}
	if (ori == GCALC_ANGLE_UNIT_DEGREES) {
		_tmp18_ = dst == GCALC_ANGLE_UNIT_RADIANS;
	} else {
		_tmp18_ = FALSE;
	}
	if (_tmp18_) {
		GCalcConstant* d = NULL;
		GCalcConstant* _tmp19_;
		GCalcMathConstant* g = NULL;
		GCalcMathConstant* _tmp20_;
		GCalcConstant* _tmp21_;
		GCalcMathConstant* _tmp22_;
		GCalcConstant* _tmp23_;
		GCalcMathConstant* _tmp24_;
		GCalcMathConstant* _tmp25_;
		_tmp19_ = gcalc_constant_new_double (180.0);
		d = _tmp19_;
		_tmp20_ = pi;
		_tmp21_ = d;
		_tmp22_ = gcalc_math_constant_divide (_tmp20_, (GCalcMathConstant*) _tmp21_);
		g = _tmp22_;
		_tmp23_ = rc;
		_tmp24_ = g;
		_tmp25_ = gcalc_math_constant_multiply ((GCalcMathConstant*) _tmp23_, _tmp24_);
		result = _tmp25_;
		_g_object_unref0 (g);
		_g_object_unref0 (d);
		_g_object_unref0 (pi);
		_g_object_unref0 (rc);
		return result;
	}
	if (ori == GCALC_ANGLE_UNIT_GRADIANS) {
		_tmp26_ = dst == GCALC_ANGLE_UNIT_RADIANS;
	} else {
		_tmp26_ = FALSE;
	}
	if (_tmp26_) {
		GCalcConstant* d = NULL;
		GCalcConstant* _tmp27_;
		GCalcMathConstant* grd = NULL;
		GCalcMathConstant* _tmp28_;
		GCalcConstant* _tmp29_;
		GCalcMathConstant* _tmp30_;
		GCalcConstant* _tmp31_;
		GCalcMathConstant* _tmp32_;
		GCalcMathConstant* _tmp33_;
		_tmp27_ = gcalc_constant_new_double (400.0);
		d = _tmp27_;
		_tmp28_ = pi;
		_tmp29_ = d;
		_tmp30_ = gcalc_math_constant_divide (_tmp28_, (GCalcMathConstant*) _tmp29_);
		grd = _tmp30_;
		_tmp31_ = rc;
		_tmp32_ = grd;
		_tmp33_ = gcalc_math_constant_multiply ((GCalcMathConstant*) _tmp31_, _tmp32_);
		result = _tmp33_;
		_g_object_unref0 (grd);
		_g_object_unref0 (d);
		_g_object_unref0 (pi);
		_g_object_unref0 (rc);
		return result;
	}
	if (ori == GCALC_ANGLE_UNIT_DEGREES) {
		_tmp34_ = dst == GCALC_ANGLE_UNIT_GRADIANS;
	} else {
		_tmp34_ = FALSE;
	}
	if (_tmp34_) {
		GCalcConstant* d = NULL;
		GCalcConstant* _tmp35_;
		GCalcConstant* g = NULL;
		GCalcConstant* _tmp36_;
		GCalcMathConstant* grd = NULL;
		GCalcConstant* _tmp37_;
		GCalcConstant* _tmp38_;
		GCalcMathConstant* _tmp39_;
		GCalcConstant* _tmp40_;
		GCalcMathConstant* _tmp41_;
		GCalcMathConstant* _tmp42_;
		_tmp35_ = gcalc_constant_new_double (9.0);
		d = _tmp35_;
		_tmp36_ = gcalc_constant_new_double (10.0);
		g = _tmp36_;
		_tmp37_ = g;
		_tmp38_ = d;
		_tmp39_ = gcalc_math_constant_divide ((GCalcMathConstant*) _tmp37_, (GCalcMathConstant*) _tmp38_);
		grd = _tmp39_;
		_tmp40_ = rc;
		_tmp41_ = grd;
		_tmp42_ = gcalc_math_constant_multiply ((GCalcMathConstant*) _tmp40_, _tmp41_);
		result = _tmp42_;
		_g_object_unref0 (grd);
		_g_object_unref0 (g);
		_g_object_unref0 (d);
		_g_object_unref0 (pi);
		_g_object_unref0 (rc);
		return result;
	}
	if (ori == GCALC_ANGLE_UNIT_GRADIANS) {
		_tmp43_ = dst == GCALC_ANGLE_UNIT_DEGREES;
	} else {
		_tmp43_ = FALSE;
	}
	if (_tmp43_) {
		GCalcConstant* d = NULL;
		GCalcConstant* _tmp44_;
		GCalcConstant* g = NULL;
		GCalcConstant* _tmp45_;
		GCalcMathConstant* dg = NULL;
		GCalcConstant* _tmp46_;
		GCalcConstant* _tmp47_;
		GCalcMathConstant* _tmp48_;
		GCalcConstant* _tmp49_;
		GCalcMathConstant* _tmp50_;
		GCalcMathConstant* _tmp51_;
		_tmp44_ = gcalc_constant_new_double (9.0);
		d = _tmp44_;
		_tmp45_ = gcalc_constant_new_double (10.0);
		g = _tmp45_;
		_tmp46_ = d;
		_tmp47_ = g;
		_tmp48_ = gcalc_math_constant_divide ((GCalcMathConstant*) _tmp46_, (GCalcMathConstant*) _tmp47_);
		dg = _tmp48_;
		_tmp49_ = rc;
		_tmp50_ = dg;
		_tmp51_ = gcalc_math_constant_multiply ((GCalcMathConstant*) _tmp49_, _tmp50_);
		result = _tmp51_;
		_g_object_unref0 (dg);
		_g_object_unref0 (g);
		_g_object_unref0 (d);
		_g_object_unref0 (pi);
		_g_object_unref0 (rc);
		return result;
	}
	result = (GCalcMathConstant*) rc;
	_g_object_unref0 (pi);
	return result;
}

GCalcUnitConverter*
gcalc_unit_converter_construct (GType object_type)
{
	GCalcUnitConverter * self = NULL;
	self = (GCalcUnitConverter*) g_object_new (object_type, NULL);
	return self;
}

GCalcUnitConverter*
gcalc_unit_converter_new (void)
{
	return gcalc_unit_converter_construct (GCALC_TYPE_UNIT_CONVERTER);
}

static void
gcalc_unit_converter_class_init (GCalcUnitConverterClass * klass,
                                 gpointer klass_data)
{
	gcalc_unit_converter_parent_class = g_type_class_peek_parent (klass);
}

static void
gcalc_unit_converter_instance_init (GCalcUnitConverter * self,
                                    gpointer klass)
{
}

static GType
gcalc_unit_converter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcUnitConverterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_unit_converter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcUnitConverter), 0, (GInstanceInitFunc) gcalc_unit_converter_instance_init, NULL };
	GType gcalc_unit_converter_type_id;
	gcalc_unit_converter_type_id = g_type_register_static (G_TYPE_OBJECT, "GCalcUnitConverter", &g_define_type_info, 0);
	return gcalc_unit_converter_type_id;
}

GType
gcalc_unit_converter_get_type (void)
{
	static volatile gsize gcalc_unit_converter_type_id__once = 0;
	if (g_once_init_enter (&gcalc_unit_converter_type_id__once)) {
		GType gcalc_unit_converter_type_id;
		gcalc_unit_converter_type_id = gcalc_unit_converter_get_type_once ();
		g_once_init_leave (&gcalc_unit_converter_type_id__once, gcalc_unit_converter_type_id);
	}
	return gcalc_unit_converter_type_id__once;
}

