Exemplo n.º 1
0
        private static void generateLocations()
        {
            var prefectureList           = new PrefectureList();
            var municipalityNameTransfer = new MunicipalityNameTransfer();

            var postalCodeFileReader = new PostalCodeFileReader(municipalityNameTransfer, new TownAreaNameTransfer());

            foreach (var postalCode in postalCodeFileReader.ReadFile(postalCodePath))
            {
                prefectureList.Add(postalCode);
            }

            var addressFileReader = new AddressFileReader(municipalityNameTransfer);

            foreach (var address in Directory.GetFiles(addressFolder).SelectMany(x => addressFileReader.ReadFile(Path.Combine(addressFolder, x))))
            {
                prefectureList.Add(address);
            }

            var locationMatcher = new LocationMatcher();
            IReadOnlyList <LocationMatch> foundLocations = locationMatcher.FindLocations(prefectureList);
            var locationCalculator             = new LocationCalculator();
            IReadOnlyList <Location> locations = locationCalculator.Calculate(foundLocations);

            File.WriteAllText(locationPath, JsonSerializer.PrettyPrint(JsonSerializer.Serialize(locations)));
            Console.WriteLine("output Locations.json");
        }
        /// <summary>
        /// Első eset: a két távolság által jelzett kör messze van egymástól:
        /// Megoldás: mindkettőt arányosan növeljük
        /// </summary>
        protected bool CheckFarDistances(TagDisplay tag1, TagDisplay tag2)
        {
            if (LocationCalculator.Distance(tag1.Origo, tag2.Origo) > tag1.Distance + tag2.Distance)
            {
                double deviance = LocationCalculator.Distance(tag1.Origo, tag2.Origo) - (tag1.Distance + tag2.Distance);
                deviance += BIAS;  // Az eltérés torzítása, így biztosan lesz metszéspont
                double max   = tag1.Distance + tag2.Distance;
                double rate1 = tag1.Distance / max;
                double rate2 = tag2.Distance / max;
                tag1.ChangeDistance(tag1.Distance + deviance * rate1);
                tag2.ChangeDistance(tag2.Distance + deviance * rate2);


                //TEST
                double dist = LocationCalculator.Distance(tag1.Origo, tag2.Origo) - (tag1.Distance + tag2.Distance);
                if (dist > 0.0)
                {
                    dist = 0; /* throw new Exception("Calculation error: distance must be 0.0"); */
                }
                //TEST

                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        protected internal static async Task <string> GetNameAsync(LocationCalculator calc, Stream stream, uint nameRVA)
        {
            var fileOffset = calc.RVAToOffset(nameRVA);

            stream.Seek(fileOffset.ToInt64(), SeekOrigin.Begin);

            var result = await stream.ReadStringAsync().ConfigureAwait(false);

            return(result);
        }
Exemplo n.º 4
0
        public void AlignByKey()
        {
            var viewModel = new AlignmentViewModel(this, CreateAlignment());
            var bounds    = new LocationCalculator().CalculateBounds(Handle, KeyGrabOffset);

            using (var grabber = UIManager.GetKeyGrabber(viewModel))
            {
                grabber.SetBounds(bounds);
                grabber.Display();
            }
        }
        public void ItShouldReturnLatIfMeterIsZero()
        {
            //Arrange
            double inputLat   = 71.639566053691;
            double inputMeter = 0;

            //Act
            double result = LocationCalculator.MoveY(inputLat, inputMeter);

            //Assert
            Assert.True(result == inputLat);
        }
        public void ItShouldReturnNewLatitude()
        {
            //Arrange
            double oldLat = 71.639566053691;
            double meters = -7500d;

            //Act
            double newLat = LocationCalculator.CalcLatMeters(oldLat, meters);

            //Assert
            Assert.True(newLat == 71.572192407382033);
        }
        public void ItShouldReturnNewLongitude()
        {
            //Arrange
            double oldLon = -51.1902823595313;
            double meters = 10000;
            double oldLat = 71.639566053691;

            //Act
            double newLat = LocationCalculator.CalcLonMeters(oldLon, meters, oldLat);

            //Assert
            Assert.True(newLat == -50.905097207707151);
        }
Exemplo n.º 8
0
        private static async Task <ushort[]> BuildFunctionOrdinalsAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
        {
            var offset = calc.RVAToOffset(directory.AddressOfNameOrdinals).ToInt64();

            stream.Seek(offset, SeekOrigin.Begin);

            var results = new ushort[directory.NumberOfNames];

            for (var i = 0; i < directory.NumberOfNames; i++)
            {
                results[i] = await stream.ReadUInt16Async().ConfigureAwait(false);
            }

            return(results);
        }
        private Point getClosestPoint(Point P, List <Point> IntersectionPoints)
        {
            int    mini = 0;
            Point  intersectionPoint;
            double mindist = LocationCalculator.Distance(P, IntersectionPoints[0]);
            double dist;

            for (int i = 1; i < IntersectionPoints.Count; i++)
            {
                intersectionPoint = IntersectionPoints[i];
                dist = LocationCalculator.Distance(P, intersectionPoint);
                if (dist < mindist)
                {
                    mini    = i;
                    mindist = dist;
                }
            }
            return(IntersectionPoints[mini]);
        }
        /// <summary>
        /// Második eset: az egyik kör a másikon belül helyezkedik el:
        /// Megoldás: a nagyobb kört arányosan csökkentjük, a kisebb kört pedig arányosan növeljük
        /// </summary>
        protected bool CheckInclude(TagDisplay tag1, TagDisplay tag2)
        {
            TagDisplay bigger, smaller;

            if (tag1.Includes(tag2))
            {
                bigger  = tag1;
                smaller = tag2;
            }
            else if (tag2.Includes(tag1))
            {
                bigger  = tag2;
                smaller = tag1;
            }
            else
            {
                return(false);
            }

            double deviance = bigger.Distance - (LocationCalculator.Distance(bigger.Origo, smaller.Origo) + smaller.Distance);

            deviance += BIAS;   // Az eltérés torzítása, így biztosan lesz metszéspont
            double max   = bigger.Distance + smaller.Distance;
            double brate = bigger.Distance / max;
            double srate = smaller.Distance / max;

            bigger.ChangeDistance(bigger.Distance - deviance * brate);
            smaller.ChangeDistance(smaller.Distance + deviance * srate);


            //TEST
            double dist = bigger.Distance - (LocationCalculator.Distance(bigger.Origo, smaller.Origo) + smaller.Distance);

            if (dist > 0.0)
            {
                dist = 0; /* throw new Exception("Calculation error: distance must be 0.0"); */
            }
            //TEST

            return(true);
        }
Exemplo n.º 11
0
        public static GeoPoint Move(GeoPoint startingPosition, IEnumerable <SantaMovement> movements)
        {
            GeoPoint currentPosition = startingPosition;
            GeoPoint newPosition     = new GeoPoint(0, 0);

            foreach (SantaMovement move in movements)
            {
                double xMeters = 0d;
                double yMeters = 0d;

                switch (move.Direction)
                {
                case "left":
                    xMeters -= move.Value;
                    break;

                case "right":
                    xMeters += move.Value;
                    break;

                case "up":
                    yMeters += move.Value;
                    break;

                case "down":
                    yMeters -= move.Value;
                    break;

                default:
                    throw new Exception("direction not supported");
                }

                newPosition.lon = LocationCalculator.MoveX(currentPosition.lon, xMeters, currentPosition.lat);
                newPosition.lat = LocationCalculator.MoveY(currentPosition.lat, yMeters);

                currentPosition = new GeoPoint(newPosition.lat, newPosition.lon);
            }

            return(currentPosition);
        }
        public LocationResult CalculateLocation(List <TagDisplay> NearbyDistances, LocationResult LastLocation)
        {
            List <TagDisplay> Distances = NearbyDistances.ToList <TagDisplay>(); // Ha azt akarjuk hogy az eredeti körök ne változzanak, akkor ezt shallow copyzni kell

            //Distances.RemoveAll(tag => tag.AverageRSSI == 0.0);
            if (Distances.Count == 0)
            {
                return(new LocationResult(new Point(-1, -1), Precision.NoTag));
            }
            if (Distances.Count == 1)
            {
                return(new LocationResult(Distances[0].Origo, Precision.OneTag, Distances[0].Distance)); // 1 vagy semennyi kör esetén nem tudunk pozíciót meghatározni
            }
            if (Distances.Count == 2)                                                                    // 2 kör esetén a metszet két pontja közti felezőpont kell
            {
                ForceAllIntersections(Distances);
                Intersection points = Intersection.CalculateIntersection(Distances[0].Origo, Distances[0].Distance, Distances[1].Origo, Distances[1].Distance);
                return(new LocationResult(LocationCalculator.Midpoint(points.Points[0], points.Points[1]), Precision.TwoTag, LocationCalculator.Distance(points.Points[0], points.Points[1]) / 2));
            }

            return(CalculateCommonPoint(Distances, LastLocation));
        }
Exemplo n.º 13
0
        private static async Task <string> BuildNameAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
        {
            var builder = new StringBuilder(256);
            var offset  = calc.RVAToOffset(directory.Name).ToInt64();

            stream.Seek(offset, SeekOrigin.Begin);

            while (true)
            {
                int value = await stream.ReadByteAsync().ConfigureAwait(false);

                if (value <= 0)
                {
                    break;
                }

                var c = (char)value;

                builder.Append(c);
            }

            return(builder.ToString());
        }
 public IntersectDistance(Point P1, Point P2)
 {
     this.P1       = P1;
     this.P2       = P2;
     this.Distance = LocationCalculator.Distance(P1, P2);
 }
 private double getDistance(Point p1, Point p2, Point p3)
 {
     return(LocationCalculator.Distance(p1, p2) + LocationCalculator.Distance(p2, p3) + LocationCalculator.Distance(p1, p3));
 }
Exemplo n.º 16
0
 public void TearDown()
 {
     _calc = null;
     _image.Dispose();
 }
Exemplo n.º 17
0
 public void SetUp()
 {
     _image = PortableExecutableImage.FromStream(TestingUtils.GetFileFromResources("nativetest.x64.dll"));
     _calc  = _image.GetCalculator();
 }
        /// <summary>
        /// Ez működik általános esetre, amikor nincs pontos metszéspont
        ///
        /// A legközelebbi 3 metszéspont átlagpontját adjuk vissza
        /// Válasszuk ki a metszéspontok távolságai közül a legrövidebb hármat
        /// Elméletileg a 3 távolság 6 metszéspontja lényegében 3 pont, amit keresünk, ezek átlaga kell
        /// </summary>
        public override Point CalculateCommonPoint(List <Intersection> intersections)
        {
            List <IntersectDistance> idistances = new List <IntersectDistance>();     // A metszéspontok távolságai
            IntersectDistance        idist;

            for (int i = 0; i < intersections.Count; i++)
            {
                for (int j = 0; j < intersections.Count; j++)
                {
                    if (i != j)
                    {
                        // Egy metszet két metszéspontjának távolságát nem is vesszük figyelembe
                        idist = new IntersectDistance(intersections[i].Points[0], intersections[j].Points[1]);
                        if (!idistances.Contains(idist))
                        {
                            idistances.Add(idist);
                        }
                        idist = new IntersectDistance(intersections[i].Points[0], intersections[j].Points[0]);
                        if (!idistances.Contains(idist))
                        {
                            idistances.Add(idist);
                        }
                        idist = new IntersectDistance(intersections[i].Points[1], intersections[j].Points[1]);
                        if (!idistances.Contains(idist))
                        {
                            idistances.Add(idist);
                        }
                    }
                }
            }

            //---------------------új megoldás:--------------------

            // Az összes metszéspontot ebben a listában tároljuk
            List <Point> intersectPoints = new List <Point>();

            //Ebben a listában tároljuk el a k legközelebbi metszéspontokat
            List <Point> closestPoints = new List <Point>();

            IntersectDistance firstDistance = getMinimumDistance(idistances);

            closestPoints.Add(firstDistance.P1);
            closestPoints.Add(firstDistance.P2);

            foreach (Intersection i in intersections)
            {
                foreach (Point p in i.Points)
                {
                    if (!p.Equals(firstDistance.P1) && !p.Equals(firstDistance.P2))
                    {
                        intersectPoints.Add(p);
                    }
                }
            }

            Point candidate1 = getClosestPoint(firstDistance.P1, intersectPoints);
            Point candidate2 = getClosestPoint(firstDistance.P2, intersectPoints);

            closestPoints.Add(getThirdPoint(candidate1, candidate2, firstDistance));

            return(LocationCalculator.PointAverage(closestPoints));
        }