/**************************************************************************/1/* math_defs.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/typedefs.h"3334#include <limits>3536namespace Math {37inline constexpr double SQRT2 = 1.4142135623730950488016887242;38inline constexpr double SQRT3 = 1.7320508075688772935274463415059;39inline constexpr double SQRT12 = 0.7071067811865475244008443621048490;40inline constexpr double SQRT13 = 0.57735026918962576450914878050196;41inline constexpr double LN2 = 0.6931471805599453094172321215;42inline constexpr double TAU = 6.2831853071795864769252867666;43inline constexpr double PI = 3.1415926535897932384626433833;44inline constexpr double E = 2.7182818284590452353602874714;45inline constexpr double INF = std::numeric_limits<double>::infinity();46inline constexpr double NaN = std::numeric_limits<double>::quiet_NaN();47} // namespace Math4849#define CMP_EPSILON 0.0000150#define CMP_EPSILON2 (CMP_EPSILON * CMP_EPSILON)5152#define CMP_NORMALIZE_TOLERANCE 0.00000153#define CMP_POINT_IN_PLANE_EPSILON 0.000015455#ifdef DEBUG_ENABLED56#define MATH_CHECKS57#endif5859//this epsilon is for values related to a unit size (scalar or vector len)60#ifdef PRECISE_MATH_CHECKS61#define UNIT_EPSILON 0.0000162#else63//tolerate some more floating point error normally64#define UNIT_EPSILON 0.00165#endif6667#define USEC_TO_SEC(m_usec) ((m_usec) / 1000000.0)6869enum ClockDirection {70CLOCKWISE,71COUNTERCLOCKWISE72};7374enum Orientation {75HORIZONTAL,76VERTICAL77};7879enum HorizontalAlignment {80HORIZONTAL_ALIGNMENT_LEFT,81HORIZONTAL_ALIGNMENT_CENTER,82HORIZONTAL_ALIGNMENT_RIGHT,83HORIZONTAL_ALIGNMENT_FILL,84};8586enum VerticalAlignment {87VERTICAL_ALIGNMENT_TOP,88VERTICAL_ALIGNMENT_CENTER,89VERTICAL_ALIGNMENT_BOTTOM,90VERTICAL_ALIGNMENT_FILL,91};9293enum InlineAlignment {94// Image alignment points.95INLINE_ALIGNMENT_TOP_TO = 0b0000,96INLINE_ALIGNMENT_CENTER_TO = 0b0001,97INLINE_ALIGNMENT_BASELINE_TO = 0b0011,98INLINE_ALIGNMENT_BOTTOM_TO = 0b0010,99INLINE_ALIGNMENT_IMAGE_MASK = 0b0011,100101// Text alignment points.102INLINE_ALIGNMENT_TO_TOP = 0b0000,103INLINE_ALIGNMENT_TO_CENTER = 0b0100,104INLINE_ALIGNMENT_TO_BASELINE = 0b1000,105INLINE_ALIGNMENT_TO_BOTTOM = 0b1100,106INLINE_ALIGNMENT_TEXT_MASK = 0b1100,107108// Presets.109INLINE_ALIGNMENT_TOP = INLINE_ALIGNMENT_TOP_TO | INLINE_ALIGNMENT_TO_TOP,110INLINE_ALIGNMENT_CENTER = INLINE_ALIGNMENT_CENTER_TO | INLINE_ALIGNMENT_TO_CENTER,111INLINE_ALIGNMENT_BOTTOM = INLINE_ALIGNMENT_BOTTOM_TO | INLINE_ALIGNMENT_TO_BOTTOM112};113114enum Side {115SIDE_LEFT,116SIDE_TOP,117SIDE_RIGHT,118SIDE_BOTTOM119};120121enum Corner {122CORNER_TOP_LEFT,123CORNER_TOP_RIGHT,124CORNER_BOTTOM_RIGHT,125CORNER_BOTTOM_LEFT126};127128enum class EulerOrder {129XYZ,130XZY,131YXZ,132YZX,133ZXY,134ZYX135};136137/**138* The "Real" type is an abstract type used for real numbers, such as 1.5,139* in contrast to integer numbers. Precision can be controlled with the140* presence or absence of the REAL_T_IS_DOUBLE define.141*/142#ifdef REAL_T_IS_DOUBLE143typedef double real_t;144#else145typedef float real_t;146#endif147148149