Пример #1
0
        /**
         * Adds a TemperatureSetPoint to the Weather Simulation.
         */
        public void Add(TemperatureSetPoint temp)
        {
            int idx = _temps.BinarySearch(temp);

            if (idx == 0)
            {
                _temps.Add(temp);
                return;
            }
            else if (idx < 0)
            {
                idx = ~idx;
            }
            _temps.Insert(idx, temp);
        }
Пример #2
0
        /**
         * Gets the temperature at the given time. Will conver the given time to the
         * internal TimeFrame if requested, otherwise assumes the given time is valid in that TimeFrame.
         * \param[in] now Time to get temperature for.
         * \param[in] convertTime Flag indicating if time should be converted.
         * \param[out] Temperature in Celsius
         */
        public Double Temperature(DateTime now, bool convertTime = false)
        {
            if (_temps.Count == 0)
            {
                return(Double.NaN);
            }
            if (convertTime)
            {
                now = Frame.time(now);
            }
            var search_point = new TemperatureSetPoint(now, 0.0);
            int idx          = _temps.BinarySearch(search_point);

            Double temp;

            if (idx >= 0)
            {
                temp = _temps[idx].Temp;
            }
            else
            {
                idx = ~idx;

                if (idx == _temps.Count)
                {
                    temp = _temps[idx - 1].Temp;
                }
                else
                {
                    int low_idx = idx - 1;

                    DateTime low_time = _temps[low_idx].Time;
                    Double   now_dt   = (now - low_time).TotalSeconds;
                    Double   all_dt   = (_temps[idx].Time - low_time).TotalSeconds;
                    Double   dTemp    = _temps[idx].Temp - _temps[low_idx].Temp;
                    temp = _temps[low_idx].Temp + dTemp * (now_dt / all_dt);
                }
            }

            return(temp);
        }