/* Debug */

        /*public List<Bezier2> debugDraw = new List<Bezier2>();
         * public List<Vector3> debugDrawPositions = new List<Vector3>();
         * bool yes = true; // :)*/

        public void BuildEllipse()
        {
            if (ellipse == null)
            {
                UIWindow2.instance.ThrowErrorMsg("Invalid radii!");
            }

            Ellipse toBeBuiltEllipse   = ellipse;
            Ellipse ellipseWithPadding = ellipse;

            /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the
             * graph traveller are not too short. They will be at least as long as the padding. */
            if (RoundAboutBuilder.UseOldSnappingAlgorithm.value)
            {
                ellipseWithPadding = new Ellipse(NetAccess.Node(centralNode).m_position, NetAccess.Node(axisNode).m_position - NetAccess.Node(centralNode).m_position, prevRadius1 + DISTANCE_PADDING, prevRadius2 + DISTANCE_PADDING);
            }

            UIWindow2.instance.LostFocus();
            UIWindow2.instance.GoBack();

            try
            {
                GraphTraveller2    traveller      = new GraphTraveller2(centralNode, ellipseWithPadding);
                EdgeIntersections2 intersections  = new EdgeIntersections2(traveller, centralNode, toBeBuiltEllipse);
                FinalConnector     finalConnector = new FinalConnector(NetAccess.Node(centralNode).Info, intersections, toBeBuiltEllipse, ControlVertices);

                // Easter egg
                RoundAboutBuilder.EasterEggToggle();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UIWindow2.instance.ThrowErrorMsg(e.ToString(), true);
            }
        }
        /* This draws the UI circles on the map */
        protected override void RenderOverlayExtended(RenderManager.CameraInfo cameraInfo)
        {
            try
            {
                if (m_hoverNode != 0)
                {
                    NetNode hoveredNode = NetAccess.Node(m_hoverNode);

                    // kinda stole this color from Move It!
                    // thanks to SamsamTS because they're a UI god
                    // ..and then Strad stole it from all of you!!
                    RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.black, hoveredNode.m_position, 15f, hoveredNode.m_position.y - 1f, hoveredNode.m_position.y + 1f, true, true);
                    float?radius = UIWindow2.instance.P_RoundAboutPanel.RadiusField.Value;
                    if (radius != null)
                    {
                        float roadWidth        = UIWindow2.instance.dropDown.Value.m_halfWidth; // There is a slight chance that this will throw an exception
                        float innerCirleRadius = radius - roadWidth > 0 ? 2 * ((float)radius - roadWidth) : 2 * (float)radius;
                        RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.red, hoveredNode.m_position, innerCirleRadius, hoveredNode.m_position.y - 2f, hoveredNode.m_position.y + 2f, true, true);
                        RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.red, hoveredNode.m_position, 2 * ((float)radius + roadWidth /*DISTANCE_PADDING - 5*/), hoveredNode.m_position.y - 1f, hoveredNode.m_position.y + 1f, true, true);
                    }
                    //RenderDirectionVectors(cameraInfo);
                    RenderHoveringLabel("Click to build\nPress +/- to adjust radius");
                }
                else
                {
                    RenderMousePositionCircle(cameraInfo);
                    RenderHoveringLabel("Hover mouse over intersection");
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
        }
        //string m_radiusField.text = RADIUS_DEF.ToString();

        /* Main method , called when user cliks on a node to create a roundabout */
        public void CreateRoundabout(ushort nodeID)
        {
            //Debug.Log(string.Format("Clicked on node ID {0}!", nodeID));

            float?radiusQ = UIWindow2.instance.P_RoundAboutPanel.RadiusField.Value;

            if (radiusQ == null)
            {
                UIWindow2.instance.ThrowErrorMsg("Radius out of bounds!");
                return;
            }

            float radius = (float)radiusQ;

            if (!UIWindow2.instance.keepOpen)
            {
                UIWindow2.instance.LostFocus();
            }

            /* These lines of code do all the work. See documentation in respective classes. */

            /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the
             * graph traveller are not too short. They will be at least as long as the padding. */
            Ellipse ellipse            = new Ellipse(NetAccess.Node(nodeID).m_position, new Vector3(0f, 0f, 0f), radius, radius);
            Ellipse ellipseWithPadding = ellipse;

            if (RoundAboutBuilder.UseOldSnappingAlgorithm.value)
            {
                ellipseWithPadding = new Ellipse(NetAccess.Node(nodeID).m_position, new Vector3(0f, 0f, 0f), radius + DISTANCE_PADDING, radius + DISTANCE_PADDING);
            }


            try
            {
                GraphTraveller2    traveller;
                EdgeIntersections2 intersections = null;
                if (!RoundAboutBuilder.DoNotRemoveAnyRoads)
                {
                    traveller     = new GraphTraveller2(nodeID, ellipse);
                    intersections = new EdgeIntersections2(traveller, nodeID, ellipse);
                }
                FinalConnector finalConnector = new FinalConnector(NetAccess.Node(nodeID).Info, intersections, ellipse, true);

                // Easter egg
                RoundAboutBuilder.EasterEggToggle();

                // Debug, don't forget to remove

                /*foreach(VectorNodeStruct intersection in intersections.Intersections)
                 * {
                 *  Debug.Log($"May have/Has restrictions: {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.MayHaveJunctionRestrictions(intersection.nodeId)}, {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.HasJunctionRestrictions(intersection.nodeId)}");
                 * }*/
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UIWindow2.instance.ThrowErrorMsg(e.ToString(), true);
            }
        }
        /* This draws UI shapes on the map. */
        protected override void RenderOverlayExtended(RenderManager.CameraInfo cameraInfo)
        {
            //debugDrawMethod(cameraInfo);
            try
            {
                if (m_hoverNode != 0 && (stage == Stage.CentralPoint || stage == Stage.MainAxis))
                {
                    NetNode hoveredNode = NetAccess.Node(m_hoverNode);
                    RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.black, hoveredNode.m_position, 15f, hoveredNode.m_position.y - 1f, hoveredNode.m_position.y + 1f, true, true);
                    UIWindow2.instance.m_hoveringLabel.isVisible = false;
                }
                else if (stage == Stage.CentralPoint)
                {
                    RenderMousePositionCircle(cameraInfo);
                    RenderHoveringLabel("Select center of elliptic roundabout");
                }
                else if (stage == Stage.MainAxis)
                {
                    RenderMousePositionCircle(cameraInfo);
                    RenderHoveringLabel("Select any intersection in direction of main axis");
                }
                else
                {
                    UIWindow2.instance.m_hoveringLabel.isVisible = false;
                }

                if (stage == Stage.MainAxis || stage == Stage.Final)
                {
                    NetNode centralNodeDraw = NetAccess.Node(centralNode);
                    RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.red, centralNodeDraw.m_position, 15f, centralNodeDraw.m_position.y - 1f, centralNodeDraw.m_position.y + 1f, true, true);
                }
                if (stage == Stage.Final)
                {
                    NetNode axisNodeDraw = NetAccess.Node(axisNode);
                    RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.green, axisNodeDraw.m_position, 15f, axisNodeDraw.m_position.y - 1f, axisNodeDraw.m_position.y + 1f, true, true);

                    if (Radius(out float radius1, out float radius2))
                    {
                        /* If the radiuses didn't change, we don't have to generate new ellipse. */
                        if (radius1 == prevRadius1 && radius2 == prevRadius2 && ellipse != null)
                        {
                            DrawEllipse(cameraInfo);
                        }
                        else
                        {
                            prevRadius1 = radius1;
                            prevRadius2 = radius2;
                            ellipse     = new Ellipse(NetAccess.Node(centralNode).m_position, NetAccess.Node(axisNode).m_position - NetAccess.Node(centralNode).m_position, radius1, radius2);
                            DrawEllipse(cameraInfo);
                        }
                    }
                    else
                    {
                        ellipse = null;
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Log("Catched exception while rendering ellipse UI.");
                Debug.Log(e);
                stage   = Stage.CentralPoint;
                enabled = false; // ???
            }
        }