Пример #1
0
        private Vertex GetVertex(Vector2 position, List <Vertex> currentVertices)
        {
            var result = currentVertices.Find(v => Vector2.DistanceSquared(v.Position, position) < 0.1 * 0.1);

            if (result == null)
            {
                result = new Vertex(this, currentVertices.Count, position);
                currentVertices.Add(result);
            }

            return(result);
        }
Пример #2
0
        public TFaceData GetNearestFace(Vector2 position)
        {
            var distance = float.MaxValue;
            var result   = _faces.First();

            foreach (var face in _faces)
            {
                if (Vector2.DistanceSquared(position, face.Center) < distance)
                {
                    distance = Vector2.DistanceSquared(position, face.Center);
                    result   = face;
                }
            }

            return(result.Data);
        }
Пример #3
0
        public Face GetFaceFor(Vector2 position)
        {
            if (!Bounds.Contains(position))
            {
                return(null);
            }

            var  minDistance = float.MaxValue;
            Face result      = null;

            for (int i = 0; i < _faces.Length; i++)
            {
                var cellDistance = Vector2.DistanceSquared(position, _faces[i].Center);
                if (cellDistance < minDistance)
                {
                    minDistance = cellDistance;
                    result      = _faces[i];
                }
            }

            return(result);
        }