Example #1
0
        protected virtual List <Segment> GetSegmentList(IDictionary <string, object> objectAsDict)
        {
            if (!objectAsDict.ContainsKey("posList"))
            {
                return(null);
            }
            var lineList = (List <string>)objectAsDict["posList"];
            // extrior (GML name) is the only one in this case
            var exteriorLine = lineList.First();

            if (string.IsNullOrEmpty(exteriorLine))
            {
                return(null);
            }
            List <Segment> netSegments        = new List <Segment>();
            var            exteriorLinePoints = TranslatorUtils.LineToVectorList(exteriorLine);
            var            reductedPoints     = DouglasPointsReduction.Reduct(exteriorLinePoints, toleranceDP);

            if (reductedPoints.Count <= 1)
            {
                return(null);
            }
            for (int i = 0; i < reductedPoints.Count - 1; i++)
            {
                netSegments.Add(new Segment {
                    p1 = reductedPoints[i], p2 = reductedPoints[i + 1]
                });
            }
            return(netSegments);
        }
Example #2
0
        /// <summary>
        ///     In case of buildings and props the most important thing are angles to road segments
        /// </summary>
        /// <param name="objectAsDict"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        protected override string GetOther(IDictionary <string, object> objectAsDict, Vector2 point)
        {
            if (TranslatorInitiator.RoadSegment == null)
            {
                return("0");
            }
            var angleToSegment = TranslatorUtils.AngleToSegment(TranslatorInitiator.RoadSegment, point);

            return(angleToSegment.ToString());
        }
Example #3
0
        protected virtual string GetPointPosition(IDictionary <string, object> objectAsDict)
        {
            if (objectAsDict.ContainsKey("pos"))
            {
                string objPoint = objectAsDict["pos"].ToString();
                var    point    = objPoint.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                  .Select(num => float.Parse(num, System.Globalization.CultureInfo.InvariantCulture))
                                  .ToArray();
                currentPoint = CoordinatesCalc.GameXY(new Vector2(point[0], point[1]));
                if (CoordinatesCalc.IsInRange(currentPoint))
                {
                    string pointStr = "";
                    pointStr += $"{currentPoint.X} {currentPoint.Y} ";
                    return(pointStr);
                }
                return(null);
            }

            else if (objectAsDict.ContainsKey("posList"))
            {
                var lineList = (List <string>)objectAsDict["posList"];
                List <List <Vector2> > lineV2List = new List <List <Vector2> >();
                for (int i = 0; i < lineList.Count; i++)
                {
                    lineV2List.Add(TranslatorUtils.LineToVectorList(lineList[i]));
                }
                var    avgPoint       = Calculations.AvgPoint(lineV2List[0]);
                string avgPointString = "";
                if (!TranslatorUtils.IsNaNVector2(avgPoint))
                {
                    avgPointString = $"{avgPoint.X} {avgPoint.Y}";
                }

                if (!string.IsNullOrEmpty(avgPointString))
                {
                    var pArea = Calculations.PolygonArea(lineV2List[0]);
                    if (lineV2List.Count > 1)
                    {
                        for (int i = 1; i < lineV2List.Count; i++)
                        {
                            pArea -= Calculations.PolygonArea(lineV2List[i]);
                        }
                    }
                    pArea64      = ((int)(pArea / 64)) * 64;
                    currentPoint = avgPoint;
                    return(avgPointString);
                }
            }
            return(null);
        }
        protected override void Translate(ExpandoObject objectToTranslate)
        {
            var objectAsDict = (IDictionary <string, object>)objectToTranslate;

            List <Segment> segmentList = GetSegmentList(objectAsDict);

            if (segmentList == null)
            {
                return;
            }

            string objectName = GetObjectName(objectAsDict);

            if (string.IsNullOrEmpty(objectName))
            {
                return;
            }
            ObjectTypeEnum objectType = GetObjectType(objectAsDict);
            string         iIP        = GetIIP(objectAsDict);
            string         other;

            if (!isNet)
            {
                List <string> translatedObjects = new List <string>();
                foreach (var segment in segmentList)
                {
                    var pointsList = AdditionalPointsCreation.CreatePointsInLine(segment.p1, segment.p2, propSize);
                    other = Calculations.Azimuth(segment.p1, segment.p2).ToString();

                    foreach (var point in pointsList)
                    {
                        translatedObjects.Add($"{objectType};{objectName};{iIP};{other};{point.X} {point.Y};");
                    }
                }

                foreach (var obj in translatedObjects)
                {
                    if (!string.IsNullOrEmpty(obj))
                    {
                        Console.WriteLine(obj);
                    }
                }
            }
            else
            {
                other = GetOther(objectAsDict);
                TranslatorUtils.WriteAttrToConsole(segmentList, objectType, objectName, iIP, other);
            }
        }
Example #5
0
        protected override void Translate(ExpandoObject objectToTranslate)
        {
            var objectAsDict = (IDictionary <string, object>)objectToTranslate;

            List <Segment> segmentList = GetSegmentList(objectAsDict);

            if (segmentList != null)
            {
                ObjectTypeEnum objectType = GetObjectType(objectAsDict);
                string         objectName = GetObjectName(objectAsDict);
                if (string.IsNullOrEmpty(objectName))
                {
                    return;
                }
                string iIP   = GetIIP(objectAsDict);
                string other = GetOther(objectAsDict);
                TranslatorUtils.WriteAttrToConsole(segmentList, objectType, objectName, iIP, other);
            }
        }
Example #6
0
        protected override void Translate(ExpandoObject objectToTranslate)
        {
            var objectAsDict = (IDictionary <string, object>)objectToTranslate;

            string gamePosition = GetPointPosition(objectAsDict);

            if (string.IsNullOrEmpty(gamePosition))
            {
                return;
            }
            string objectName = GetObjectName(objectAsDict);

            if (string.IsNullOrEmpty(objectName))
            {
                return;
            }
            ObjectTypeEnum objectType = GetObjectType(objectAsDict);
            string         iIP        = GetIIP(objectAsDict);
            string         other      = GetOther(objectAsDict, currentPoint);

            TranslatorUtils.WriteAttrToConsole(objectType, objectName, iIP, other, gamePosition);
        }
        protected virtual HashSet <Vector2> GetPointsInArea(IDictionary <string, object> objectAsDict)
        {
            if (objectAsDict.ContainsKey("posList"))
            {
                var lineList   = (List <string>)objectAsDict["posList"];
                var exteriorV2 = TranslatorUtils.LineToVectorList(lineList[0]);
                //var exteriorV2 = TranslatorUtils.LineListToVector2Arr(lineList, 0);
                if (exteriorV2.Count < 3)
                {
                    return(null);
                }

                var areaMinMax = Calculations.FindMaxMin(exteriorV2);
                var points     = AdditionalPointsCreation.CreatePointArray(areaMinMax[0], areaMinMax[1], gridDist);
                List <List <Vector2> > interiors = new List <List <Vector2> >();
                if (lineList.Count > 1)
                {
                    for (int i = 1; i < lineList.Count; i++)
                    {
                        interiors.Add(TranslatorUtils.LineToVectorList(lineList[i]));
                    }
                }

                HashSet <Vector2> selectedPoints = new HashSet <Vector2>();
                foreach (var p in points)
                {
                    if (Calculations.PointInPoly(exteriorV2, p) &&
                        (interiors == null || !interiors.Any(interior => Calculations.PointInPoly(interior, p))))
                    {
                        selectedPoints.Add(p);
                    }
                }
                return(selectedPoints);
            }
            return(null);
        }