示例#1
0
        public ToolForm(Control target, EPin pin, Point ofs, Size size, bool modal)
        {
            m_ofs = ofs;
            m_pin = pin;
            Owner = target?.TopLevelControl as Form;
            Icon  = Owner?.Icon;
            AutoScaleDimensions = new SizeF(6F, 13F);
            AutoScaleMode       = AutoScaleMode.Font;
            StartPosition       = FormStartPosition.Manual;
            HideOnClose         = !modal;
            AutoFade            = false;
            FadeRange           = new RangeF(1.0, 1.0);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            if (size != Size.Empty)
            {
                Size = size;
            }

            // Pin to the target window
            PinWindow = true;
            PinTarget = target;

            // Calling CreateHandle here prevents this window appearing over the parent if the parent is TopMost
            //if (!modal)
            //	CreateHandle();
        }
        /// <summary>
        /// Add extruded point(s) based on two neighbouring line segments.
        /// </summary>
        /// <param name="linePointAndForwardSegment">A line point and its corresponding segment.</param>
        /// <param name="previousLinePointAndForwardSegment">The previous line point and its corresponding segment.</param>
        /// <param name="nextLinePoint">The next line point (since its parameter, uv etc will be needed).</param>
        /// <param name="lineSegmentIndexToAssign">Line segment index to assign the extruded point coming from.</param>
        /// <param name="extrusionAmount">The extrusion amount.</param>
        /// <param name="extrudedLinePoints">The list of all extruded line points.</param>
        /// <param name="findParameter">Delegate for determining altered point parameter.</param>
        private static void AddPointExtrusionFromPreviousNextSegments(LinePointUVAndSegment linePointAndForwardSegment, LinePointUVAndSegment previousLinePointAndForwardSegment, LinePointUV nextLinePoint, int lineSegmentIndexToAssign, float extrusionAmount, List <ExtrudedPointUV> extrudedLinePoints, GetShiftedScaledParameter findParameter)
        {
            double extrusionMagnitudeFractionFirstTangent;
            bool   segmentIntersection = LineSegmentUtil.DoNeighbouringSegmentTangentsFromCommonPointIntersect(previousLinePointAndForwardSegment.SegmentTangent, linePointAndForwardSegment.SegmentTangent, Mathf.Sign(extrusionAmount), out extrusionMagnitudeFractionFirstTangent);

            if (segmentIntersection)
            {
                //Concave section; expect intersection of neighbouring line segments around this point
                var  extrusionDistanceAlongTangents = Mathf.Abs((float)extrusionMagnitudeFractionFirstTangent * extrusionAmount);
                bool intersectionOccursOutOfSegment = extrusionDistanceAlongTangents >= Mathf.Min(previousLinePointAndForwardSegment.SegmentLength, linePointAndForwardSegment.SegmentLength);
                if (intersectionOccursOutOfSegment)
                {
                    AttemptAddNaiveExtrudedPointsWhenTheirExtrudedSegmentsDoNotIntersect(linePointAndForwardSegment, previousLinePointAndForwardSegment, lineSegmentIndexToAssign, extrusionAmount, extrudedLinePoints, findParameter, extrusionDistanceAlongTangents);
                }
                else
                {
                    var intersection = LineSegmentUtil.GetExtrudedSegmentNeighbouringIntersectionPoint(linePointAndForwardSegment.Point, previousLinePointAndForwardSegment.SegmentTangent, extrusionMagnitudeFractionFirstTangent, extrusionAmount);
                    var linePointOfThisIntersection = new LinePointUV(findParameter(linePointAndForwardSegment.Parameter), intersection, linePointAndForwardSegment.UV);
                    extrudedLinePoints.Add(new ExtrudedPointUV(linePointOfThisIntersection, lineSegmentIndexToAssign, lineSegmentIndexToAssign - 1));
                }
            }
            else
            {
                //Convex section, expect a circular fan of points around this point.
                RangeF rangeFromPreviousPoints = new RangeF(findParameter(previousLinePointAndForwardSegment.Parameter), findParameter(linePointAndForwardSegment.Parameter));
                RangeF rangeFromNextPoints     = new RangeF(findParameter(linePointAndForwardSegment.Parameter), findParameter(nextLinePoint.Parameter));
                RangeF parameterRangeToUse     = new RangeF(rangeFromPreviousPoints.FromFractionUnclamped(0.6f), rangeFromNextPoints.FromFractionUnclamped(0.4f));

                var   extrudedFromPreviousNormal     = linePointAndForwardSegment.Point + extrusionAmount * previousLinePointAndForwardSegment.SegmentNormal;
                var   extrudedFromNextNormal         = linePointAndForwardSegment.Point + extrusionAmount * linePointAndForwardSegment.SegmentNormal;
                var   diffBetweenExtrusion           = (extrudedFromNextNormal - extrudedFromPreviousNormal).magnitude;
                var   minNeighbouringSegmentDistance = Mathf.Min(previousLinePointAndForwardSegment.SegmentLength, linePointAndForwardSegment.SegmentLength);
                float absExtrusionAmount             = Mathf.Abs(extrusionAmount);
                var   comparisonDistance             = Mathf.Min(minNeighbouringSegmentDistance, absExtrusionAmount);

                var angleBetweenSegmentNormals = Mathf.Acos(Mathf.Clamp(Vector3.Dot(previousLinePointAndForwardSegment.SegmentNormal, linePointAndForwardSegment.SegmentNormal), -1f, 1f));

                int numPointsFromDistance = Mathf.CeilToInt(diffBetweenExtrusion / comparisonDistance);
                if (numPointsFromDistance <= 2)
                {
                    numPointsFromDistance++;
                }                                                           //NB Want at least the end-points, and if distance is large enough to need 2 naturally, 3 seems to looks better.
                int numPointsFromAngle = Mathf.CeilToInt(angleBetweenSegmentNormals / _convexExtrusionMinimumAngleRadians);
                int numPoints          = Mathf.Max(numPointsFromDistance, numPointsFromAngle);

                for (int i = 0; i < numPoints; i++)
                {
                    float fraction       = numPoints == 1 ? 0.5f : i / (numPoints - 1.0f);
                    var   averageTangent = previousLinePointAndForwardSegment.SegmentTangent.AverageDirectionVector(linePointAndForwardSegment.SegmentTangent, fraction);
                    var   averageNormal  = NormalUtil.NormalFromTangent(averageTangent);
                    var   extrudedVector = linePointAndForwardSegment.Point + averageNormal * extrusionAmount;
                    var   parameter      = parameterRangeToUse.FromFractionUnclamped(fraction);

                    Vector2 newUV = GetUVParameterOfFanPoint(linePointAndForwardSegment, previousLinePointAndForwardSegment, nextLinePoint, absExtrusionAmount, angleBetweenSegmentNormals, fraction);

                    var newLinePointInFan = new LinePointUV(parameter, extrudedVector, newUV);
                    extrudedLinePoints.Add(new ExtrudedPointUV(newLinePointInFan, lineSegmentIndexToAssign, lineSegmentIndexToAssign - 1));
                }
            }
        }
示例#3
0
        /// <summary>
        /// Add a plot of the 1D histogram. You should call the Refresh() function to update the control after all modification is complete.
        /// </summary>
        /// <param name="name">The name of the histogram</param>
        /// <param name="color">The drawing color</param>
        /// <param name="histogram">The 1D histogram to be drawn</param>
        public void AddHistogram(String name, Color color, DenseHistogram histogram)
        {
            Debug.Assert(histogram.Dimension == 1, Properties.StringTable.Only1DHistogramSupported);

            GraphPane pane = new GraphPane();

            // Set the Title
            pane.Title.Text       = name;
            pane.XAxis.Title.Text = Properties.StringTable.Value;
            pane.YAxis.Title.Text = Properties.StringTable.Count;

            #region draw the histogram
            RangeF   range   = histogram.Ranges[0];
            int      binSize = histogram.BinDimension[0].Size;
            float    step    = (range.Max - range.Min) / binSize;
            float    start   = range.Min;
            double[] bin     = new double[binSize];
            for (int binIndex = 0; binIndex < binSize; binIndex++)
            {
                bin[binIndex] = start;
                start        += step;
            }

            PointPairList pointList = new PointPairList(
                bin,
                Array.ConvertAll <float, double>((float[])histogram.MatND.ManagedArray, System.Convert.ToDouble));

            pane.AddCurve(name, pointList, color);
            #endregion

            zedGraphControl1.MasterPane.Add(pane);
        }
示例#4
0
        /// <summary>
        /// Return the nearest significant support level above or below 'price'.
        /// 'sign' is the direction to look for a level. +1 means above, -1 means below, 0 means either side.
        /// 'min_dist' means the nearest SnR level >= price + sign * min_dist (default: 0 if sign=0, 0.25*MCS if sign=±1)
        /// 'range' is a bound on the levels to check (default: no range limit)
        /// 'radius' is a shortcut for Range(price - radius, price + radius). (Default: ignored) </summary>
        public Level Nearest(QuoteCurrency price, int sign, QuoteCurrency?min_dist = null, RangeF?range = null, QuoteCurrency?radius = null, double?min_strength = 0.5)
        {
            // Set the range
            if (radius != null && range == null)
            {
                range = new RangeF((double)(price - radius), (double)(price + radius));
            }

            // Set the minimum if not provided
            min_dist = min_dist ?? (sign == 0 ? 0 : 0.25 * Instrument.MCS);

            // Get the threshold price
            var thresh = price + sign * min_dist.Value;

            // Find levels above/below the threshold
            var levels = (IEnumerable <Level>)SnRLevels;

            if (range != null)
            {
                levels = levels.Where(x => range.Value.Contains((double)x.Price));
            }
            if (sign != 0)
            {
                levels = levels.Where(x => Math.Sign(x.Price - thresh) == sign);
            }
            if (min_strength != null)
            {
                levels = levels.Where(x => x.Strength >= min_strength.Value);
            }

            // Return the levels closed to 'price'
            return(levels.MinByOrDefault(x => Math.Abs(x.Price - price)));
        }
示例#5
0
        public ToolFormUI(Control owner) : base(owner, EPin.TopRight)
        {
            InitializeComponent();
            AutoFade = true;

            m_combo_pin_to.Items.AddRange(Enum <EPin> .Values.Cast <object>().ToArray());
            m_combo_pin_to.SelectedIndexChanged += (s, a) =>
            {
                Pin = (EPin)m_combo_pin_to.SelectedItem;
            };

            PopulateChildCombo(owner.TopLevelControl);
            m_combo_child.DisplayMember         = "Name";
            m_combo_child.SelectedIndexChanged += (s, a) =>
            {
                PinTarget = (Control)m_combo_child.SelectedItem;
            };

            m_track_autofade.Value         = m_track_autofade.Maximum;
            m_track_autofade.ValueChanged += (s, a) =>
            {
                FadeRange = new RangeF(Math_.Frac(m_track_autofade.Minimum, m_track_autofade.Value, m_track_autofade.Maximum), 1f);
            };

            m_cb_form_border.Items.AddRange(Enum <FormBorderStyle> .ValuesArray);
            m_cb_form_border.SelectedIndexChanged += (s, a) =>
            {
                FormBorderStyle = (FormBorderStyle)m_cb_form_border.SelectedItem;
            };
        }
示例#6
0
 public SmokeParticleDelegate(AtlasGlobal atlas, float totalLife)
     : base(atlas)
 {
     _totalLife = totalLife;
     drag       = 1;
     strength   = new RangeF();
 }
示例#7
0
        public static string WriteDiscountRange(Item item, Shop shop)
        {
            if (item == null || shop == null)
            {
                return("");
            }

            var info = new StringBuilder();

            CatalogEntry entry = shop.Catalog?.Entries.FirstOrDefault(x => x.ItemId == item.Id);

            if (entry == null)
            {
                return("");
            }

            if (entry.DiscountChance <= 0)
            {
                return("");
            }

            info.Append($"(**{entry.MinDiscount ?? CatalogEntry.DefaultMinDiscount}**% to ");
            info.Append($"**{entry.MaxDiscount ?? CatalogEntry.DefaultMaxDiscount}**% discount range");

            info.Append($", **{RangeF.Convert(0, 1, 0, 100, entry.DiscountChance):##,0.##}**% chance of discount)");

            return(info.ToString());
        }
示例#8
0
        /// <summary>Add XML serialisation support for graphics types</summary>
        public static XmlConfig SupportRylogicCommonTypes(this XmlConfig cfg)
        {
            Xml_.ToMap[typeof(RangeI)] = (obj, node) =>
            {
                var r = (RangeI)obj;
                node.SetValue($"{r.Beg} {r.End}");
                return(node);
            };
            Xml_.AsMap[typeof(RangeI)] = (elem, type, instance) =>
            {
                return(RangeI.Parse(elem.Value));
            };

            Xml_.ToMap[typeof(RangeF)] = (obj, node) =>
            {
                var r = (RangeF)obj;
                node.SetValue($"{r.Beg} {r.End}");
                return(node);
            };
            Xml_.AsMap[typeof(RangeF)] = (elem, type, instance) =>
            {
                return(RangeF.Parse(elem.Value));
            };

            return(cfg);
        }
示例#9
0
        public SimExchange(Simulation sim, Exchange exch, PriceDataMap price_data)
        {
            try
            {
                Debug.Assert(Model.BackTesting == true);

                Sim       = sim;
                Exchange  = exch;
                PriceData = price_data;
                m_ord     = new LazyDictionary <long, Order>(k => null);
                m_his     = new LazyDictionary <long, OrderCompleted>(k => null);
                m_bal     = new LazyDictionary <Coin, AccountBalance>(k => new AccountBalance(k, 0m._(k)));
                m_depth   = new LazyDictionary <TradePair, MarketDepth>(k => new MarketDepth(k.Base, k.Quote));
                m_rng     = null;

                // Cache settings values
                m_order_value_range = SettingsData.Settings.BackTesting.OrderValueRange;
                m_spread_frac       = SettingsData.Settings.BackTesting.SpreadFrac;
                m_orders_per_book   = SettingsData.Settings.BackTesting.OrdersPerBook;

                Exchange.Sim = this;

                Reset();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
示例#10
0
 public static string ToStringE(this RangeF range)
 {
     return(string.Format(
                "[{0}=>{1}]"
                , range.Min
                , range.Max));
 }
示例#11
0
        public ColorContainer(ShemaLayer layer, RangeF rangeF)
        {
            __MinAlt = rangeF.Min;
            __MaxAlt = rangeF.Max;

            __AltRange = __MaxAlt - __MinAlt;

            int cNum = 0;
            int oldcNum = 0;

            __ColorTable = new UColor[MAX_COLOR_INDEX];

            layer.SortColors();

            foreach (var ch in layer.ColorHeights)
            {
                cNum = ch.Heigth;

                ReadColor(oldcNum, cNum, ch.Color);

                oldcNum = cNum;
            }

            __MaxHeight = cNum;
        }
示例#12
0
 public CandlePattern(ECandlePattern pattern, TradeType tt, RangeF range, Idx index, QuoteCurrency ep)
 {
     Pattern = pattern;
     TT      = tt;
     Range   = range;
     Index   = index;
     EP      = ep;
 }
示例#13
0
 /// <summary>
 /// Creates a uniform 1-D histogram of the specified size
 /// </summary>
 /// <param name="binSize">The number of bins in this 1-D histogram. </param>
 /// <param name="range">The lower (inclusive) and upper (exclusive) boundary of the bin</param>
 public DenseHistogram(int binSize, RangeF range)
     : this(new int[1] {
     binSize
 }, new RangeF[1] {
     range
 })
 {
 }
 private void ComputeRange(IEnumerable <Point> points, int idx, ref RangeF range)
 {
     foreach (Point point in points)
     {
         range.UpdateMin(point.Position[idx]);
         range.UpdateMax(point.Position[idx]);
     }
 }
示例#15
0
        public void CenterTest_BothPositive()
        {
            RangeF range = new RangeF(3, 5);

            float expected = 4.0f;
            float actual   = range.Center;

            Assert.AreEqual(expected, actual);
        }
示例#16
0
        public void LengthTest_NegativeNegative()
        {
            RangeF range = new RangeF(-5, -3);

            float expected = 2.0f;
            float actual   = range.Length;

            Assert.AreEqual(expected, actual);
        }
示例#17
0
        public void EqualsTest_Equal()
        {
            RangeF thisRange  = new RangeF(1, 3);
            RangeF otherRange = new RangeF(1, 3);

            Assert.IsTrue(thisRange.Equals(otherRange));
            Assert.IsTrue(otherRange.Equals(thisRange));
            Assert.AreEqual(thisRange.GetHashCode(), otherRange.GetHashCode());
        }
示例#18
0
        public void LengthTest_BothPositive()
        {
            RangeF range = new RangeF(3, 5);

            float expected = 2.0f;
            float actual   = range.Length;

            Assert.AreEqual(expected, actual);
        }
示例#19
0
        public void EqualsTest_BothNotEqual()
        {
            RangeF thisRange  = new RangeF(2, 3);
            RangeF otherRange = new RangeF(1, 4);

            Assert.IsFalse(thisRange.Equals(otherRange));
            Assert.IsFalse(otherRange.Equals(thisRange));
            Assert.AreNotEqual(thisRange.GetHashCode(), otherRange.GetHashCode());
        }
示例#20
0
        public void CenterTest_NegativeNegative()
        {
            RangeF range = new RangeF(-5, -3);

            float expected = -4.0f;
            float actual   = range.Center;

            Assert.AreEqual(expected, actual);
        }
示例#21
0
 /// <summary>Cause graphics model that intersect 'x_range' to be recreated</summary>
 public void FlushCachedGraphics(RangeF x_range)
 {
     Invalidate();
     Cache.Invalidate(x_range);
     if (m_range_x != RangeF.Invalid)
     {
         m_range_x.Grow(x_range);
     }
 }
示例#22
0
        public void UpdateMax_OriginalNotSet()
        {
            RangeF actual = new RangeF();

            actual.UpdateMax(-4);

            RangeF expected = new RangeF(float.MaxValue, -4);

            Assert.AreEqual(expected, actual);
        }
示例#23
0
        public void UpdateMax_GreaterThan()
        {
            RangeF actual = new RangeF(-5, -3);

            actual.UpdateMax(+7);

            RangeF expected = new RangeF(-5, 7);

            Assert.AreEqual(expected, actual);
        }
示例#24
0
        public void UpdateMin_SmallerThan()
        {
            RangeF actual = new RangeF(-5, -3);

            actual.UpdateMin(-7);

            RangeF expected = new RangeF(-7, -3);

            Assert.AreEqual(expected, actual);
        }
示例#25
0
 public ReleaseParameters()
 {
     Quantity = 1;
     Speed    = RangeF.Parse("[-1.0,1.0]");
     Colour   = new ColourRange(new Colour(0f, 0.5f, 0.5f), new Colour(360f, 0.5f, 0.5f));
     Opacity  = RangeF.Parse("[0.0,1.0]");
     Scale    = RangeF.Parse("[1.0,10.0]");
     Rotation = RangeF.Parse("[-3.14159,3.14159]");
     Mass     = 1f;
 }
示例#26
0
        public void UpdateMin_OriginalNotSet()
        {
            RangeF actual = new RangeF();

            actual.UpdateMin(-7);

            RangeF expected = new RangeF(-7, float.MinValue);

            Assert.AreEqual(expected, actual);
        }
 public ReleaseParameters()
 {
     Quantity = 1;
     Speed    = RangeF.Parse("[-1.0,1.0]");
     Colour   = new ColourRange(new Colour(0f, 0.5f, 0.5f), new Colour(360f, 0.5f, 0.5f));
     Opacity  = RangeF.Parse("[0.0,1.0]");
     Scale    = RangeF.Parse("[1.0,10.0]");
     Rotation = RangeF.Parse("[-3.14159,3.14159]");
     Mass     = 1f;
 }
示例#28
0
        /// <summary>Generate a piece of the graphics for 'x'</summary>
        private ChartGfxPiece CreatePiece(double x, RangeF missing)
        {
            Debug.Assert(missing.Contains(x));
            using (Lock())
            {
                // Find the nearest point in the data to 'x'
                var idx = m_data.BinarySearch(pt => pt.xf.CompareTo(x), find_insert_position: true);

                // Convert 'missing' to an index range within the data
                var idx_missing = new RangeI(
                    m_data.BinarySearch(pt => pt.xf.CompareTo(missing.Beg), find_insert_position: true),
                    m_data.BinarySearch(pt => pt.xf.CompareTo(missing.End), find_insert_position: true));

                // Limit the size of 'idx_missing' to the block size
                const int PieceBlockSize = 4096;
                var       idx_range      = new RangeI(
                    Math.Max(idx_missing.Beg, idx - PieceBlockSize),
                    Math.Min(idx_missing.End, idx + PieceBlockSize));

                // Create graphics over the data range 'idx_range'
                //todo: this isn't right... need to handle this function returning 'failed to create piece'
                switch (Options.PlotType)
                {
                default: throw new Exception($"Unsupported plot type: {Options.PlotType}");

                case EPlotType.Point:
                {
                    return(idx_range.Size > 0
                                                        ? CreatePointPlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }

                case EPlotType.Line:
                {
                    return(idx_range.Size > 1
                                                        ? CreateLinePlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }

                case EPlotType.StepLine:
                {
                    return(idx_range.Size > 1
                                                        ? CreateStepLinePlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }

                case EPlotType.Bar:
                {
                    return(idx_range.Size > 1
                                                        ? CreateBarPlot(idx_range)
                                                        : new ChartGfxPiece(null, missing));
                }
                }
            }
        }
示例#29
0
        private void SetMomentArea(float min, float max)
        {
            var momentRange = new RangeF();

            momentRange.Min = min;
            momentRange.Max = max;

            _detectorInput.Settings.MomentArea = momentRange;

            UpdateMomentSlidersFromSettings();
        }
示例#30
0
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------

        public MonsterZolGreen()
        {
            color         = MonsterColor.Green;
            MaxHealth     = 1;
            ContactDamage = 1;

            moveSpeed     = 0.75f;
            jumpSpeed     = new RangeF(2.0f);
            stopTime      = new RangeI(48);
            stopAnimation = GameData.ANIM_MONSTER_ZOL;
            jumpAnimation = GameData.ANIM_MONSTER_ZOL_JUMP;
        }
示例#31
0
        /// <summary>
        /// Add a plot of the 1D histogram.
        /// </summary>
        /// <param name="name">The name of the histogram</param>
        /// <param name="color">The drawing color</param>
        /// <param name="histogram">The 1D histogram to be drawn</param>
        /// <param name="binSize">The size of the bin</param>
        /// <param name="ranges">The ranges</param>
        /// <returns>The image of the histogram</returns>
        public Mat GenerateHistogram(String name, Color color, Mat histogram, int binSize, float[] ranges)
        {
            //Debug.Assert(histogram.Dimension == 1, Properties.StringTable.Only1DHistogramSupported);

            #region draw the histogram
            RangeF range = new RangeF(ranges[0], ranges[1]);

            float    step  = (range.Max - range.Min) / binSize;
            float    start = range.Min;
            double[] bin   = new double[binSize];
            for (int binIndex = 0; binIndex < binSize; binIndex++)
            {
                bin[binIndex] = start;
                start        += step;
            }

            double[] binVal = new double[histogram.Size.Height];
            GCHandle handle = GCHandle.Alloc(binVal, GCHandleType.Pinned);

            using (Matrix <double> m = new Matrix <double>(binVal.Length, 1, handle.AddrOfPinnedObject(),
                                                           sizeof(double)))
            {
                histogram.ConvertTo(m, DepthType.Cv64F);
            }
            handle.Free();

            using (VectorOfDouble x = new VectorOfDouble(bin))
                using (VectorOfDouble y = new VectorOfDouble(binVal))
                {
                    using (Emgu.CV.Plot.Plot2d plot = new Plot2d(x, y))
                    {
                        plot.SetShowText(false);
                        plot.SetPlotBackgroundColor(new MCvScalar(255, 255, 255));
                        plot.SetPlotLineColor(new MCvScalar(0, 0, 0));
                        plot.SetPlotGridColor(new MCvScalar(220, 220, 220));
                        plot.SetGridLinesNumber(255);
                        plot.SetPlotSize(512, 200);
                        plot.SetMinX(0);
                        plot.SetMaxX(256);
                        plot.SetMinY(-1);
                        plot.SetMaxY(binVal.Max());
                        plot.SetInvertOrientation(true);

                        Mat render = new Mat();
                        plot.Render(render);
                        CvInvoke.PutText(render, name, new Point(20, 30), FontFace.HersheyComplex, 0.8,
                                         new MCvScalar(0, 0, 255));
                        return(render);
                    }
                }
            #endregion
        }
示例#32
0
        /// <summary>Looks for a price channel in the recent candle history</summary>
        private PriceChannel?FindChannel(Idx iend)
        {
            const int    MinCandlesPerChannel = 12;
            const int    MaxCandlesPerChannel = 30;
            const double AspectThreshold      = 0.5;
            var          channel = (PriceChannel?)null;

            // Find the channel with the best aspect ratio
            var count       = 0;
            var range       = RangeF.Invalid;
            var best_aspect = AspectThreshold;

            for (var i = iend; i != Instrument.IdxFirst; --i, ++count)
            {
                range.Encompass(Instrument[i].Open);
                range.Encompass(Instrument[i].Close);
                if (count < MinCandlesPerChannel)
                {
                    continue;
                }
                if (count > MaxCandlesPerChannel)
                {
                    break;
                }

                // Aspect ratio of the channel (width/height)
                var aspect = count * Instrument.PipSize / range.Size;
                if (aspect > best_aspect)
                {
                    var idx_range = new RangeF(i, 1).Shift(-Instrument.IdxFirst);

                    // Eliminate channels that are not preceded by a trend
                    var d = MA[i] - MA[2 * i];
                    if (Math.Abs(d) < 2 * range.Size)
                    {
                        continue;
                    }

                    //	// Eliminate channels where price is not evenly distributed within the channel
                    //	var c = new Correlation();
                    //	int_.Range(i,1).ForEach(x => c.Add(x, Instrument[x].Close));
                    //	if (Math.Abs(c.LinearRegression.A) > 0.5 * range.Size / idx_range.Size)
                    //		continue;

                    // Possible channel
                    channel     = new PriceChannel(idx_range, range, Math.Sign(d));
                    best_aspect = aspect;
                }
            }

            return(channel);
        }
        protected virtual RangeF DetermineMapHeightRange()
        {
            RangeF range = new RangeF(float.MinValue, float.MaxValue);
            for (int x = 0; x < mapSize.Width; x++)
            {
                for (int y = 0; y < mapSize.Height; y++)
                {
                    float value = this[x, y];
                    if (value > range.Max)
                        range.Max = value;
                    if (value < range.Min)
                        range.Min = value;
                }
            }

            return range;
        }
    /// <summary>
    /// Calculates the rectangle boundaries of the polygon and stores the values in the polygon.
    /// </summary>
    public void RecalculateBoundaries()
    {
        var xBoundaries = new RangeF(float.MaxValue, float.MinValue);
        var zBoundaries = new RangeF(float.MaxValue, float.MinValue);

        foreach (var point in this.points)
        {
            if (point.x < xBoundaries.minimum)
            {
                xBoundaries.minimum = point.x;
            }
            if (point.x > xBoundaries.maximum)
            {
                xBoundaries.maximum = point.x;
            }
            if (point.z < zBoundaries.minimum)
            {
                zBoundaries.minimum = point.z;
            }
            if (point.z > zBoundaries.maximum)
            {
                zBoundaries.maximum = point.z;
            }
        }

        this.transform.position = new Vector3(
            (xBoundaries.minimum + xBoundaries.maximum) * 0.5f,
            0.0f,
            (zBoundaries.minimum + zBoundaries.maximum) * 0.5f
            );

        this.xBoundaries = xBoundaries;
        this.zBoundaries = zBoundaries;
    }
示例#35
0
 /// <summary>
 /// Gets the next random single value between the specified range of values.
 /// </summary>
 /// <param name="range">A range representing the inclusive minimum and maximum values.</param>
 /// <returns>A random single value between the specified minimum and maximum values.</returns>
 public static float NextSingle(RangeF range)
 {
     return NextSingle(range.Min, range.Max);
 }
 public static float NextSingle(RangeF range)
 {
     return NextSingle(range.X, range.Y);
 }