Esempio n. 1
0
        public void Range_Default()
        {
            var range = new Range2 <char>('0', '9');

            Assert.AreEqual('0', range.MinValue);
            Assert.AreEqual('9', range.MaxValue);
        }
Esempio n. 2
0
        public static void UpdateBounds(this Mesh mesh, Rect xyBounds, Range2 rangeZ)
        {
            Vector2 center = xyBounds.center;
            Vector2 size   = xyBounds.size;

            mesh.bounds = new Bounds(new Vector3(center.x, center.y, rangeZ.Center), new Vector3(size.x, size.y, rangeZ.Size));
        }
Esempio n. 3
0
        public void Range2_With_Integers()
        {
            var range = new Range2 <int>(1, 3);

            Assert.AreEqual(1, range.MinValue);
            Assert.AreEqual(3, range.MaxValue);
        }
Esempio n. 4
0
 public void Contains(
     Range2 <int> range,
     int i,
     bool contains
     )
 {
     Assert.That(range.Contains(i), Is.EqualTo(contains));
 }
Esempio n. 5
0
 public void Overlaps(
     Range2 <int> range0,
     Range2 <int> range1,
     bool overlaps
     )
 {
     Assert.That(range0.Overlaps(range1), Is.EqualTo(overlaps));
 }
Esempio n. 6
0
 public void Contains(
     Range2 <int> range0,
     Range2 <int> range1,
     bool contains
     )
 {
     Assert.That(range0.Contains(range1), Is.EqualTo(contains));
 }
Esempio n. 7
0
        public void Array_From_Range()
        {
            var range = new Range2 <char>("A-B".Split('-').Select(x => x[0]).ToArray());
            var array = range.AsArray();

            Assert.AreEqual(2, array.Length);
            Assert.AreEqual('A', array[0]);
            Assert.AreEqual('B', array[1]);
        }
Esempio n. 8
0
        public void Construct(
            int?start,
            int?end
            )
        {
            var range = new Range2 <int>(
                start,
                end);

            Assert.That(range.Start, Is.EqualTo(start));
            Assert.That(range.End, Is.EqualTo(end));
        }
Esempio n. 9
0
 internal static string ExpandRanges(this string reg)
 {
     // [12]{1,2} becomes [12] or [12][12]
     return(Regex.Replace(reg, @"(\[[^\]]+\])\{(\d+),(\d+)\}", match =>
     {
         var toRepeat = match.Groups[1].Value;
         var lowerBoundary = int.Parse(match.Groups[2].Value);
         var upperBoundary = int.Parse(match.Groups[3].Value);
         int[] intRange = new Range2 <int>(lowerBoundary, upperBoundary).AsArray();
         return string.Concat(intRange.Sample().Times(_ => toRepeat));
     }, RegexOptions.Compiled));
 }
Esempio n. 10
0
 public AgreementParty(
     Agreement agreement,
     Organisation organisation,
     Role role,
     Range2 <DateTime> period
     ) : this(
         Guid.NewGuid(),
         agreement,
         organisation,
         role,
         period)
 {
 }
Esempio n. 11
0
 public AgreementParty(
     Agreement agreement,
     Person person,
     Role role,
     Range2 <DateTime> period
     ) : this(
         Guid.NewGuid(),
         agreement,
         person,
         role,
         period)
 {
 }
Esempio n. 12
0
 public OrganisationMember(
     Organisation organisation,
     Organisation member,
     Role role,
     Range2 <DateTime> period
     ) : this(
         Guid.NewGuid(),
         organisation,
         member,
         role,
         period)
 {
 }
Esempio n. 13
0
 public PartyInRole(
     Guid id,
     Organisation party,
     Role role,
     Range2 <DateTime> period
     ) : base(
         id,
         party,
         role)
 {
     Organisation = party;
     Period       = period;
 }
Esempio n. 14
0
 public PartyInRole(
     Guid id,
     Person party,
     Role role,
     Range2 <DateTime> period
     ) : base(
         id,
         party,
         role)
 {
     Person = party;
     Period = period;
 }
Esempio n. 15
0
 public Sponsor(
     Organisation organisation,
     Role role,
     Range2 <DateTime> period,
     decimal?equity
     ) : this(
         Guid.NewGuid(),
         organisation,
         role,
         period,
         equity)
 {
 }
Esempio n. 16
0
        public double MapToValue1(double value2)
        {
            var value2Dis = Range2.NumericDistanceToMin(value2);
            var value1Dis = value2Dis * Value1ToValue2Rato;

            if (reverseMap)
            {
                return(Range1.Max - value1Dis);
            }
            else
            {
                return(value1Dis + Range1.Min);
            }
        }
Esempio n. 17
0
        public void Range2_With_Chars()
        {
            var range = new Range2 <char>('a', 'b');

            Assert.AreEqual('a', range.MinValue);
            Assert.AreEqual('b', range.MaxValue);
            var expected = new char[] { 'a', 'b' };
            var actuals  = range.AsArray();

            for (var i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actuals[i]);
            }
        }
Esempio n. 18
0
 public Sponsor(
     Guid id,
     Organisation organisation,
     Role role,
     Range2 <DateTime> period,
     decimal?equity
     ) : base(
         id,
         organisation,
         role,
         period)
 {
     Equity = equity;
 }
Esempio n. 19
0
 public OrganisationMember(
     Guid id,
     Organisation organisation,
     Organisation member,
     Role role,
     Range2 <DateTime> period
     ) : base(
         id,
         member,
         role,
         period)
 {
     MemberOf = organisation;
 }
Esempio n. 20
0
        private static void BardQ(AIHeroClient Target, bool Type, bool Draw = false)
        {
            // Type 0: no sturn / 1: only sturn
            // If Draw is true, return draw

            /* return
             * target1, target2, type
             */
            Range1 = new LeagueSharp.Common.Geometry.Polygon.Rectangle(Player.Position, Player.Position.LSExtend(Target.Position, _Q.Range), _Q.Width);
            Range2 = null;
            if (Draw)
            {
                Range1.Draw(Color.Red);
            }
            cnt          = 0;
            BardQTarget1 = Player;
            BardQTarget2 = Player;
            foreach (var item in ObjectManager.Get <Obj_AI_Base>().OrderBy(f => f.Distance(f.Position)))
            {
                if (item.Distance(Player.Position) < _Q.Range)
                {
                    if (item is AIHeroClient || item is Obj_AI_Minion)
                    {
                        if (item.IsEnemy && !item.IsDead)
                        {
                            if (cnt == 2)
                            {
                                break;
                            }
                            if (cnt == 0 && Range1.IsInside(item.Position))
                            {
                                BardQTarget1 = item;
                                Range2       = new LeagueSharp.Common.Geometry.Polygon.Rectangle(Player.Position.Extend(BardQTarget1.Position, Player.Distance(BardQTarget1.Position)),
                                                                                                 Player.Position.Extend(BardQTarget1.Position, Player.Distance(BardQTarget1.Position) + 450), _Q.Width);
                                if (Draw)
                                {
                                    Range2.Draw(Color.Yellow);
                                }
                                cnt++;
                            }
                            if (cnt == 1 && Range2.IsInside(item.Position))
                            {
                                BardQTarget2 = item;
                                cnt++;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 21
0
 public AgreementParty(
     Guid id,
     Agreement agreement,
     Person person,
     Role role,
     Range2 <DateTime> period
     ) : base(
         id,
         person,
         role,
         period)
 {
     Agreement = agreement;
     Agreement.Parties.Add(this);
 }
Esempio n. 22
0
 public AgreementParty(
     Guid id,
     Agreement agreement,
     Organisation organisation,
     Role role,
     Range2 <DateTime> period
     ) : base(
         id,
         organisation,
         role,
         period)
 {
     Agreement = agreement;
     Agreement.Parties.Add(this);
 }
Esempio n. 23
0
 private void NoFilter_Click(object sender, EventArgs e)
 {
     dt.DefaultView.RowFilter = string.Empty;
     dt = cp.GetDataTable();
     data.DataSource     = dt;
     cbFilter.Visible    = false;
     labelFilter.Visible = false;
     labelRange.Visible  = false;
     labelTo.Visible     = false;
     Range1.Visible      = false;
     Range2.Visible      = false;
     FilterRange.Visible = false;
     cbCategory.ResetText();
     Range1.Clear();
     Range2.Clear();
 }
Esempio n. 24
0
        /// <summary>
        /// Generates a random weather forecast for 5 days.
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <WeatherForecast> Forecast(int numberOfDays = 5)
        {
            if (numberOfDays < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numberOfDays), "Must not be negative.");
            }
            var temperatureRangeC = new Range2 <int>(-20, 50);
            var result            = new List <WeatherForecast>();

            result.AddRange(numberOfDays.Times(x => new WeatherForecast
            {
                Date         = DateTime.UtcNow.AddDays(x),
                TemperatureC = temperatureRangeC.Sample(),
                Summary      = Summary()
            }));;
            return(result);
        }
Esempio n. 25
0
        /// <summary>
        /// Given a regular expression, attempt to generate a string that would match it. This is a rather
        /// simple implementation, so don't be shocked if it blows up on you in a spectacular fashion. It does
        /// not handle ., *, unbound ranges such as {1,}, extensions such as (?=), character classes, some
        /// abbreviations for characters classes, and nested parantheses. I told you it was simple. :) It's
        /// also probably dog-slow, so you shouldn't use it. It will take a reg ex like this:
        /// "^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}$"
        /// and generate a string like this: "U3V  3TP"
        /// </summary>
        /// <param name="reg"></param>
        /// <returns></returns>
        public static string Regexify(this string reg)
        {
            // Trim slashes:
            reg = reg.Trim('/');

            // Ditch the anchors
            reg = Regex.Replace(reg, @"{^\/?\^?}", string.Empty, RegexOptions.Compiled);
            reg = Regex.Replace(reg, @"{\$?\/?$}", string.Empty, RegexOptions.Compiled);

            // All {2} become {2,2}
            reg = Regex.Replace(reg, @"\{(\d+)\}", "{$1,$1}", RegexOptions.Compiled);

            // All ? become {0,1}
            reg = Regex.Replace(reg, @"\?", "{0,1}", RegexOptions.Compiled);

            // [12]{1,2} becomes [12] or [12][12]
            reg = reg.ExpandRanges();

            // (12|34){1,2} becomes (12|34) or (12|34)(12|34)
            reg = Regex.Replace(reg, @"(\([^\)]+\))\{(\d+),(\d+)\}", match =>
            {
                throw new NotImplementedException();
            }, RegexOptions.Compiled);

            // A{1,2} becomes A or AA or \d{3} becomes \d\d\d
            reg = Regex.Replace(reg,
                                @"(\\?.)\{(\d+),(\d+)\}",
                                match =>
            {
                var toRepeat      = match.Groups[1].Value;
                var lowerBoundary = int.Parse(match.Groups[2].Value);
                var upperBoundary = int.Parse(match.Groups[3].Value);
                int[] intRange    = new Range2 <int>(lowerBoundary, upperBoundary).AsArray();
                var result        = string.Concat(intRange.Sample().Times(_ => toRepeat));
                return(result);
            }, RegexOptions.Compiled);

            // (this|that) becomes 'this' or 'that'
            reg = ExpandOr(reg);

            // All A-Z inside of [] become C (or X, or whatever)
            reg = Regex.Replace(reg, @"\[([^\]]+)\]", match =>
            {
                var result = Regex.Replace(match.Value, @"(\w\-\w)", range =>
                {
                    var parts     = Regex.Split(range.Value, "-");
                    var charRange = new Range2 <char>(parts[0][0], parts[1][0]);
                    return($"{charRange.Sample()}");
                });
                return(result);
            }, RegexOptions.Compiled);

            // All [ABC] become B (or A or C)
            reg = Regex.Replace(reg, @"\[([^\]]+)\]", match =>
            {
                var charRange = match.Groups[1].Value.ToCharArray();
                return($"{charRange.Sample()}");
            }, RegexOptions.Compiled);

            reg = Regex.Replace(reg, Regex.Escape(@"\d"), _ => $"{Numbers.Sample()}", RegexOptions.Compiled);
            reg = Regex.Replace(reg, Regex.Escape(@"\w"), _ => $"{Letters.Sample()}", RegexOptions.Compiled);
            return(reg);
        }
Esempio n. 26
0
        private static IEnumerable <object> ConstructNode(Range <Type> types, Range2 <object> rows)
        {
            var table = Table.Get(types[0]);

            var relations = new List <(int index, Relation relation)>();

            for (int i = 1; i < types.Length; ++i)
            {
                if (table.Relations.TryGetValue(types[i], out Relation r))
                {
                    relations.Add((i, r));
                }
            }
            relations.Add((types.Length, null));

            var    roots = new List <(int index, object pk)>();
            object pk    = null;

            for (int i = 0; i < rows.Length1; ++i)
            {
                var row = rows[i, 0];
                if (row != null)
                {
                    var newpk = table[row, table.PrimaryKey];
                    if (pk?.Equals(newpk) != true)
                    {
                        pk = newpk;
                        roots.Add((i, pk));
                    }
                }
            }
            roots.Add((rows.Length1, null));

            var done = new HashSet <object>();

            for (int roi = 0; roi < roots.Count - 1; ++roi)
            {
                var root = rows[roots[roi].index, 0];
                if (done.Contains(table[root, table.PrimaryKey]))
                {
                    continue;
                }

                for (var rei = 0; rei < relations.Count - 1; ++rei)
                {
                    var subts   = types.GetRange(relations[rei].index, relations[rei + 1].index - relations[rei].index);
                    var subrows = rows.GetRange(
                        roots[roi].index,
                        roots[roi + 1].index - roots[roi].index,
                        relations[rei].index,
                        relations[rei + 1].index - relations[rei].index);

                    var nodes = ConstructNode(subts, subrows).ToList();
                    relations[rei].relation.SetValue(root, nodes);

                    if (Table.Get(subts[0]).Relations.TryGetValue(types[0], out Relation reverse))
                    {
                        foreach (var node in nodes)
                        {
                            reverse.SetValue(node, new List <object> {
                                root
                            });
                        }
                    }
                }

                yield return(root);

                done.Add(table[root, table.PrimaryKey]);
            }
        }
Esempio n. 27
0
        public void Range_With_Integers()
        {
            var range = new Range2 <int>(4, 7);

            Assert.AreEqual(4, range.Length());
        }