Ejemplo n.º 1
0
        private PointF?CalculateWithMirrorPositions2(List <SignalEventDetails> orderedGroup)
        {
            PointF?eventPosition     = null;
            int    groupCount        = orderedGroup.Count;
            var    detectionMirrors  = new List <Tuple <PointF, PointF> >(groupCount);
            int    totalSignalWeight = 0;

            for (int i = 0; i < groupCount; i++)
            {
                var signalEventDetails = orderedGroup[i];
                signalEventDetails.Distance = _signalToDistanceConverter.GetDistance(signalEventDetails.Rssi);
                var    otherSignalEventDetails = i < groupCount - 1 ? orderedGroup[i + 1] : orderedGroup[i - 1];
                double angle = GeometryUtil.GetAngle(signalEventDetails.BleReceiver.Position,
                                                     otherSignalEventDetails.BleReceiver.Position);
                var mirrors = CreateMirroredPoints(signalEventDetails.BleReceiver.Position, signalEventDetails.Distance,
                                                   angle);
                detectionMirrors.Add(mirrors);
                totalSignalWeight += signalEventDetails.Rssi;
            }
            //get first mirror closest to leading sensor then advance to each mirror closest to event position
            for (int i = 1; i < groupCount - 1; i++)
            {
                var    signalEventDetails = orderedGroup[i];
                var    nextMirrors        = detectionMirrors[i + 1];
                PointF refPosition;
                if (eventPosition.HasValue)
                {
                    refPosition = eventPosition.Value;
                }
                else
                {
                    refPosition = signalEventDetails.BleReceiver.Position;
                }
                var selectedNextPoint = GeometryUtil.GetDistance(nextMirrors.Item1, refPosition) <
                                        GeometryUtil.GetDistance(nextMirrors.Item2, refPosition)
                    ? nextMirrors.Item1
                    : nextMirrors.Item2;

                if (!eventPosition.HasValue)
                {
                    var currentMirrors = detectionMirrors[i];
                    refPosition = GeometryUtil.GetDistance(currentMirrors.Item1, selectedNextPoint) <
                                  GeometryUtil.GetDistance(currentMirrors.Item2, selectedNextPoint)
                        ? currentMirrors.Item1
                        : currentMirrors.Item2;
                }
                eventPosition = GeometryUtil.CalculatePointInBetween(refPosition, selectedNextPoint);
            }
            return(eventPosition);
        }