public IHttpActionResult PutPacman_location_db(int id, Pacman_location_db pacman_location_db)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != pacman_location_db.ID)
            {
                return BadRequest();
            }

            db.Entry(pacman_location_db).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Pacman_location_dbExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
        public IHttpActionResult PostPacman_location_db(Pacman_location_db pacman_location_db)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Pacman_location_db.Add(pacman_location_db);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = pacman_location_db.ID }, pacman_location_db);
        }
        private static bool RayIntersectsSegment(Pacman_location_db point, Tuple<FencePoint, FencePoint> side)
        {
            if ((point.coordinates_y == side.Item1.Longitude) || (point.coordinates_y == side.Item2.Longitude))
            {
                var newPoint = new Pacman_location_db()
                {
                    coordinates_x = point.coordinates_x,
                    coordinates_y = point.coordinates_y + EPSILON
                };
                point = newPoint;
            }
            if ((point.coordinates_y < side.Item1.Longitude) || (point.coordinates_y > side.Item2.Longitude))
            {
                return false;
            }
            else if (point.coordinates_x > Math.Max(side.Item1.Latitude, side.Item2.Latitude))
            {
                return false;
            }
            else
            {
                decimal m_red;
                decimal m_blue;
                if (point.coordinates_x < Math.Min(side.Item1.Latitude, side.Item2.Latitude))
                {
                    return true;
                }
                else
                {
                    if (side.Item1.Latitude != side.Item2.Latitude)
                    {
                        m_red = (side.Item2.Longitude - side.Item1.Longitude) / (side.Item2.Latitude - side.Item1.Latitude);
                    }
                    else
                    {
                        m_red = INFINITY;
                    }
                    if (side.Item1.Latitude != point.coordinates_x)
                    {
                        m_blue = (point.coordinates_y - side.Item1.Longitude) / (point.coordinates_x - side.Item1.Latitude);
                    }
                    else
                    {
                        m_blue = INFINITY;
                    }

                    return (m_blue >= m_red);
                }
            }
        }
        public void ConcaveFenceWithThreePointsOnOneLine()
        {
            Models.FencePoint point1 = new Models.FencePoint()
            {
                Latitude = 2,
                Longitude = 0
            };
            Models.FencePoint point2 = new Models.FencePoint()
            {
                Latitude = 4,
                Longitude = 0
            };
            Models.FencePoint point3 = new Models.FencePoint()
            {
                Latitude = 2,
                Longitude = 3
            };
            Models.FencePoint point4 = new Models.FencePoint()
            {
                Latitude = 4,
                Longitude = 6
            };
            Models.FencePoint point5 = new Models.FencePoint()
            {
                Latitude = 0,
                Longitude = 6
            };

            Tuple<Models.FencePoint, Models.FencePoint> side1 = new Tuple<Models.FencePoint, Models.FencePoint>(point1, point2);
            Tuple<Models.FencePoint, Models.FencePoint> side2 = new Tuple<Models.FencePoint, Models.FencePoint>(point2, point3);
            Tuple<Models.FencePoint, Models.FencePoint> side3 = new Tuple<Models.FencePoint, Models.FencePoint>(point3, point4);
            Tuple<Models.FencePoint, Models.FencePoint> side4 = new Tuple<Models.FencePoint, Models.FencePoint>(point4, point5);
            Tuple<Models.FencePoint, Models.FencePoint> side5 = new Tuple<Models.FencePoint, Models.FencePoint>(point5, point1);

            List<Tuple<Models.FencePoint, Models.FencePoint>> sides = new List<Tuple<Models.FencePoint, Models.FencePoint>>();
            sides.Add(side1);
            sides.Add(side2);
            sides.Add(side3);
            sides.Add(side4);
            sides.Add(side5);

            Pacman_location_db location = new Pacman_location_db
            {
                coordinates_x = 4,
                coordinates_y = 3
            };

            Assert.IsTrue(!CheckPolygonFence.CheckPointInside(sides, location));
        }
 public static bool CheckPointInside(IEnumerable<Tuple<FencePoint, FencePoint>> sides, Pacman_location_db point)
 {
     int count = 0;
     foreach (Tuple<FencePoint, FencePoint> side in sides)
     {
         if (RayIntersectsSegment(point, side))
         {
             count += 1;
         }
     }
     if (IsOdd(count))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 public void MarkAsModifiedPacman_location_db(Pacman_location_db item)
 {
 }
        public IHttpActionResult PostPacman_location_db(Pacman_location_db location)
        {
            checkFence cf = new checkFence();
            var client = (from c in db.Pacman_carer_db
                          where c.ID == location.id_carer
                          select c).FirstOrDefault();
            cf.careDeviceId = client.device_id;

            var pncl = (from c in db.Pacman_patient_db
                        where c.ID == location.id_patient
                        select c).FirstOrDefault();
            cf.patientName = pncl.name;

            if (location != null)
            {
                location.ID = null;
            }
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Pacman_location_db.Add(location);
            db.SaveChanges();

            location = db.Pacman_location_db.Find(location.ID);

            if (location != null)
            {

                cf.patientx = location.coordinates_x;
                cf.patienty = location.coordinates_y;
                var fence = (from f in db.Pacman_fence_db
                             where (f.id_patient == location.id_patient)
                             orderby f.ID descending
                             select f).FirstOrDefault();
                if (fence != null)
                {
                    cf.fencex = Convert.ToDecimal(fence.Latitude);
                    cf.fencey = Convert.ToDecimal(fence.Longitude);
                    cf.radius = fence.radius;

                    cf.distanceCheck();
                }

                try
                {
                    var pFence  = (from f in db.Fences
                             where f.PatientID == location.id_patient
                             orderby f.ID descending
                             select f).FirstOrDefault();

                    if (pFence != null) {
                        var points = from fencePoint in db.FencePoints
                                     where fencePoint.FenceID == pFence.ID
                                     orderby fencePoint.ID
                                     select fencePoint;

                        var sides = Tuplise(points.ToList());

                        if (!CheckPolygonFence.CheckPointInside(sides, location))
                        {
                            cf.alarm();
                        }
                    }

                }
                catch (Exception ex)
                {

                }

            }

            return CreatedAtRoute("DefaultApi", new { id = location.ID }, location);
        }
 public void MarkAsModifiedPacman_location_db(Pacman_location_db item)
 {
     Entry(item).State = EntityState.Modified;
 }
示例#9
0
 public void MarkAsModifiedPacman_location_db(Pacman_location_db item)
 {
     Entry(item).State = EntityState.Modified;
 }
        public void HexagonFence()
        {
            Models.FencePoint point1 = new Models.FencePoint()
            {
                Latitude = 1,
                Longitude = 0
            };
            Models.FencePoint point2 = new Models.FencePoint()
            {
                Latitude = 3,
                Longitude = 0
            };
            Models.FencePoint point3 = new Models.FencePoint()
            {
                Latitude = 4,
                Longitude = 2
            };
            Models.FencePoint point4 = new Models.FencePoint()
            {
                Latitude = 3,
                Longitude = 4
            };
            Models.FencePoint point5 = new Models.FencePoint()
            {
                Latitude = 1,
                Longitude = 4
            };
            Models.FencePoint point6 = new Models.FencePoint()
            {
                Latitude = 0,
                Longitude = 2
            };

            Tuple<Models.FencePoint, Models.FencePoint> side1 = new Tuple<Models.FencePoint, Models.FencePoint>(point1, point2);
            Tuple<Models.FencePoint, Models.FencePoint> side2 = new Tuple<Models.FencePoint, Models.FencePoint>(point2, point3);
            Tuple<Models.FencePoint, Models.FencePoint> side3 = new Tuple<Models.FencePoint, Models.FencePoint>(point3, point4);
            Tuple<Models.FencePoint, Models.FencePoint> side4 = new Tuple<Models.FencePoint, Models.FencePoint>(point4, point5);
            Tuple<Models.FencePoint, Models.FencePoint> side5 = new Tuple<Models.FencePoint, Models.FencePoint>(point5, point6);
            Tuple<Models.FencePoint, Models.FencePoint> side6 = new Tuple<Models.FencePoint, Models.FencePoint>(point6, point1);

            List<Tuple<Models.FencePoint, Models.FencePoint>> sides = new List<Tuple<Models.FencePoint, Models.FencePoint>>();
            sides.Add(side1);
            sides.Add(side2);
            sides.Add(side3);
            sides.Add(side4);
            sides.Add(side5);
            sides.Add(side6);

            Pacman_location_db location = new Pacman_location_db
            {
                coordinates_x = 3,
                coordinates_y = 1
            };

            Assert.IsTrue(CheckPolygonFence.CheckPointInside(sides, location));
        }
        public void TriangleFence()
        {
            Models.FencePoint point1 = new Models.FencePoint()
            {
                Latitude = 0,
                Longitude = 0
            };
            Models.FencePoint point2 = new Models.FencePoint()
            {
                Latitude = 2,
                Longitude = 0
            };
            Models.FencePoint point3 = new Models.FencePoint()
            {
                Latitude = 0,
                Longitude = 1
            };

            Tuple<Models.FencePoint, Models.FencePoint> side1 = new Tuple<Models.FencePoint, Models.FencePoint>(point1, point2);
            Tuple<Models.FencePoint, Models.FencePoint> side2 = new Tuple<Models.FencePoint, Models.FencePoint>(point2, point3);
            Tuple<Models.FencePoint, Models.FencePoint> side3 = new Tuple<Models.FencePoint, Models.FencePoint>(point3, point1);

            List<Tuple<Models.FencePoint, Models.FencePoint>> sides = new List<Tuple<Models.FencePoint, Models.FencePoint>>();
            sides.Add(side1);
            sides.Add(side2);
            sides.Add(side3);

            Pacman_location_db location = new Pacman_location_db
            {
                coordinates_x = 3,
                coordinates_y = 1
            };

            Assert.IsTrue(!CheckPolygonFence.CheckPointInside(sides, location));
        }
        public void IrregularConvexFence()
        {
            Models.FencePoint point1 = new Models.FencePoint()
            {
                Latitude = 2,
                Longitude = 2
            };
            Models.FencePoint point2 = new Models.FencePoint()
            {
                Latitude = 6,
                Longitude = 1
            };
            Models.FencePoint point3 = new Models.FencePoint()
            {
                Latitude = 2,
                Longitude = 4
            };
            Models.FencePoint point4 = new Models.FencePoint()
            {
                Latitude = 0,
                Longitude = 4
            };

            Tuple<Models.FencePoint, Models.FencePoint> side1 = new Tuple<Models.FencePoint, Models.FencePoint>(point1, point2);
            Tuple<Models.FencePoint, Models.FencePoint> side2 = new Tuple<Models.FencePoint, Models.FencePoint>(point2, point3);
            Tuple<Models.FencePoint, Models.FencePoint> side3 = new Tuple<Models.FencePoint, Models.FencePoint>(point3, point4);
            Tuple<Models.FencePoint, Models.FencePoint> side4 = new Tuple<Models.FencePoint, Models.FencePoint>(point4, point1);

            List<Tuple<Models.FencePoint, Models.FencePoint>> sides = new List<Tuple<Models.FencePoint, Models.FencePoint>>();
            sides.Add(side1);
            sides.Add(side2);
            sides.Add(side3);
            sides.Add(side4);

            Pacman_location_db location = new Pacman_location_db
            {
                coordinates_x = 4,
                coordinates_y = 3
            };

            Assert.IsTrue(!CheckPolygonFence.CheckPointInside(sides, location));
        }