示例#1
0
 public void TestInitialize()
 {
     this.pitagoricTable = new Map2D <int, int, int>();
     this.pitagoricTable.Fill(
         Enumerable.Range(1, 10),
         Enumerable.Range(1, 10),
         (i, j) => i * j);
 }
示例#2
0
 public LookupMatcher(IMap2D <TerrainData> map,
                      ITileTagEntrySelectionFactory factory,
                      ITileTagEntrySelection[] selections)
 {
     this.Owner      = factory;
     this.map        = map;
     this.selections = selections;
 }
示例#3
0
 /// <inheritdoc cref="IEquatable{T}.Equals(T)" />
 public bool Equals(IMap2D <TKey1, TKey2, TValue> other)
 {
     if (other is null)
     {
         return(false);
     }
     return(this.Equals(other));
 }
示例#4
0
 /// <inheritdoc cref="IEquatable{T}.Equals(T)" />
 public bool Equals(IMap2D <TKey1, TKey2, TValue> other)
 {
     if (other is Map2D <TKey1, TKey2, TValue> other2)
     {
         return(this.Equals(other2));
     }
     // TODO: improve
     return(false);
 }
示例#5
0
 /// <inheritdoc cref="IEquatable{T}.Equals(T)" />
 public bool Equals(IMap2D <TKey1, TKey2, TValue> other)
 {
     // TODO: improve
     if (other is Map2D <TKey1, TKey2, TValue> maps)
     {
         return(Equals(maps));
     }
     return(false);
 }
示例#6
0
        public void Render <TNode>(IMap2D <TNode> map, WriteableBitmap target, ImageProvider <TNode> imageProvider, DrawingWindowState drawingWindowState)
        {
            if (drawingWindowState.Z >= 1200 - _minZoom * 1200.0)
            {
                drawingWindowState.Z = (int)(1200 - _minZoom * 1200.0);
            }

            if (drawingWindowState.Z < 0)
            {
                drawingWindowState.Z = 0;
            }

            var scale   = (1200 - drawingWindowState.Z) / 1200.0;
            var xOffset = drawingWindowState.X / (_cellWidth * scale);
            var yOffset = drawingWindowState.Y / (_cellHeight * scale);

            var cellWidth  = (int)(_cellWidth * scale);
            var cellHeight = (int)(_cellHeight * scale);

            var xCellsAmount = target.PixelWidth / cellWidth;
            var yCellsAmount = target.PixelHeight / cellHeight;

            var xPixelOffset = (int)((xOffset - Math.Truncate(xOffset)) * cellWidth);
            var yPixelOffset = (int)((yOffset - Math.Truncate(yOffset)) * cellHeight);

            var targetRect = new Rect(0, 0, cellWidth, cellHeight);

            for (var y = 0; y <= yCellsAmount; y++)
            {
                for (var x = 0; x <= xCellsAmount; x++)
                {
                    var node = map.SafeNodeAt(x - (int)xOffset, y - (int)yOffset);
                    if (ReferenceEquals(node, null))
                    {
                        continue;
                    }

                    targetRect.X = x * cellWidth + xPixelOffset;
                    targetRect.Y = y * cellHeight + yPixelOffset;
                    foreach (var image in imageProvider(node, x, y))
                    {
                        target.Blit(targetRect, image, _sourceRect);
                    }
                }
            }
        }
示例#7
0
        private static List <Point2D> TraceContour <TNode>(IMap2D <int> labels, int currentLabel, Map2D <TNode> map, Func <TNode, int> getType, int x, int y, bool isExternal)
        {
            var contour = new List <Point2D>();

            var index = isExternal ? 7 : 3;

            var startX = x;
            var startY = y;

            var localX = -1;
            var localY = -1;

            labels[startX, startY] = currentLabel;

            var done = false;

            while (!done)
            {
                contour.Add(new Point2D(startX, startY));

                int counter;
                for (counter = 0; counter < 8; counter++, index = (index + 1) % 8)
                {
                    var differencePoint = DifferencePoints[index];
                    var currentX        = (int)(startX + differencePoint.X);
                    var currentY        = (int)(startY + differencePoint.Y);

                    if (currentX < 0 || currentX >= map.Width)
                    {
                        continue;
                    }

                    if (currentY < 0 || currentY >= map.Height)
                    {
                        continue;
                    }

                    if (getType(map[currentX, currentY]) != BackgroundType)
                    {
                        labels[currentX, currentY] = currentLabel;
                        if (localX < 0 && localY < 0)
                        {
                            localX = currentX;
                            localY = currentY;
                        }
                        else
                        {
                            done = x == startX && localX == currentX && y == startY && localY == currentY;
                        }

                        startX = currentX;
                        startY = currentY;
                        break;
                    }

                    labels[currentX, currentY] = -1;
                }

                if (counter == 8)
                {
                    done = true;
                }

                var previous = (index + 4) % 8;
                index = (previous + 2) % 8;
            }

            return(contour);
        }
示例#8
0
 protected static GridMatcher CreateMatcher <T>(IMap2D <T> map, T matchee)
     where T : IEquatable <T>
 {
     return((x, y) => map[x, y].Equals(matchee));
 }
示例#9
0
文件: Map2D.cs 项目: Brandhyw/Map
 public void CopyTo(IMap2D <T> map)
 {
     CopyTo(map);
 }
示例#10
0
 /// <inheritdoc cref="IEquatable{T}.Equals(T)" />
 public bool Equals(IMap2D <TKey1, TKey2, TValue> other)
 {
     return(this.table.Equals(other.table));
 }
示例#11
0
 /// <inheritdoc cref="IEquatable{T}.Equals(T)"/>
 public bool Equals(IMap2D <TKey1, TKey2, TValue> other)
 {
     return(other is Map2D <TKey1, TKey2, TValue> otherMap?this.Equals(otherMap) : false);
 }
示例#12
0
 /// <inheritdoc cref="IEquatable{T}.Equals(T)" />
 public bool Equals(IMap2D <TKey1, TKey2, TValue> other)
 {
     return(this.NumberOfElements == other.NumberOfElements &&
            this.GetElements().Equals(other.GetElements()));
 }
示例#13
0
 public ReadOnlyHeightMap(IMap2D <DataMap> parent)
 {
     Parent = parent;
 }
示例#14
0
 /// <inheritdoc cref="IEquatable{T}.Equals(T)" />
 public bool Equals(IMap2D <TKey1, TKey2, TValue> other)
 {
     // TODO: improve
     return(base.Equals(other));
 }