public RoomSplit(Room a, Room b, SplitDirection direction, int coordinate)
 {
     this.a          = a;
     this.b          = b;
     this.direction  = direction;
     this.coordinate = coordinate;
 }
Example #2
0
        /// <summary>
        /// Checks the current gui event to determine if the user is currently
        /// resizing the view
        /// </summary>
        /// <param name="handleRect">Where the grab area is located</param>
        /// <param name="splitDirection">The direction of the split</param>
        private void CheckIsResizing(Rect handleRect, SplitDirection splitDirection)
        {
            if (Event.current.type == EventType.MouseDown &&
                handleRect.Contains(Event.current.mousePosition))
            {
                isResizing = true;
            }

            if (isResizing && availableRect.width > 0f)
            {
                if (splitDirection == SplitDirection.Horizontal)
                {
                    normalizedSplitPosition = Event.current.mousePosition.x / availableRect.width;
                }
                else
                {
                    normalizedSplitPosition = Event.current.mousePosition.y / availableRect.height;
                }

                normalizedSplitPosition = Mathf.Clamp(normalizedSplitPosition,
                                                      normalizedMinMargin, normalizedMaxMargin);
            }

            if (Event.current.rawType == EventType.MouseUp)
            {
                isResizing = false;
            }
        }
Example #3
0
        private void AdjustmentCollider(GameObject colliderGameObject, SplitDirection splitDirection)
        {
            var collider = colliderGameObject.GetComponent <BoxCollider>();

            if (collider == null)
            {
                return;
            }

            // ReSize
            var colSize = collider.size;

            colSize.x    /= 2f;
            collider.size = colSize;

            // ReCenter
            var mesh = colliderGameObject.GetComponent <MeshFilter>().mesh;

            var vertices = mesh.vertices;

            var xMax           = vertices.Max(v => v.x);
            var xMin           = vertices.Min(v => v.x);
            var centerPosition = (xMin + xMax) / 2f;

            var colCenter = collider.center;

            colCenter.x     = centerPosition;
            collider.center = colCenter;
        }
Example #4
0
        /// <summary>
        /// Splits (divides) the surface into two parts at the specified parameter
        /// </summary>
        /// <param name="parameter">The parameter at which to split the surface, parameter should be between 0 and 1.</param>
        /// <param name="direction">Where to split in the U or V direction of the surface.</param>
        /// <returns>If the surface is split vertically (U direction) the left side is returned as the first surface and the right side is returned as the second surface.<br/>
        /// If the surface is split horizontally (V direction) the bottom side is returned as the first surface and the top side is returned as the second surface.</returns>
        public NurbsSurface[] SplitAt(double parameter, SplitDirection direction)
        {
            if (parameter < 0.0 || parameter > 1.0)
            {
                throw new ArgumentOutOfRangeException(nameof(parameter), "The parameter is not into the domain 0.0 to 1.0.");
            }

            return(Sampling.Surface.Split(this, parameter, direction));
        }
Example #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="direction">Direction of the split</param>
        /// <param name="initialNormalizedSplitPosition">Where to start the split</param>
        /// <param name="minSizeConstraint">Any positive value to constrain the smallest
        /// allowable size for the first window</param>
        /// /// <param name="maxSizeConstraint">Any positive value to constrain the largest
        /// allowable size for the first window</param>
        public SplitViewLayout(SplitDirection direction,
                               float initialNormalizedSplitPosition = 0.5f, float minSizeConstraint = NO_CONSTRAINT,
                               float maxSizeConstraint = NO_CONSTRAINT)
        {
            splitDirection          = direction;
            normalizedSplitPosition = initialNormalizedSplitPosition;

            MinSize = minSizeConstraint;
            MaxSize = maxSizeConstraint;
        }
Example #6
0
        public SplitComponent(SplitDirection direction, float splitPercentage = 50)
        {
            var horiz = direction == SplitDirection.Horizontal;

            splitPercentage = 100 - splitPercentage;
            RootElement     = new jQuery("<div>").AddClass("split-pane", horiz ? "horizontal-percent" : "vertical-percent");
            RootElement.Append(firstContentElement = new jQuery("<div>").AddClass("split-pane-component").Css(horiz ? "bottom" : "right", $"{splitPercentage}%"));
            RootElement.Append(new jQuery("<div>").AddClass("split-pane-divider").Css(horiz ? "bottom" : "right", $"{splitPercentage}%"));
            RootElement.Append(secondContentElement = new jQuery("<div>").AddClass("split-pane-component").Css(horiz ? "height" : "width", $"{splitPercentage}%"));
            ((dynamic)RootElement).splitPane();
        }
Example #7
0
        public void Split(float splitCoordinate, SplitDirection direction, out BoundingBox boundingBox1, out BoundingBox boundingBox2)
        {
            if ((splitCoordinate <= 0) || (splitCoordinate >= 1))
            {
                throw new ArgumentException("The argument splitCoordinate must be between 0 and 1, excluding both.");
            }

            if (direction == SplitDirection.X)
            {
                boundingBox1 = new BoundingBox(this._Position, this._Width * splitCoordinate, this._Hight);
                boundingBox2 = new BoundingBox(new Point(this._Position.X + (splitCoordinate * this._Width), this._Position.Y), this._Width - (this._Width * splitCoordinate), this._Hight);
                foreach (Shape singleShape in this._Shapes)
                {
                    if (singleShape.Position.X < this._Position.X + (splitCoordinate * this._Width))
                    {
                        boundingBox1.Shapes.Add(singleShape);

                        if (singleShape.OutherPoint.X > this._Position.X + (splitCoordinate * this._Width))
                        {
                            boundingBox2.Shapes.Add(singleShape);
                        }
                    }
                    else
                    {
                        boundingBox2.Shapes.Add(singleShape);
                    }
                }
            }
            else
            {
                boundingBox1 = new BoundingBox(this._Position, this._Width, this._Hight * splitCoordinate);
                boundingBox2 = new BoundingBox(new Point(this._Position.X, this._Position.Y - (this._Hight * splitCoordinate)), this._Width, this._Hight - (this._Hight - (this._Hight * splitCoordinate)));
                foreach (Shape singleShape in this._Shapes)
                {
                    if (singleShape.Position.Y > this._Position.Y - (splitCoordinate * this._Hight))
                    {
                        boundingBox1.Shapes.Add(singleShape);

                        if (singleShape.BottomPoint.Y < this._Position.Y - (splitCoordinate * this._Hight))
                        {
                            boundingBox2.Shapes.Add(singleShape);
                        }
                    }
                    else
                    {
                        boundingBox2.Shapes.Add(singleShape);
                    }
                }
            }
        }
Example #8
0
        /// <inheritdoc />
        /// <summary>
        /// Split the <paramref name="selectedFreeRectangle"/> by it's longer axis
        /// </summary>
        /// <param name="selectedFreeRectangle">The free rectangle that was selected for a placement of <paramref name="rectToBePlaced"/></param>
        /// <param name="rectToBePlaced">The rectangle that should be placed</param>
        /// <returns>Free rectangle that results from the splitting of <paramref name="selectedFreeRectangle"/></returns>
        public IEnumerable <PPRect> SplitFreeRectangle(PPRect selectedFreeRectangle, PPRect rectToBePlaced)
        {
            SplitDirection splitDirection = SelectSplitDirection(/*selectedFreeRectangle, */ rectToBePlaced);

            switch (splitDirection)
            {
            case SplitDirection.HORIZONTAL:
                return(SplitFreeRectangleHorizontal(ref selectedFreeRectangle, rectToBePlaced));

            case SplitDirection.VERTICAL:
                return(SplitFreeRectangleVertical(ref selectedFreeRectangle, rectToBePlaced));

            default:
                throw new InvalidOperationException();
            }
        }
Example #9
0
        private static int RecurseAndPredict(LabeledPoint point, DecisionTreeNode node, DecisionTreeOptions options)
        {
            if (node.IsLeaf)
            {
                return(node.Class);
            }
            else
            {
                SplitDirection direction = ComputeSplitDirection(point, node.Question, options);

                if (direction == SplitDirection.Left)
                {
                    return(RecurseAndPredict(point, node.LeftBranch, options));
                }
                else
                {
                    return(RecurseAndPredict(point, node.RightBranch, options));
                }
            }
        }
Example #10
0
    void Start()
    {
        PlayerPrefs.SetInt("GameScore", 0);
        LevelEndUI.SetActive(false);
        // get the seed from the playerPrefs. If none, assume the name is Shantanu and store it cuz why not

        seed = PlayerPrefs.GetString("Name");
        if (seed.Length == 0)
        {
            seed = "ThankGodForJimSterling";
        }

        // get references in-script
        player = GameObject.FindGameObjectWithTag("Player");


        // start-of-game conditions
        currentLevel = 0;
        DIR          = SplitDirection.HORIZONTAL; // starter
        BSP_initLevel();
    }
Example #11
0
        private void AdjustmentMesh(GameObject meshGameObject, SplitDirection splitDirection)
        {
            var mesh = meshGameObject.GetComponent <MeshFilter>().mesh;

            if (mesh == null)
            {
                return;
            }

            var vertices = mesh.vertices;

            var xMax           = vertices.Max(v => v.x);
            var xMin           = vertices.Min(v => v.x);
            var centerPosition = (xMin + xMax) / 2f;

            for (var i = 0; i < vertices.Length; i++)
            {
                switch (splitDirection)
                {
                case SplitDirection.Left:
                    if (vertices[i].x >= centerPosition)
                    {
                        vertices[i].x = centerPosition;
                    }
                    break;

                case SplitDirection.Right:
                    if (vertices[i].x <= centerPosition)
                    {
                        vertices[i].x = centerPosition;
                    }
                    break;
                }
            }

            mesh.vertices = vertices;
            mesh.RecalculateBounds();
        }
Example #12
0
        private static void RecurseAndPartition(List <LabeledPoint> trainingPoints, List <SplittingQuestion> splittingQuestions,
                                                int currentRecursionLevel, DecisionTreeOptions options, DecisionTreeNode currentNode, Random random)
        {
            Console.WriteLine($"{new String('-', currentRecursionLevel)}{currentRecursionLevel}");

            if (currentRecursionLevel >= options.MaximumNumberOfRecursionLevels)
            {
                // create leaf node
                MakeLeafNode(currentNode, trainingPoints);
            }
            else
            {
                double            currentShannonEntropy = ComputeShannonEntropy(trainingPoints);
                double            highestGain           = double.MinValue;
                SplittingQuestion bestSplittingQuestion = null;

                //for (int s = 0; s < splittingQuestions.Count; s++)
                Parallel.For(0, splittingQuestions.Count, s =>
                {
                    //Console.Write(".");
                    //Interlocked.Increment(ref t);
                    //Console.WriteLine($"{t}/{splittingQuestions.Count}");

                    //List<LabeledPoint> leftBucket1 = new List<LabeledPoint>();
                    //List<LabeledPoint> rightBucket1 = new List<LabeledPoint>();

                    List <LabeledPointGroup> leftBucket = new List <LabeledPointGroup>();
                    leftBucket.Add(new LabeledPointGroup
                    {
                        Count = 0,
                        Class = 0
                    });
                    leftBucket.Add(new LabeledPointGroup
                    {
                        Count = 0,
                        Class = 1
                    });
                    List <LabeledPointGroup> rightBucket = new List <LabeledPointGroup>();
                    rightBucket.Add(new LabeledPointGroup
                    {
                        Count = 0,
                        Class = 0
                    });
                    rightBucket.Add(new LabeledPointGroup
                    {
                        Count = 0,
                        Class = 1
                    });

                    SplittingQuestion splittingQuestion = splittingQuestions[s];

                    for (int p = 0; p < trainingPoints.Count; p++)
                    {
                        //if (random.NextDouble() < .1 || trainingPoints.Count < 1000)
                        {
                            LabeledPoint trainingPoint = trainingPoints[p];

                            SplitDirection split = ComputeSplitDirection(trainingPoint, splittingQuestion, options);

                            if (split == SplitDirection.Left)
                            {
                                leftBucket[trainingPoint.Label].Count++;
                                //leftBucket1.Add(trainingPoint);
                            }
                            else
                            {
                                //rightBucket1.Add(trainingPoint);
                                rightBucket[trainingPoint.Label].Count++;
                            }
                        }
                    }

                    //double gain = ComputeGain(currentShannonEntropy, leftBucket1, rightBucket1);
                    double gain = ComputeGain(currentShannonEntropy, leftBucket, rightBucket);

                    lock (typeof(DecisionTreeBuilder))
                    {
                        if (gain > highestGain)
                        {
                            highestGain           = gain;
                            bestSplittingQuestion = splittingQuestion;
                        }
                    }
                });

                if (highestGain > options.SufficientGainLevel)
                {
                    List <LabeledPoint> bestLeftBucket  = new List <LabeledPoint>();
                    List <LabeledPoint> bestRightBucket = new List <LabeledPoint>();

                    for (int p = 0; p < trainingPoints.Count; p++)
                    {
                        LabeledPoint trainingPoint = trainingPoints[p];

                        SplitDirection split = ComputeSplitDirection(trainingPoint, bestSplittingQuestion, options);

                        if (split == SplitDirection.Left)
                        {
                            bestLeftBucket.Add(trainingPoint);
                        }
                        else
                        {
                            bestRightBucket.Add(trainingPoint);
                        }
                    }

                    currentNode.Question    = bestSplittingQuestion;
                    currentNode.LeftBranch  = new DecisionTreeNode();
                    currentNode.RightBranch = new DecisionTreeNode();
                    currentNode.IsLeaf      = false;

                    //System.Console.WriteLine("left: " + bestLeftBucket.Count.ToString());
                    //System.Console.WriteLine("right: " + bestRightBucket.Count.ToString());

                    //splittingQuestions =
                    //    GenerateSplittingQuestions(random, options);

                    RecurseAndPartition(bestLeftBucket, splittingQuestions,
                                        currentRecursionLevel + 1, options, currentNode.LeftBranch, random);

                    RecurseAndPartition(bestRightBucket, splittingQuestions,
                                        currentRecursionLevel + 1, options, currentNode.RightBranch, random);
                }
                else
                {
                    MakeLeafNode(currentNode, trainingPoints);
                }
            }
        }
Example #13
0
        /// <summary>
        /// Returns the updated available space left when the strip is subtracted.
        /// </summary>
        private Rect LayoutStrip(Rect availableSpace, List <IHierarchicalData> stripMembers, double stripProportion, SplitDirection direction)
        {
            Debug.Assert(!double.IsNaN(stripProportion));
            if (direction == SplitDirection.Vertically)
            {
                return(LayoutVerticalStrip(availableSpace, stripMembers, stripProportion));
            }

            return(LayoutHorizontalStrip(availableSpace, stripMembers, stripProportion));
        }
Example #14
0
    // Recursively split the map into two halves until the larger room you create is the minimum allowed size
    bool[,] partition(bool[,] map, int start_x, int end_x, int start_y, int end_y)
    {
        if (DIR == SplitDirection.HORIZONTAL && (end_y - start_y) <= minSize)
        {
            //Debug.Log("Exit Condition 1");
            return(map);
        }
        else if (DIR == SplitDirection.VERTICAL && (end_x - start_x) <= minSize)
        {
            //Debug.Log("Exit Condition 2");
            return(map);
        }
        else
        {
            //Debug.Log("Recursing");
            if (DIR == SplitDirection.HORIZONTAL)
            {
                DIR = SplitDirection.VERTICAL;
                int split_y = rand.getRandint(start_y + 1, end_y - 1);

                // can probably be made cleaner. Will look into
                while (!((start_y + 1) < split_y && split_y < (end_y - 1)))
                {
                    split_y = rand.getRandint(start_y, end_y);
                }

                for (int i = start_x; i < (end_x + 1); i++)
                {
                    map[split_y, i] = true;
                }

                // put two doors in at either end.
                // It is possible to do this with trees,
                // But this is a much quicker solution that is 95% less complicated
                //map[split_y,start_x + 1] = false;
                //map[split_y, end_x - 1] = false;

                map[split_y, rand.getRandint(start_x + 1, start_x + 2)] = false;
                map[split_y, rand.getRandint(end_x - 2, end_x - 1)]     = false;

                //if (split_y - start_y >= end_y - split_y) {
                //    return partition(map, start_x, end_x, start_y, (split_y - 1));
                //}
                //else {
                //    return partition(map, start_x, end_x, (split_y + 1), end_y);
                //}
                //return partition(map, start_x, end_x, start_y, (split_y - 1));
                //return partition(map, start_x, end_x, (split_y + 1), end_y);
                return(mergedMaps(partition(map, start_x, end_x, start_y, (split_y - 1)), partition(map, start_x, end_x, (split_y + 1), end_y)));
            }
            else if (DIR == SplitDirection.VERTICAL)
            {
                DIR = SplitDirection.HORIZONTAL;
                int split_x = rand.getRandint(start_x, end_x);

                // again, I think there's a cleaner way to do this next loop part but this works
                while (!((start_x + 1) < split_x && split_x < (end_x - 1)))
                {
                    split_x = rand.getRandint(start_x, end_x);
                }
                for (int i = start_y; i < (end_y + 1); i++)
                {
                    map[i, split_x] = true;
                }

                // again we put some doorways
                //map[start_y + 1, split_x] = false;
                //map[end_y - 1, split_x] = false;
                map[rand.getRandint(start_y + 1, start_y + 2), split_x] = false;
                map[rand.getRandint(end_y - 2, end_y - 1), split_x]     = false;

                //if(split_x - start_x >= end_x - split_x) {
                //    return partition(map, start_x, (split_x - 1), start_y, end_y);
                //}
                //else {
                //    return partition(map, (split_x + 1), end_x, start_y, end_y);
                //}
                //return partition(map, start_x, (split_x - 1), start_y, end_y);
                //return partition(map, (split_x + 1), end_x, start_y, end_y);
                return(mergedMaps(partition(map, start_x, (split_x - 1), start_y, end_y), partition(map, (split_x + 1), end_x, start_y, end_y)));
            }
            else
            {
                Debug.Log("This literally can't happen");
                return(map);
            }
        }
    }
Example #15
0
        /// <summary>
        /// WIP: Creates a new split layout.
        /// </summary>
        /// <param name="target">The target dock.</param>
        /// <param name="context">The context object.</param>
        /// <param name="direction">The split direction.</param>
        /// <returns>The new instance of the <see cref="IDock"/> class.</returns>
        public static IDock SplitLayout(this IDock target, object context, SplitDirection direction)
        {
            IDock  layout1 = null;
            IDock  layout2 = null;
            double width   = double.NaN;
            double height  = double.NaN;
            string dock    = "";

            switch (direction)
            {
            case SplitDirection.Left:
            case SplitDirection.Right:
                width  = target.Width == double.NaN ? double.NaN : target.Width / 2.0;
                height = target.Height == double.NaN ? double.NaN : target.Height;
                break;

            case SplitDirection.Top:
            case SplitDirection.Bottom:
                width  = target.Width == double.NaN ? double.NaN : target.Width;
                height = target.Height == double.NaN ? double.NaN : target.Height / 2.0;
                dock   = "Top";
                break;
            }

            IDock emptyStrip = new DockStrip
            {
                Id          = nameof(DockStrip),
                Width       = width,
                Height      = height,
                CurrentView = null,
                Views       = new ObservableCollection <IDock>()
            };

            IDock targetStrip = new DockStrip
            {
                Id          = target.Id,
                Width       = width,
                Height      = height,
                CurrentView = target.CurrentView,
                Views       = target.Views
            };

            switch (direction)
            {
            case SplitDirection.Left:
            case SplitDirection.Top:
            {
                layout1 = new DockLayout
                {
                    Id          = nameof(DockLayout),
                    CurrentView = null,
                    Views       = new ObservableCollection <IDock> {
                        targetStrip
                    }
                };

                layout2 = new DockLayout
                {
                    Id          = nameof(DockLayout),
                    CurrentView = null,
                    Views       = new ObservableCollection <IDock> {
                        emptyStrip
                    }
                };
            }
            break;

            case SplitDirection.Right:
            case SplitDirection.Bottom:
            {
                layout1 = new DockLayout
                {
                    Id          = nameof(DockLayout),
                    CurrentView = null,
                    Views       = new ObservableCollection <IDock> {
                        emptyStrip
                    }
                };

                layout2 = new DockLayout
                {
                    Id          = nameof(DockLayout),
                    CurrentView = null,
                    Views       = new ObservableCollection <IDock> {
                        targetStrip
                    }
                };
            }
            break;
            }

            switch (direction)
            {
            case SplitDirection.Left:
            case SplitDirection.Right:
                layout1.Dock = "Left";
                layout2.Dock = "Right";
                dock         = "Left";
                break;

            case SplitDirection.Top:
            case SplitDirection.Bottom:
                layout1.Dock = "Top";
                layout2.Dock = "Bottom";
                dock         = "Top";
                break;
            }

            var splitLayout = new DockLayout
            {
                Id          = nameof(DockLayout),
                Dock        = "",
                Width       = double.NaN,
                Height      = double.NaN,
                Title       = target.Title,
                CurrentView = null,
                Views       = new ObservableCollection <IDock>
                {
                    layout1,
                    new DockSplitter()
                    {
                        Id   = nameof(DockSplitter),
                        Dock = dock
                    },
                    layout2
                }
            };

            target.Factory?.Update(splitLayout, context);

            return(splitLayout);
        }
Example #16
0
    void Split( int minSize, SplitDirection dir, int position )
    {
        int axis = dir == SplitDirection.Random ? Random.Range(0, 2) : (int)dir;
        int otherAxis = 1 - axis;

        if (position == -1)
            position = Random.Range(minSize, area_.size_[otherAxis] - minSize);

        //  Debug.Log("Position: " + position);

        // Size of the "left over" area
        var remainingAreaOtherAxisSize = area_.size_[otherAxis] - position;

        // Size of the area inside the slice
        var slicedAreaOtherAxisSize = area_.size_[otherAxis] - remainingAreaOtherAxisSize;

        // Size of both new nodes along slice axis
        var axisSize = area_.size_[axis];

        var remainingAreaSize = new IntVector2();
        remainingAreaSize[axis] = axisSize;
        remainingAreaSize[otherAxis] = remainingAreaOtherAxisSize;

        var slicedAreaSize = new IntVector2();
        slicedAreaSize[axis] = axisSize;
        slicedAreaSize[otherAxis] = slicedAreaOtherAxisSize;

        if (axis == 0)
        {
            IntRect remainingArea = new IntRect(area_.xMin_, area_.yMin_ + position, remainingAreaSize.x, remainingAreaSize.y);
            IntRect slicedArea = new IntRect(area_.xMin_, area_.yMin_, slicedAreaSize.x, slicedAreaSize.y);

            childNodes_[0] = new BSPNode(remainingArea);
            childNodes_[1] = new BSPNode(slicedArea);
        }
        if (axis == 1)
        {
            IntRect slicedArea = new IntRect(area_.xMin_, area_.yMin_, slicedAreaSize.x, slicedAreaSize.y);
            IntRect remainingArea = new IntRect(area_.xMin_ + slicedArea.w_, area_.yMin_, remainingAreaSize.x, remainingAreaSize.y);

            childNodes_[0] = new BSPNode(slicedArea);
            childNodes_[1] = new BSPNode(remainingArea);

        }

        childNodes_[0].parent_ = this;
        childNodes_[0].sibling_ = childNodes_[1];
        childNodes_[1].sibling_ = childNodes_[0];
        childNodes_[1].parent_ = this;
    }
Example #17
0
        /// <summary>
        /// Splits (divides) the surface into two parts at the specified parameter
        /// </summary>
        /// <param name="surface">The NURBS surface to split.</param>
        /// <param name="parameter">The parameter at which to split the surface, parameter should be between 0 and 1.</param>
        /// <param name="direction">Where to split in the U or V direction of the surface.</param>
        /// <returns>If the surface is split vertically (U direction) the left side is returned as the first surface and the right side is returned as the second surface.<br/>
        /// If the surface is split horizontally (V direction) the bottom side is returned as the first surface and the top side is returned as the second surface.<br/>
        /// If the spit direction selected is both, the split computes first a U direction split and on the result a V direction split.</returns>
        internal static NurbsSurface[] Split(NurbsSurface surface, double parameter, SplitDirection direction)
        {
            KnotVector            knots      = surface.KnotsV;
            int                   degree     = surface.DegreeV;
            List <List <Point4> > srfCtrlPts = surface.ControlPoints;

            if (direction != SplitDirection.V)
            {
                srfCtrlPts = CollectionHelpers.Transpose2DArray(surface.ControlPoints);
                knots      = surface.KnotsU;
                degree     = surface.DegreeU;
            }

            List <double> knotsToInsert = CollectionHelpers.RepeatData(parameter, degree + 1);
            int           span          = knots.Span(degree, parameter);

            List <List <Point4> > surfPtsLeft  = new List <List <Point4> >();
            List <List <Point4> > surfPtsRight = new List <List <Point4> >();
            NurbsBase             result       = null;

            foreach (List <Point4> pts in srfCtrlPts)
            {
                NurbsCurve tempCurve = new NurbsCurve(degree, knots, pts);
                result = KnotVector.Refine(tempCurve, knotsToInsert);

                surfPtsLeft.Add(result.ControlPoints.GetRange(0, span + 1));
                surfPtsRight.Add(result.ControlPoints.GetRange(span + 1, span + 1));
            }

            if (result == null)
            {
                throw new Exception($"Could not split {nameof(surface)}.");
            }

            KnotVector knotLeft  = result.Knots.GetRange(0, span + degree + 2).ToKnot();
            KnotVector knotRight = result.Knots.GetRange(span + 1, span + degree + 2).ToKnot();

            NurbsSurface[] surfaceResult = Array.Empty <NurbsSurface>();

            switch (direction)
            {
            case SplitDirection.U:
            {
                surfaceResult = new NurbsSurface[]
                {
                    new NurbsSurface(degree, surface.DegreeV, knotLeft, surface.KnotsV.Copy(), CollectionHelpers.Transpose2DArray(surfPtsLeft)),
                    new NurbsSurface(degree, surface.DegreeV, knotRight, surface.KnotsV.Copy(), CollectionHelpers.Transpose2DArray(surfPtsRight))
                };
                break;
            }

            case SplitDirection.V:
            {
                surfaceResult = new NurbsSurface[]
                {
                    new NurbsSurface(surface.DegreeU, degree, surface.KnotsU.Copy(), knotLeft, surfPtsLeft),
                    new NurbsSurface(surface.DegreeU, degree, surface.KnotsU.Copy(), knotRight, surfPtsRight)
                };
                break;
            }

            case SplitDirection.Both:
            {
                NurbsSurface srf1 = new NurbsSurface(degree, surface.DegreeV, knotLeft, surface.KnotsV.Copy(), CollectionHelpers.Transpose2DArray(surfPtsLeft));
                NurbsSurface srf2 = new NurbsSurface(degree, surface.DegreeV, knotRight, surface.KnotsV.Copy(), CollectionHelpers.Transpose2DArray(surfPtsRight));

                NurbsSurface[] split1 = Split(srf1, parameter, SplitDirection.V);
                NurbsSurface[] split2 = Split(srf2, parameter, SplitDirection.V);

                surfaceResult = split2.Concat(split1).ToArray();
                break;
            }
            }

            return(surfaceResult);
        }
Example #18
0
 public void SetSplitDirection(SplitDirection splitDirection)
 {
     this.splitDirection = splitDirection;
 }