Exemplo n.º 1
0
        private Corner MakeCorner(Vector point)
        {
            if (point == null)
            {
                return(null);
            }
            int bucket;

            for (bucket = (int)point.X - 1; bucket <= (int)point.X + 1; bucket++)
            {
                foreach (Corner possibleCorner in (ArrayList)_cornerMap[bucket])
                {
                    var dx = point.X - possibleCorner.location.X;
                    var dy = point.Y - possibleCorner.location.Y;
                    if (dx * dx + dy * dy < 1E-6)
                    {
                        return(possibleCorner);
                    }
                }
            }
            bucket = (int)point.X;
            if (_cornerMap[bucket] == null)
            {
                _cornerMap[bucket] = new ArrayList();
            }
            var corner = new Corner {
                index     = _corners.Count,
                location  = point,
                mapBorder =
                    (Math.Abs(point.X) < 1E-6 || Math.Abs(point.X - _size) < 1E-6 || Math.Abs(point.Y) < 1E-6 ||
                     Math.Abs(point.Y - _size) < 1E-6),
                touches   = new HashSet <Center>(),
                protrudes = new HashSet <Edge>(),
                adjacent  = new HashSet <Corner>()
            };

            _corners.Add(corner);
            _cornerMap[bucket] = corner;
            return(corner);
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Add another vector
 /// </summary>
 /// <param name="vector">V</param>
 public void Add(Vector vector)
 {
     for (var i = 0; i < Dimension; i++) {
         this[i] += vector[i];
     }
 }
Exemplo n.º 3
0
 /// <summary>
 ///     Build a new vector as a copy of an existing one
 /// </summary>
 /// <param name="vector">The existing vector</param>
 public Vector(Vector vector)
     : this(vector._data)
 {
 }
Exemplo n.º 4
0
 public static double Dist(Vector vector, Site site)
 {
     if (vector.Dimension != 2) {
         return -1;
     }
     return Math.Pow(vector.X - site.X, 2) + Math.Pow(vector.Y - site.Y, 2); ;
 }
Exemplo n.º 5
0
 /// <summary>
 ///     Get the distance of two vectors
 /// </summary>
 public static double Dist(Vector a, Vector b)
 {
     if (a.Dimension != b.Dimension) {
         return -1;
     }
     var distance = 0.0d;
     for (var i = 0; i < a.Dimension; i++) {
         distance += Math.Pow(a[i] - b[i], 2);
     }
     return distance;
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Subtract two vectors
 /// </summary>
 public static Vector operator -(Vector a, Vector b)
 {
     if (a.Dimension != b.Dimension) {
         throw new Exception("Vectors of different dimension!");
     }
     var vector = new Vector(a.Dimension);
     for (var i = 0; i < a.Dimension; i++) {
         vector[i] = a[i] - b[i];
     }
     return vector;
 }
Exemplo n.º 7
0
 /// <summary>
 ///     Scale one vector
 /// </summary>
 public static Vector operator *(Vector vector, double scalar)
 {
     var newVector = new Vector(vector.Dimension);
     for (var i = 0; i < vector.Dimension; i++) {
         newVector[i] = vector[i] * scalar;
     }
     return newVector;
 }
Exemplo n.º 8
0
 private Corner MakeCorner(Vector point)
 {
     if (point == null) {
         return null;
     }
     int bucket;
     for (bucket = (int) point.X - 1; bucket <= (int) point.X + 1; bucket++) {
         foreach (Corner possibleCorner in (ArrayList) _cornerMap[bucket]) {
             var dx = point.X - possibleCorner.location.X;
             var dy = point.Y - possibleCorner.location.Y;
             if (dx * dx + dy * dy < 1E-6) {
                 return possibleCorner;
             }
         }
     }
     bucket = (int) point.X;
     if (_cornerMap[bucket] == null) {
         _cornerMap[bucket] = new ArrayList();
     }
     var corner = new Corner {
         index = _corners.Count,
         location = point,
         mapBorder =
             (Math.Abs(point.X) < 1E-6 || Math.Abs(point.X - _size) < 1E-6 || Math.Abs(point.Y) < 1E-6 ||
              Math.Abs(point.Y - _size) < 1E-6),
         touches = new HashSet<Center>(),
         protrudes = new HashSet<Edge>(),
         adjacent = new HashSet<Corner>()
     };
     _corners.Add(corner);
     _cornerMap[bucket] = corner;
     return corner;
 }