1/**
2 * Mandelbulber v2, a 3D fractal generator  _%}}i*<.        ____                _______
3 * Copyright (C) 2020 Mandelbulber Team   _>]|=||i=i<,     / __ \___  ___ ___  / ___/ /
4 *                                        \><||i|=>>%)    / /_/ / _ \/ -_) _ \/ /__/ /__
5 * This file is part of Mandelbulber.     )<=i=]=|=i<>    \____/ .__/\__/_//_/\___/____/
6 * The project is licensed under GPLv3,   -<>>=|><|||`        /_/
7 * see also COPYING file in this folder.    ~+{i%+++
8 *
9 * poly fold sym DarkBeam's version
10 * @reference
11 * DarkBeam (luca) http://www.fractalforums.com/mandelbulber/
12 * _polyfold_sym-and-polyfoldsymifs-in-mandelbulber-2/msg98162/#msg98162
13
14 * This file has been autogenerated by tools/populateUiInformation.php
15 * from the file "fractal_transf_poly_fold_sym_xy.cpp" in the folder formula/definition
16 * D O    N O T    E D I T    T H I S    F I L E !
17 */
18
19REAL4 TransfPolyFoldSymXYIteration(REAL4 z, __constant sFractalCl *fractal, sExtendedAuxCl *aux)
20{
21	REAL4 oldZ = z;
22	// pre abs
23	if (fractal->transformCommon.functionEnabledxFalse) z.x = fabs(z.x);
24	if (fractal->transformCommon.functionEnabledyFalse) z.y = fabs(z.y);
25
26	int order = fractal->transformCommon.int6;
27	REAL div2PI = (REAL)order / M_PI_2x_F;
28
29	bool cy = false;
30	int sector;
31	if (!fractal->transformCommon.functionEnabledFalse)
32		sector = (int)(-div2PI * atan(z.x / z.y));
33	else
34		sector = (int)(-div2PI * atan2(z.x, z.y));
35
36	if (sector & 1) cy = true; // parity   if (sector & 1) is a "bit check", true = odd
37	REAL angle = (REAL)(sector / div2PI);
38	// z.xy = rotate(z.xy,angle); // sin
39	REAL tempZx = z.x;
40	REAL sAng = native_sin(angle);
41	REAL cAng = native_cos(angle);
42	z.x = z.x * cAng - z.y * sAng;
43	z.y = tempZx * sAng + z.y * cAng;
44	if (cy) z.y = -z.y;
45	// if ((order&1) && (sector == 0)) z.y = fabs(z.y); // more continuous?
46
47	// addition constant
48	z.x += fractal->transformCommon.offset0;
49	z.y += fractal->transformCommon.offsetA0;
50
51	if (fractal->analyticDE.enabled)
52	{
53		if (!fractal->analyticDE.enabledFalse)
54			aux->DE = aux->DE * fractal->analyticDE.scale1 + fractal->analyticDE.offset0;
55		else
56		{
57			REAL avgScale = length(z) / length(oldZ);
58			aux->DE = aux->DE * avgScale * fractal->analyticDE.scale1 + fractal->analyticDE.offset0;
59		}
60	}
61	return z;
62}