NearestPointFactor() public static method

public static NearestPointFactor ( Int2 lineStart, Int2 lineEnd, Int2 point ) : float
lineStart Int2
lineEnd Int2
point Int2
return float
Example #1
0
        public override Vector3 ClosestPointOnNodeXZ(Vector3 _p)
        {
            INavmeshHolder navmeshHolder = TriangleMeshNode.GetNavmeshHolder(base.GraphIndex);
            Int3           vertex        = navmeshHolder.GetVertex(this.v0);
            Int3           vertex2       = navmeshHolder.GetVertex(this.v1);
            Int3           vertex3       = navmeshHolder.GetVertex(this.v2);
            Int3           point         = (Int3)_p;
            int            y             = point.y;

            vertex.y  = 0;
            vertex2.y = 0;
            vertex3.y = 0;
            point.y   = 0;
            if ((long)(vertex2.x - vertex.x) * (long)(point.z - vertex.z) - (long)(point.x - vertex.x) * (long)(vertex2.z - vertex.z) > 0L)
            {
                float num = Mathf.Clamp01(AstarMath.NearestPointFactor(vertex, vertex2, point));
                return(new Vector3((float)vertex.x + (float)(vertex2.x - vertex.x) * num, (float)y, (float)vertex.z + (float)(vertex2.z - vertex.z) * num) * 0.001f);
            }
            if ((long)(vertex3.x - vertex2.x) * (long)(point.z - vertex2.z) - (long)(point.x - vertex2.x) * (long)(vertex3.z - vertex2.z) > 0L)
            {
                float num2 = Mathf.Clamp01(AstarMath.NearestPointFactor(vertex2, vertex3, point));
                return(new Vector3((float)vertex2.x + (float)(vertex3.x - vertex2.x) * num2, (float)y, (float)vertex2.z + (float)(vertex3.z - vertex2.z) * num2) * 0.001f);
            }
            if ((long)(vertex.x - vertex3.x) * (long)(point.z - vertex3.z) - (long)(point.x - vertex3.x) * (long)(vertex.z - vertex3.z) > 0L)
            {
                float num3 = Mathf.Clamp01(AstarMath.NearestPointFactor(vertex3, vertex, point));
                return(new Vector3((float)vertex3.x + (float)(vertex.x - vertex3.x) * num3, (float)y, (float)vertex3.z + (float)(vertex.z - vertex3.z) * num3) * 0.001f);
            }
            return(_p);
        }
        public override Vector3 ClosestPointOnNodeXZ(Vector3 _p)
        {
            // Get the object holding the vertex data for this node
            // This is usually a graph or a recast graph tile
            INavmeshHolder g = GetNavmeshHolder(GraphIndex);

            // Get all 3 vertices for this node
            Int3 tp1 = g.GetVertex(v0);
            Int3 tp2 = g.GetVertex(v1);
            Int3 tp3 = g.GetVertex(v2);

            // We need the point as an Int3
            Int3 p = (Int3)_p;

            // Save the original y coordinate, we will return a point with the same y coordinate
            int oy = p.y;

            // Assumes the triangle vertices are laid out in (counter?)clockwise order

            tp1.y = 0;
            tp2.y = 0;
            tp3.y = 0;
            p.y   = 0;

            if ((long)(tp2.x - tp1.x) * (long)(p.z - tp1.z) - (long)(p.x - tp1.x) * (long)(tp2.z - tp1.z) > 0)
            {
                float f = Mathf.Clamp01(AstarMath.NearestPointFactor(tp1, tp2, p));
                return(new Vector3(tp1.x + (tp2.x - tp1.x) * f, oy, tp1.z + (tp2.z - tp1.z) * f) * Int3.PrecisionFactor);
            }
            else if ((long)(tp3.x - tp2.x) * (long)(p.z - tp2.z) - (long)(p.x - tp2.x) * (long)(tp3.z - tp2.z) > 0)
            {
                float f = Mathf.Clamp01(AstarMath.NearestPointFactor(tp2, tp3, p));
                return(new Vector3(tp2.x + (tp3.x - tp2.x) * f, oy, tp2.z + (tp3.z - tp2.z) * f) * Int3.PrecisionFactor);
            }
            else if ((long)(tp1.x - tp3.x) * (long)(p.z - tp3.z) - (long)(p.x - tp3.x) * (long)(tp1.z - tp3.z) > 0)
            {
                float f = Mathf.Clamp01(AstarMath.NearestPointFactor(tp3, tp1, p));
                return(new Vector3(tp3.x + (tp1.x - tp3.x) * f, oy, tp3.z + (tp1.z - tp3.z) * f) * Int3.PrecisionFactor);
            }
            else
            {
                return(_p);
            }

            /*
             * Equivalent to the above, but the above uses manual inlining
             * if (!Polygon.Left (tp1, tp2, p)) {
             *      float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp1, tp2, p));
             *      return new Vector3(tp1.x + (tp2.x-tp1.x)*f, oy, tp1.z + (tp2.z-tp1.z)*f)*Int3.PrecisionFactor;
             * } else if (!Polygon.Left (tp2, tp3, p)) {
             *      float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp2, tp3, p));
             *      return new Vector3(tp2.x + (tp3.x-tp2.x)*f, oy, tp2.z + (tp3.z-tp2.z)*f)*Int3.PrecisionFactor;
             * } else if (!Polygon.Left (tp3, tp1, p)) {
             *      float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp3, tp1, p));
             *      return new Vector3(tp3.x + (tp1.x-tp3.x)*f, oy, tp3.z + (tp1.z-tp3.z)*f)*Int3.PrecisionFactor;
             * } else {
             *      return _p;
             * }*/

            /* Almost equivalent to the above, but this is slower
             * Vector3 tp1 = (Vector3)g.GetVertex(v0);
             * Vector3 tp2 = (Vector3)g.GetVertex(v1);
             * Vector3 tp3 = (Vector3)g.GetVertex(v2);
             * tp1.y = 0;
             * tp2.y = 0;
             * tp3.y = 0;
             * _p.y = 0;
             * return Pathfinding.Polygon.ClosestPointOnTriangle (tp1,tp2,tp3,_p);*/
        }
        public override Vector3 ClosestPointOnNodeXZ(Vector3 _p)
        {
            INavmeshHolder g   = GetNavmeshHolder(GraphIndex);
            Int3           tp1 = g.GetVertex(v0);
            Int3           tp2 = g.GetVertex(v1);
            Int3           tp3 = g.GetVertex(v2);

            Int3 p  = (Int3)_p;
            int  oy = p.y;

            // Assumes the triangle vertices are laid out in (counter?)clockwise order

            tp1.y = 0;
            tp2.y = 0;
            tp3.y = 0;
            p.y   = 0;

            if ((long)(tp2.x - tp1.x) * (long)(p.z - tp1.z) - (long)(p.x - tp1.x) * (long)(tp2.z - tp1.z) > 0)
            {
                float f = Mathf.Clamp01(AstarMath.NearestPointFactor(tp1, tp2, p));
                return(new Vector3(tp1.x + (tp2.x - tp1.x) * f, oy, tp1.z + (tp2.z - tp1.z) * f) * Int3.PrecisionFactor);
            }
            else if ((long)(tp3.x - tp2.x) * (long)(p.z - tp2.z) - (long)(p.x - tp2.x) * (long)(tp3.z - tp2.z) > 0)
            {
                float f = Mathf.Clamp01(AstarMath.NearestPointFactor(tp2, tp3, p));
                return(new Vector3(tp2.x + (tp3.x - tp2.x) * f, oy, tp2.z + (tp3.z - tp2.z) * f) * Int3.PrecisionFactor);
            }
            else if ((long)(tp1.x - tp3.x) * (long)(p.z - tp3.z) - (long)(p.x - tp3.x) * (long)(tp1.z - tp3.z) > 0)
            {
                float f = Mathf.Clamp01(AstarMath.NearestPointFactor(tp3, tp1, p));
                return(new Vector3(tp3.x + (tp1.x - tp3.x) * f, oy, tp3.z + (tp1.z - tp3.z) * f) * Int3.PrecisionFactor);
            }
            else
            {
                return(_p);
            }

            /*
             * Equivalent to the above, but the above uses manual inlining
             * if (!Polygon.Left (tp1, tp2, p)) {
             *      float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp1, tp2, p));
             *      return new Vector3(tp1.x + (tp2.x-tp1.x)*f, oy, tp1.z + (tp2.z-tp1.z)*f)*Int3.PrecisionFactor;
             * } else if (!Polygon.Left (tp2, tp3, p)) {
             *      float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp2, tp3, p));
             *      return new Vector3(tp2.x + (tp3.x-tp2.x)*f, oy, tp2.z + (tp3.z-tp2.z)*f)*Int3.PrecisionFactor;
             * } else if (!Polygon.Left (tp3, tp1, p)) {
             *      float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp3, tp1, p));
             *      return new Vector3(tp3.x + (tp1.x-tp3.x)*f, oy, tp3.z + (tp1.z-tp3.z)*f)*Int3.PrecisionFactor;
             * } else {
             *      return _p;
             * }*/

            /* Almost equivalent to the above, but this is slower
             * Vector3 tp1 = (Vector3)g.GetVertex(v0);
             * Vector3 tp2 = (Vector3)g.GetVertex(v1);
             * Vector3 tp3 = (Vector3)g.GetVertex(v2);
             * tp1.y = 0;
             * tp2.y = 0;
             * tp3.y = 0;
             * _p.y = 0;
             * return Pathfinding.Polygon.ClosestPointOnTriangle (tp1,tp2,tp3,_p);*/
        }
Example #4
0
            public bool FinalInts(Vector3 target, Vector3 closeEdgeConstraint, bool drawGizmos, out Vector3 closest)
            {
                ints1.Sort();
                ints2.Sort();
                ints3.Sort();

                float a = (float)Math.Atan2(direction.z, direction.x);

                Vector3 cross = Vector3.Cross(direction, Vector3.up);
                Vector3 p1    = cross * (float)Math.Tan(angle) * limit;

                Vector3 pLeft  = origin + direction * limit + p1;
                Vector3 pRight = origin + direction * limit - p1;

                Vector3 pLeft2  = pLeft + new Vector3((float)Math.Cos(a + angle), 0, (float)Math.Sin(a + angle)) * 100;
                Vector3 pRight2 = pRight + new Vector3((float)Math.Cos(a - angle), 0, (float)Math.Sin(a - angle)) * 100;

                bool anyCloseFound = false;

                closest = Vector3.zero;

                int IgnoreDirection = Vector3.Dot(closeEdgeConstraint - origin, cross) > 0 ? 2 : 1;               //(pRight-(transform.position+velocity)).sqrMagnitude < (pLeft-(transform.position+velocity)).sqrMagnitude ? 2 : 1;//Vector3.Dot (pRight-pLeft,target-pLeft) > 0 ? 1 : 2;

                for (int j = 1; j <= 3; j++)
                {
                    if (j == IgnoreDirection)
                    {
                        continue;
                    }

                    List <IntersectionPair> ints = j == 1 ? ints1 : (j == 2 ? ints2 : ints3);

                    /*IntersectionState prevInside = ints[0].state;
                     * if (ints[0].state == IntersectionState.Outside) {
                     *      ints[0].SetState (IntersectionState.Exit);
                     * }*/

                    /*for (int i=1;i<ints.Count;i++) {
                     *      Debug.Log ("Intersection at "+j+", "+i+" : "+ints[i].factor);
                     *      prevInside = ints[i].state;
                     *      if (prevInside == IntersectionState.Outside) {
                     *              ints[i].SetState (IntersectionState.Enter);
                     *      } else if (prevInside == IntersectionState.Inside) {
                     *              ints[i].SetState (ints[i].state == IntersectionState.Inside ? IntersectionState.Inside : IntersectionState.Exit);
                     *      }
                     * }
                     * if (ints[ints.Count-1].state == IntersectionState.Exit) {
                     *      ints.Add (new IntersectionPair (1,false));
                     * }*/

                    Vector3 start = (j == 1 || j == 3 ? pLeft : pRight);
                    Vector3 end   = (j == 1 ? pLeft2 : (j == 2 ? pRight2 : pRight));

                    float closestFactor = AstarMath.NearestPointFactor(start, end, target);

                    float closeMin = float.PositiveInfinity;
                    float closeMax = float.NegativeInfinity;

                    bool anySegmClose = false;
                    for (int i = 0; i < ints.Count - (j == 3 ? 1 : 0); i++)
                    {
                        if (drawGizmos)
                        {
                            Debug.DrawRay(start + (end - start) * ints[i].factor, Vector3.down, ints[i].state == IntersectionState.Outside ? Color.green : Color.red);
                        }
                        if (ints[i].state == IntersectionState.Outside && ((i == ints.Count - 1 && (i == 0 || ints[i - 1].state != IntersectionState.Outside)) || (i < ints.Count - 1 && ints[i + 1].state == IntersectionState.Outside)))
                        {
                            anySegmClose = true;
                            float startFactor = ints[i].factor;
                            float endFactor   = i == ints.Count - 1 ? (j == 3 ? 1 : float.PositiveInfinity) : ints[i + 1].factor;


                            if (drawGizmos)
                            {
                                Debug.DrawLine(start + (end - start) * startFactor + Vector3.up, start + (end - start) * Mathf.Clamp01(endFactor) + Vector3.up, Color.green);
                            }

                            if (startFactor <= closestFactor && endFactor >= closestFactor)
                            {
                                closeMin = closestFactor;
                                closeMax = closestFactor;
                                break;
                            }
                            else if (endFactor < closestFactor && endFactor > closeMax)
                            {
                                closeMax = endFactor;
                            }
                            else if (startFactor > closestFactor && startFactor < closeMin)
                            {
                                closeMin = startFactor;
                            }
                        }
                    }

                    if (anySegmClose)
                    {
                        //The closest factor
                        float closeV = closeMin == float.NegativeInfinity ? closeMax : (closeMax == float.PositiveInfinity ? closeMin : (Mathf.Abs(closestFactor - closeMin) < Mathf.Abs(closestFactor - closeMax) ? closeMin : closeMax));

                        /*if (Mathf.Abs(closestFactor-closeMin) < Mathf.Abs(closestFactor-closeMax)) {
                         *      segmClose = start+ (end-start)*closeMin;
                         * } else {
                         *      segmClose = start+ (end-start)*closeMax;
                         * }*/
                        Vector3 segmClose = start + (end - start) * closeV;

                        if (!anyCloseFound || (segmClose - target).sqrMagnitude < (closest - target).sqrMagnitude)
                        {
                            closest = segmClose;
                        }
                        if (drawGizmos)
                        {
                            Debug.DrawLine(target, closest, Color.yellow);
                        }

                        anyCloseFound = true;
                    }
                }

                return(anyCloseFound);
            }
            public bool FinalInts(Vector3 target, Vector3 closeEdgeConstraint, bool drawGizmos, out Vector3 closest)
            {
                this.ints1.Sort();
                this.ints2.Sort();
                this.ints3.Sort();
                float   num     = (float)Math.Atan2((double)this.direction.z, (double)this.direction.x);
                Vector3 vector  = Vector3.Cross(this.direction, Vector3.up);
                Vector3 b       = vector * (float)Math.Tan((double)this.angle) * this.limit;
                Vector3 vector2 = this.origin + this.direction * this.limit + b;
                Vector3 vector3 = this.origin + this.direction * this.limit - b;
                Vector3 vector4 = vector2 + new Vector3((float)Math.Cos((double)(num + this.angle)), 0f, (float)Math.Sin((double)(num + this.angle))) * 100f;
                Vector3 vector5 = vector3 + new Vector3((float)Math.Cos((double)(num - this.angle)), 0f, (float)Math.Sin((double)(num - this.angle))) * 100f;
                bool    flag    = false;

                closest = Vector3.zero;
                int num2 = (Vector3.Dot(closeEdgeConstraint - this.origin, vector) <= 0f) ? 1 : 2;

                for (int i = 1; i <= 3; i++)
                {
                    if (i != num2)
                    {
                        List <LocalAvoidance.IntersectionPair> list = (i != 1) ? ((i != 2) ? this.ints3 : this.ints2) : this.ints1;
                        Vector3 vector6 = (i != 1 && i != 3) ? vector3 : vector2;
                        Vector3 vector7 = (i != 1) ? ((i != 2) ? vector3 : vector5) : vector4;
                        float   num3    = AstarMath.NearestPointFactor(vector6, vector7, target);
                        float   num4    = float.PositiveInfinity;
                        float   num5    = float.NegativeInfinity;
                        bool    flag2   = false;
                        for (int j = 0; j < list.Count - ((i != 3) ? 0 : 1); j++)
                        {
                            if (drawGizmos)
                            {
                                Debug.DrawRay(vector6 + (vector7 - vector6) * list[j].factor, Vector3.down, (list[j].state != LocalAvoidance.IntersectionState.Outside) ? Color.red : Color.green);
                            }
                            if (list[j].state == LocalAvoidance.IntersectionState.Outside && ((j == list.Count - 1 && (j == 0 || list[j - 1].state != LocalAvoidance.IntersectionState.Outside)) || (j < list.Count - 1 && list[j + 1].state == LocalAvoidance.IntersectionState.Outside)))
                            {
                                flag2 = true;
                                float factor = list[j].factor;
                                float num6   = (j != list.Count - 1) ? list[j + 1].factor : ((i != 3) ? float.PositiveInfinity : 1f);
                                if (drawGizmos)
                                {
                                    Debug.DrawLine(vector6 + (vector7 - vector6) * factor + Vector3.up, vector6 + (vector7 - vector6) * Mathf.Clamp01(num6) + Vector3.up, Color.green);
                                }
                                if (factor <= num3 && num6 >= num3)
                                {
                                    num4 = num3;
                                    num5 = num3;
                                    break;
                                }
                                if (num6 < num3 && num6 > num5)
                                {
                                    num5 = num6;
                                }
                                else if (factor > num3 && factor < num4)
                                {
                                    num4 = factor;
                                }
                            }
                        }
                        if (flag2)
                        {
                            float   d       = (num4 != float.NegativeInfinity) ? ((num5 != float.PositiveInfinity) ? ((Mathf.Abs(num3 - num4) >= Mathf.Abs(num3 - num5)) ? num5 : num4) : num4) : num5;
                            Vector3 vector8 = vector6 + (vector7 - vector6) * d;
                            if (!flag || (vector8 - target).sqrMagnitude < (closest - target).sqrMagnitude)
                            {
                                closest = vector8;
                            }
                            if (drawGizmos)
                            {
                                Debug.DrawLine(target, closest, Color.yellow);
                            }
                            flag = true;
                        }
                    }
                }
                return(flag);
            }
Example #6
0
        public void Apply(bool forceNewCheck)
        {
            //TODO
            //This function assumes that connections from the n1,n2 nodes never need to be removed in the future (e.g because the nodes move or something)
            NNConstraint nn = NNConstraint.None;

            nn.distanceXZ = true;
            int graph = (int)startNode.GraphIndex;

            //Search all graphs but the one which start and end nodes are on
            nn.graphMask = ~(1 << graph);

            bool same = true;

            if (true)
            {
                NNInfo n1 = AstarPath.active.GetNearest(StartTransform.position, nn);
                same          &= n1.node == connectedNode1 && n1.node != null;
                connectedNode1 = n1.node as MeshNode;
                clamped1       = n1.clampedPosition;
                if (connectedNode1 != null)
                {
                    Debug.DrawRay((Vector3)connectedNode1.position, Vector3.up * 5, Color.red);
                }
            }

            if (true)
            {
                NNInfo n2 = AstarPath.active.GetNearest(EndTransform.position, nn);
                same          &= n2.node == connectedNode2 && n2.node != null;
                connectedNode2 = n2.node as MeshNode;
                clamped2       = n2.clampedPosition;
                if (connectedNode2 != null)
                {
                    Debug.DrawRay((Vector3)connectedNode2.position, Vector3.up * 5, Color.cyan);
                }
            }

            if (connectedNode2 == null || connectedNode1 == null)
            {
                return;
            }

            startNode.SetPosition((Int3)StartTransform.position);
            endNode.SetPosition((Int3)EndTransform.position);

            if (same && !forceNewCheck)
            {
                return;
            }

            RemoveConnections(startNode);
            RemoveConnections(endNode);

            uint cost = (uint)Mathf.RoundToInt(((Int3)(StartTransform.position - EndTransform.position)).costMagnitude * costFactor);

            startNode.AddConnection(endNode, cost);
            endNode.AddConnection(startNode, cost);

            Int3 dir = connectedNode2.position - connectedNode1.position;

            for (int a = 0; a < connectedNode1.GetVertexCount(); a++)
            {
                Int3 va1 = connectedNode1.GetVertex(a);
                Int3 va2 = connectedNode1.GetVertex((a + 1) % connectedNode1.GetVertexCount());

                if (Int3.DotLong((va2 - va1).Normal2D(), dir) > 0)
                {
                    continue;
                }

                for (int b = 0; b < connectedNode2.GetVertexCount(); b++)
                {
                    Int3 vb1 = connectedNode2.GetVertex(b);
                    Int3 vb2 = connectedNode2.GetVertex((b + 1) % connectedNode2.GetVertexCount());

                    if (Int3.DotLong((vb2 - vb1).Normal2D(), dir) < 0)
                    {
                        continue;
                    }


                    //Debug.DrawLine ((Vector3)va1, (Vector3)va2, Color.magenta);
                    //Debug.DrawLine ((Vector3)vb1, (Vector3)vb2, Color.cyan);
                    //Debug.Break ();

                    if (Int3.Angle((vb2 - vb1), (va2 - va1)) > (170.0 / 360.0f) * Mathf.PI * 2)
                    {
                        float t1 = 0;
                        float t2 = 1;

                        t2 = System.Math.Min(t2, AstarMath.NearestPointFactor(va1, va2, vb1));
                        t1 = System.Math.Max(t1, AstarMath.NearestPointFactor(va1, va2, vb2));

                        if (t2 < t1)
                        {
                            Debug.LogError("Wait wut!? " + t1 + " " + t2 + " " + va1 + " " + va2 + " " + vb1 + " " + vb2 + "\nTODO, fix this error");
                        }
                        else
                        {
                            Vector3 pa = (Vector3)(va2 - va1) * t1 + (Vector3)va1;
                            Vector3 pb = (Vector3)(va2 - va1) * t2 + (Vector3)va1;

                            startNode.portalA = pa;
                            startNode.portalB = pb;

                            endNode.portalA = pb;
                            endNode.portalB = pa;

                            //Add connections between nodes, or replace old connections if existing
                            connectedNode1.AddConnection(startNode, (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude * costFactor));
                            connectedNode2.AddConnection(endNode, (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude * costFactor));

                            startNode.AddConnection(connectedNode1, (uint)Mathf.RoundToInt(((Int3)(clamped1 - StartTransform.position)).costMagnitude * costFactor));
                            endNode.AddConnection(connectedNode2, (uint)Mathf.RoundToInt(((Int3)(clamped2 - EndTransform.position)).costMagnitude * costFactor));

                            return;
                        }
                    }
                }
            }
        }
        // Token: 0x060001D7 RID: 471 RVA: 0x00012314 File Offset: 0x00010714
        public void Apply(bool forceNewCheck)
        {
            NNConstraint none = NNConstraint.None;

            none.distanceXZ = true;
            int graphIndex = (int)this.startNode.GraphIndex;

            none.graphMask = ~(1 << graphIndex);
            bool   flag    = true;
            NNInfo nearest = AstarPath.active.GetNearest(this.StartTransform.position, none);

            flag &= (nearest.node == this.connectedNode1 && nearest.node != null);
            this.connectedNode1 = (nearest.node as MeshNode);
            this.clamped1       = nearest.clampedPosition;
            if (this.connectedNode1 != null)
            {
                Debug.DrawRay((Vector3)this.connectedNode1.position, Vector3.up * 5f, Color.red);
            }
            NNInfo nearest2 = AstarPath.active.GetNearest(this.EndTransform.position, none);

            flag &= (nearest2.node == this.connectedNode2 && nearest2.node != null);
            this.connectedNode2 = (nearest2.node as MeshNode);
            this.clamped2       = nearest2.clampedPosition;
            if (this.connectedNode2 != null)
            {
                Debug.DrawRay((Vector3)this.connectedNode2.position, Vector3.up * 5f, Color.cyan);
            }
            if (this.connectedNode2 == null || this.connectedNode1 == null)
            {
                return;
            }
            this.startNode.SetPosition((Int3)this.StartTransform.position);
            this.endNode.SetPosition((Int3)this.EndTransform.position);
            if (flag && !forceNewCheck)
            {
                return;
            }
            this.RemoveConnections(this.startNode);
            this.RemoveConnections(this.endNode);
            uint cost = (uint)Mathf.RoundToInt((float)((Int3)(this.StartTransform.position - this.EndTransform.position)).costMagnitude * this.costFactor);

            this.startNode.AddConnection(this.endNode, cost);
            this.endNode.AddConnection(this.startNode, cost);
            Int3 rhs = this.connectedNode2.position - this.connectedNode1.position;

            for (int i = 0; i < this.connectedNode1.GetVertexCount(); i++)
            {
                Int3 vertex  = this.connectedNode1.GetVertex(i);
                Int3 vertex2 = this.connectedNode1.GetVertex((i + 1) % this.connectedNode1.GetVertexCount());
                if (Int3.DotLong((vertex2 - vertex).Normal2D(), rhs) <= 0L)
                {
                    for (int j = 0; j < this.connectedNode2.GetVertexCount(); j++)
                    {
                        Int3 vertex3 = this.connectedNode2.GetVertex(j);
                        Int3 vertex4 = this.connectedNode2.GetVertex((j + 1) % this.connectedNode2.GetVertexCount());
                        if (Int3.DotLong((vertex4 - vertex3).Normal2D(), rhs) >= 0L)
                        {
                            if ((double)Int3.Angle(vertex4 - vertex3, vertex2 - vertex) > 2.9670598109563189)
                            {
                                float num  = 0f;
                                float num2 = 1f;
                                num2 = Math.Min(num2, AstarMath.NearestPointFactor(vertex, vertex2, vertex3));
                                num  = Math.Max(num, AstarMath.NearestPointFactor(vertex, vertex2, vertex4));
                                if (num2 >= num)
                                {
                                    Vector3 vector  = (Vector3)(vertex2 - vertex) * num + (Vector3)vertex;
                                    Vector3 vector2 = (Vector3)(vertex2 - vertex) * num2 + (Vector3)vertex;
                                    this.startNode.portalA = vector;
                                    this.startNode.portalB = vector2;
                                    this.endNode.portalA   = vector2;
                                    this.endNode.portalB   = vector;
                                    this.connectedNode1.AddConnection(this.startNode, (uint)Mathf.RoundToInt((float)((Int3)(this.clamped1 - this.StartTransform.position)).costMagnitude * this.costFactor));
                                    this.connectedNode2.AddConnection(this.endNode, (uint)Mathf.RoundToInt((float)((Int3)(this.clamped2 - this.EndTransform.position)).costMagnitude * this.costFactor));
                                    this.startNode.AddConnection(this.connectedNode1, (uint)Mathf.RoundToInt((float)((Int3)(this.clamped1 - this.StartTransform.position)).costMagnitude * this.costFactor));
                                    this.endNode.AddConnection(this.connectedNode2, (uint)Mathf.RoundToInt((float)((Int3)(this.clamped2 - this.EndTransform.position)).costMagnitude * this.costFactor));
                                    return;
                                }
                                Debug.LogError(string.Concat(new object[]
                                {
                                    "Wait wut!? ",
                                    num,
                                    " ",
                                    num2,
                                    " ",
                                    vertex,
                                    " ",
                                    vertex2,
                                    " ",
                                    vertex3,
                                    " ",
                                    vertex4,
                                    "\nTODO, fix this error"
                                }));
                            }
                        }
                    }
                }
            }
        }