//-----------------------------------------------------------------------
        //
        //ORIGINAL LINE: void _findAllIntersections(const Shape& STLAllocator<U, AllocPolicy>, List<IntersectionInShape>& intersections) const
        private void _findAllIntersections(Shape other, ref std_vector<IntersectionInShape> intersections) {
            for (ushort i = 0; i < getSegCount(); i++) {
                Segment2D seg1 = new Segment2D(getPoint(i), getPoint(i + 1));

                for (ushort j = 0; j < other.getSegCount(); j++) {
                    Segment2D seg2 = new Segment2D(other.getPoint(j), other.getPoint(j + 1));

                    Vector2 intersect = new Vector2();
                    if (seg1.findIntersect(seg2, ref intersect)) {
                        IntersectionInShape inter = new IntersectionInShape(i, j, intersect);
                        // check if intersection is "borderline" : too near to a vertex
                        if ((seg1.mA - intersect).SquaredLength < 1e-8) {
                            inter.onVertex[0] = true;
                        }
                        if ((seg1.mB - intersect).SquaredLength < 1e-8) {
                            inter.onVertex[0] = true;
                            inter.index[0]++;
                        }
                        if ((seg2.mA - intersect).SquaredLength < 1e-8) {
                            inter.onVertex[1] = true;
                        }
                        if ((seg2.mB - intersect).SquaredLength < 1e-8) {
                            inter.onVertex[1] = true;
                            inter.index[1]++;
                        }

                        intersections.push_back(inter);
                    }
                }
            }
        }
        //-----------------------------------------------------------------------
        //
        //ORIGINAL LINE: bool _findWhereToGo(const Shape* inputShapes[], BooleanOperationType opType, IntersectionInShape intersection, byte& shapeSelector, sbyte& isIncreasing, uint& currentSegment) const
        private bool _findWhereToGo(Shape[] inputShapes, BooleanOperationType opType, IntersectionInShape intersection, ref byte shapeSelector, ref sbyte isIncreasing, ref uint currentSegment) {
            if (intersection.onVertex[0] || intersection.onVertex[1]) {
                // determine 4 directions with normal info
                // if 2 normals "face each other" then you have the couple of outside directions
                Vector2[] directions = new Vector2[4];
                //string sides = new string(new char[4]);
                byte[] sides = new byte[4];
                byte incomingDirection;

                // fill-in the incoming arrays
                if (isIncreasing == 0) {
                    incomingDirection = 255;
                }
                else {
                    incomingDirection = (byte)(shapeSelector + (isIncreasing == 1 ? 2 : 0));
                }
                for (byte i = 0; i < 2; i++)
                    if (intersection.onVertex[i]) {
                        directions[i] = inputShapes[i].getDirectionBefore(intersection.index[i]);
                        directions[2 + i] = -inputShapes[i].getDirectionAfter(intersection.index[i]);
                    }
                    else {
                        directions[2 + i] = -inputShapes[i].getDirectionAfter(intersection.index[i]);
                        directions[i] = -directions[2 + i];
                    }
                for (byte i = 0; i < 4; i++) {
                    sides[i] = (byte)((i / 2 == 0 ? -1 : 1) * (inputShapes[i % 2].mOutSide == Side.SIDE_RIGHT ? -1 : 1));
                }

                bool[] isOutside = new bool[4];
                //std.pair<Radian, byte>[] sortedDirections = new std.pair[4];
                KeyValuePair<Radian, byte>[] sortedDirections = new KeyValuePair<Radian, byte>[4];
                // sort by angle
                for (byte i = 0; i < 4; i++) {
                    if (i == 0) {
                        //sortedDirections[i].first = 0;
                        sortedDirections[i] = new KeyValuePair<Radian, byte>(0, i);
                    }
                    else {
                        Radian first = sides[0] * Utils.angleTo(directions[0], directions[i]);
                        sortedDirections[i] = new KeyValuePair<Radian, byte>(first, i);
                    }
                    //sortedDirections[i].second=i;
                }

                //std.sort(sortedDirections, sortedDirections+4, GlobalMembersProceduralShape._sortAngles);
                //ToDo:sortedDirectionsÅÅÐò
                List<KeyValuePair<Radian, byte>> sort_sortedDirections = new List<KeyValuePair<Radian, byte>>();
                sort_sortedDirections.AddRange(sortedDirections);
                sort_sortedDirections.Sort((X, Y) => {
                    return _sortAngles(X, Y) ? -1 : 1;
                });
                sortedDirections = sort_sortedDirections.ToArray();
                //Array.Sort(sortedDirections);
                //find which segments are outside
                if (sides[0] != sides[sortedDirections[1].Value]) {
                    isOutside[0] = isOutside[sortedDirections[1].Value] = true;
                    isOutside[sortedDirections[2].Value] = isOutside[sortedDirections[3].Value] = false;
                }
                else {
                    isOutside[sortedDirections[1].Value] = isOutside[sortedDirections[2].Value] = true;
                    isOutside[sortedDirections[3].Value] = isOutside[sortedDirections[0].Value] = false;
                }

                //find first eligible segment that is not the current segment
                for (ushort i = 0; i < 4; i++)
                    if ((isOutside[i] == _isLookingForOutside(opType, (sbyte)(i % 2))) && (i != incomingDirection)) {
                        shapeSelector = (byte)(i % 2);
                        isIncreasing = (sbyte)(i / 2 == 0 ? 1 : -1);
                        currentSegment = intersection.index[shapeSelector];
                        return true;
                    }
                // if we reach here, it means that no segment is eligible! (it should only happen with difference opereation
                return false;
            }
            else {
                // determine which way to go
                int nextShapeSelector = (shapeSelector + 1) % 2;

                float d = inputShapes[nextShapeSelector].getDirectionAfter(intersection.index[nextShapeSelector]).DotProduct(inputShapes[shapeSelector].getNormalAfter(currentSegment));
                isIncreasing = _isIncreasing(d, opType, (sbyte)nextShapeSelector);

                shapeSelector = (byte)nextShapeSelector;

                currentSegment = intersection.index[shapeSelector];
                return true;
            }
        }