Пример #1
0
        public ModelPointList(ModelPoint initStrengthPoint, ModelPoint lifetimePoint, ModelPoint[] initIntermediatePoints = null)
        {
            if (initStrengthPoint.Time != 0.0f)
            {
                Debug.LogError("Initial strength point must have a time value of zero!");
                initStrengthPoint.Time = 0.0f;
            }

            if (lifetimePoint.Strength != 0.0f)
            {
                Debug.LogError("Lifetime point must have a strength value of zero!");
                lifetimePoint.Strength = 0.0f;
            }

            _start    = new ModelPointNode(initStrengthPoint);
            _end      = new ModelPointNode(lifetimePoint);
            _comparer = new ModelPointComparer();

            _start.next   = _end;
            _end.previous = _start;

            if (initIntermediatePoints != null)
            {
                foreach (ModelPoint mp in initIntermediatePoints)
                {
                    this.Add(mp);
                }
            }
        }
Пример #2
0
        public bool RecalculateLine(ModelPoint p1, ModelPoint p2)
        {
            if (p1.Time == p2.Time)
            {
                Debug.LogError("Model line cannot have an infinite slope");
                return(false);
            }

            _slope      = (float)Math.Round((p2.Strength - p1.Strength) / (p2.Time - p1.Time), 2);
            _yIntercept = (float)Math.Round(p2.Strength - _slope * p2.Time, 2);
            return(true);
        }
Пример #3
0
 public override bool Equals(object obj)
 {
     if (obj == null || !this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         ModelPoint point = (ModelPoint)obj;
         return(this == point);
     }
 }
Пример #4
0
        /// <summary>
        /// Checks if the list contains the given point
        /// </summary>
        public bool Contains(ModelPoint point)
        {
            ModelPointNode currentNode = _start;

            while (currentNode != null)
            {
                if (currentNode.Value == point)
                {
                    return(true);
                }
                currentNode = currentNode.next;
            }

            return(false);
        }
Пример #5
0
        /// <summary>
        /// Returns the list's modelpoints as an array
        /// </summary>
        public ModelPoint[] ToArray()
        {
            ModelPoint[]   pointArray = new ModelPoint[this.Count];
            ModelPointNode current    = _start;
            int            idx        = 0;

            while (current != null)
            {
                pointArray[idx] = current.Value;
                idx++;
                current = current.next;
            }

            return(pointArray);
        }
Пример #6
0
        /// <summary>
        /// get the point's index in this list
        /// returns -1 if it isn't in the list
        /// </summary>
        public int IndexOf(ModelPoint point)
        {
            int            idx         = 0;
            ModelPointNode currentNode = _start;

            while (currentNode != null)
            {
                if (currentNode.Value == point)
                {
                    return(idx);
                }
                idx++;
                currentNode = currentNode.next;
            }

            return(-1);
        }
Пример #7
0
        /// <summary>
        /// Based on given points, construct dictionary relating lines to their domains
        /// </summary>
        public MagnitudeDropoffModel(ModelPointList pointList)
        {
            //_modelPoints = pointList;

            _points = pointList.ToArray();
            _lines  = new Dictionary <ModelTimeDomain, ModelLine>();

            // calculate model's lines and their corresponding time domains
            for (int i = 0; i < _points.Length - 1; i++)
            {
                ModelPoint p1 = _points[i];
                ModelPoint p2 = _points[i + 1];

                ModelLine       line   = new ModelLine(p1, p2);
                ModelTimeDomain domain = new ModelTimeDomain(p1.Time, p2.Time);
                _lines.Add(domain, line);
            }
        }
Пример #8
0
        /// <summary>
        /// Adds point to list, keeping order with the other nodes
        /// Returns true if addition successful, false otherwise
        /// </summary>
        public bool Add(ModelPoint point)
        {
            // check that point is within the model's bounds
            if (!PointInBounds(point))
            {
                Debug.LogWarning("Point " + point.ToString() + " is not in bounds");
                return(false);
            }

            // don't add if point already in the list
            if (Contains(point))
            {
                Debug.LogWarning("List already contains point " + point.ToString());
                return(false);
            }

            ModelPointNode currentNode = _start;

            while (currentNode.next != null &&
                   !(_comparer.Compare(point, currentNode.Value) == 1 &&
                     _comparer.Compare(point, currentNode.next.Value) == -1))
            {
                currentNode = currentNode.next;
            }

            if (currentNode.next == null)
            {
                return(false);
            }
            else
            {
                ModelPointNode newNode  = new ModelPointNode(point);
                ModelPointNode nextNode = currentNode.next;

                currentNode.next  = newNode;
                newNode.next      = nextNode;
                newNode.previous  = currentNode;
                nextNode.previous = newNode;

                return(true);
            }
        }
Пример #9
0
        /// <summary>
        /// Removes point from the list
        /// </summary>
        public bool Remove(ModelPoint point)
        {
            // can't remove an out of bounds point
            if (!PointInBounds(point))
            {
                Debug.LogWarning("Point " + point.ToString() + " is not in bounds");
                return(false);
            }

            // can't remove the start or end points
            if (point == _start.Value || point == _end.Value)
            {
                Debug.LogWarning("Cannot remove the start or end point");
                return(false);
            }

            // iterate through intermediate points to find the point
            ModelPointNode currentNode = _start;

            while (currentNode.next != null && currentNode.next.Value != point)
            {
                currentNode = currentNode.next;
            }

            // point not in list
            if (currentNode.next == null)
            {
                return(false);
            }
            else
            {
                ModelPointNode newNext = currentNode.next.next;
                currentNode.next = newNext;
                newNext.previous = currentNode;
                return(true);
            }
        }
Пример #10
0
 public bool Contains(ModelPoint mp)
 {
     return(Contains(mp.Time));
 }
Пример #11
0
 public ModelLine(ModelPoint p1, ModelPoint p2)
 {
     _slope      = 0.0f;
     _yIntercept = 0.0f;
     RecalculateLine(p1, p2);
 }
Пример #12
0
 /// <summary>
 /// Checks if the given point is within the list's start and end point's times
 /// </summary>
 public bool PointInBounds(ModelPoint point)
 {
     return(_comparer.Compare(_start.Value, point) < 0 && _comparer.Compare(_end.Value, point) > 0);
 }
Пример #13
0
 public ModelPointNode(float t, float s)
 {
     _value = new ModelPoint(t, s);
 }
Пример #14
0
 public ModelPointNode(ModelPoint mp)
 {
     _value = mp;
 }
Пример #15
0
 public static ModelPoint MultiplyByTimeAndStrength(float timeFactor, float strengthFactor, ModelPoint mp)
 {
     return(new ModelPoint(timeFactor * mp.Time, strengthFactor * mp.Strength));
 }