} //todo łącz przy kasowaniu!

        public List <WeldRegenerationOrder> RegisterWeld(WeldPosition weldPosition, WeldSideType sideType,
                                                         WeldingInputTerrain inputTerrain)
        {
            var outList      = new List <WeldRegenerationOrder>();
            var newWeldsList = new List <Weld>();

            foreach (var weld in _welds)
            {
                if (RangeIsInWeld(weld, weldPosition.Range))
                {
                    WeldSplicingResult spliced = SpliceWeld(weld, weldPosition.Range);
                    var newWeld = spliced.NewWeld;
                    newWeld.AddSide(new WeldSideSource()
                    {
                        SideType = sideType,
                        Terrain  = inputTerrain
                    });

                    outList.Add(new WeldRegenerationOrder()
                    {
                        Weld = newWeld
                    });

                    newWeldsList.AddRange(spliced.RestOfWelds);
                    newWeldsList.Add(spliced.NewWeld);
                }
                else
                {
                    newWeldsList.Add(weld);
                }
            }

            _welds = newWeldsList.OrderBy(c => c.GlobalSizeRange.X).ToList();
            return(outList.Where(c => c.Weld.ThereAreBothSides).ToList());
        }
示例#2
0
        public int RegisterTerrain(WeldingInputTerrain inputTerrain)
        {
            var newId = _lastTerrainId.GetNext();

            inputTerrain.WeldingInputTerrainId = newId;
            PostPureAsyncAction(() => _dispatcher.RegisterTerrain(inputTerrain));
            return(newId);
        }
        public Task RegisterTerrain(WeldingInputTerrain inputTerrain)
        {
            _terrains[inputTerrain.WeldingInputTerrainId] = new WeldingTerrainEntity()
            {
                Uvs = new TerrainWeldUvs(),
                WeldModificationCallback = inputTerrain.WeldModificationCallback
            };

            var globalSubPosition = RectangleUtils.CalculateSubPosition(inputTerrain.DetailGlobalArea,
                                                                        inputTerrain.UvCoordsPositions2D);

            var weldPositions = new Dictionary <WeldSideType, WeldPosition>();

            weldPositions[WeldSideType.Bottom] = new WeldPosition()
            {
                ConstantAxisPosition = Mathf.RoundToInt(globalSubPosition.Y),
                Orientation          = WeldOrientation.Horizontal,
                Range = new IntVector2(Mathf.RoundToInt(globalSubPosition.X), Mathf.RoundToInt(globalSubPosition.MaxX))
            };
            weldPositions[WeldSideType.Top] = new WeldPosition()
            {
                ConstantAxisPosition = Mathf.RoundToInt(globalSubPosition.MaxY),
                Orientation          = WeldOrientation.Horizontal,
                Range = new IntVector2(Mathf.RoundToInt(globalSubPosition.X), Mathf.RoundToInt(globalSubPosition.MaxX))
            };
            weldPositions[WeldSideType.Left] = new WeldPosition()
            {
                ConstantAxisPosition = Mathf.RoundToInt(globalSubPosition.X),
                Orientation          = WeldOrientation.Vertical,
                Range = new IntVector2(Mathf.RoundToInt(globalSubPosition.Y), Mathf.RoundToInt(globalSubPosition.MaxY))
            };
            weldPositions[WeldSideType.Right] = new WeldPosition()
            {
                ConstantAxisPosition = Mathf.RoundToInt(globalSubPosition.MaxX),
                Orientation          = WeldOrientation.Vertical,
                Range = new IntVector2(Mathf.RoundToInt(globalSubPosition.Y), Mathf.RoundToInt(globalSubPosition.MaxY))
            };

            var orders = new List <WeldRegenerationOrder>();

            foreach (var weldPositionPair in weldPositions)
            {
                var weldPosition = weldPositionPair.Value;
                var orientation  = weldPositionPair.Key.GetOrientation();
                var weldsDict    = _welds[orientation];

                if (!weldsDict.ContainsKey(weldPosition.ConstantAxisPosition))
                {
                    weldsDict[weldPosition.ConstantAxisPosition] = new WeldLine();
                }

                var line = weldsDict[weldPosition.ConstantAxisPosition];
                orders.AddRange(line.RegisterWeld(weldPosition, weldPositionPair.Key, inputTerrain));
            }

            //var weldsUvs = TaskUtils.WhenAll(orders.Select(c => _mapLevel1Manager.Process(c))).Result;
            var weldsUvs = orders.Select(c => _mapLevel1Manager.Process(c)).ToList();

            foreach (var x in weldsUvs.SelectMany(c => c))
            {
                var terrainId = x.Key;
                var weldUv    = x.Value;

                var terrain = _terrains[terrainId];
                terrain.Uvs.Merge(weldUv);
                terrain.WeldModificationCallback(terrain.Uvs);
            }

            return(TaskUtils.EmptyCompleted());
        }