Beispiel #1
0
            public Node Intersect(Node other, Lineage lineage, ValueSelector <TKey, TValue, TValue, TValue> collision = null)
            {
                var intersection = IntersectElements(other);
                var list         = new List <StructTuple <int, Bucket> >();

#if ASSERTS
                var hsMe    = AllBuckets.Select(x => x.Key).ToHashSet(Eq);
                var hsOther = other.AllBuckets.Select(x => x.Key).ToHashSet(Eq);
                hsMe.IntersectWith(hsOther);
#endif
                foreach (var pair in intersection)
                {
                    var newBucket = pair.First.Bucket.Intersect(pair.Second.Bucket, lineage, collision);
                    if (!newBucket.IsEmpty)
                    {
                        list.Add(StructTuple.Create(pair.First.Hash, newBucket));
                    }
                }
#if ASSERTS
                var duplicates = list.Select(x => new { x, count = list.Count(y => y.First.Equals(x.First)) }).OrderByDescending(x => x.count);
                list.Count.AssertEqual(x => x <= Count && x <= other.Count);
                Debug_Intersect(list.SelectMany(x => x.Second.Buckets.Select(y => y.Key)).ToList(), other);
#endif
                return(FromSortedList(list, 0, list.Count - 1, lineage));
            }
Beispiel #2
0
        protected IDerivedState <TResult> BindToDerivedState <TInput, TResult>(IState <TInput> state, Func <TInput, TResult> derive)
        {
            var derivedState = new DerivedState <TInput, TResult>(state, derive);

            boundStates.Add(state, ValueSelector.Create(derive));
            return(derivedState);
        }
Beispiel #3
0
 public LayerBase()
 {
     Effects = new ObservableCollection<EffectBase>();
     Effects.CollectionChanged += updateEffectLayer;
     Visible = true;
     VisibleFor = new ValueSelector<BoolWithPassthrough>(BoolWithPassthrough.Yes);
 }
Beispiel #4
0
 /// <summary>Initializes a new instance of the <seealso cref="FlexibleDictionary{TKey, TValue}"/> class. Each key in the provided collection is transformed with <paramref name="valueSelector"/> and added to the dictionary.</summary>
 /// <param name="keyCollection">The collection of keys to initialize the dictionary from.</param>
 /// <param name="valueSelector">The selector that transforms a <typeparamref name="TKey"/> into a <typeparamref name="TValue"/>.</param>
 public FlexibleDictionary(IEnumerable <TKey> keyCollection, ValueSelector <TKey, TValue> valueSelector)
     : this()
 {
     foreach (var key in keyCollection)
     {
         Add(key, valueSelector(key));
     }
 }
        public void SelectElement_ShouldReturnValueDeclarations_WhenNoAttributesArePassed()
        {
            // Given
            var underTest = new ValueSelector();

            // When

            // Then
        }
Beispiel #6
0
 private Control RenderValueSelector(ValueSelector valueSelector)
 {
     return(new OptionSelector
     {
         Name = valueSelector.Name,
         Margin = ControlMargin,
         Options = valueSelector.Options,
         SelectedItem = valueSelector.SelectedOptionKey,
     });
 }
        public void SelectElement_ShouldReturnValueDeclarations_WhenNoAttributesArePassed()
        {
            // Given
            var underTest = new ValueSelector();

            // When

            // Then

        }
Beispiel #8
0
        private void MergeVisual(Label label, params VisualCollector[] styles)
        {
            label.TextColor      = ValueSelector.GetTextColor(styles);
            label.FontAttributes = ValueSelector.FontAttribute(styles);
            label.FontFamily     = ValueSelector.FontFamily(styles);
            label.FontSize       = ValueSelector.FontSize(styles);

            label.LineBreakMode           = ValueSelector.GetLineBreakMode(styles);
            label.VerticalTextAlignment   = ValueSelector.GetVerticalAlignment(styles);
            label.HorizontalTextAlignment = ValueSelector.GetHorizontalAlignment(styles);
        }
Beispiel #9
0
        public ValueSelectorValidatorTests()
        {
            _validator = new ValueSelectorValidator();
            _settings  = new Dictionary <string, string>();

            var config = Substitute.For <IStronkConfig>();

            config.ConfigSources.Returns(new[] { new DictionarySource(_settings) });
            config.Mappers.Returns(new[] { new PropertyNamePropertyMapper() });

            _selector = new ValueSelector(config);
        }
Beispiel #10
0
        /// <summary>
        ///     Subtracts the key-value pairs in the specified map from this one, applying the subtraction function on each key shared between the maps.
        /// </summary>
        /// <param name="other">A sequence of key-value pairs. This operation is much faster if it's a map compatible with this one.</param>
        /// <param name="subtraction">Optionally, a subtraction function that generates the value in the resulting key-value map. Otherwise, key-value pairs are always removed.</param>
        /// <remarks>
        ///	Subtraction over maps is anaologous to Except over sets.
        ///	If the subtraction function is not specified (or is null), the operation simply subtracts all the keys present in the other map from this one.
        /// If a subtraction function is supplied, the operation invokes the function on each key-value pair shared with the other map. If the function returns a value,
        /// that value is used in the return map. If the function returns None, the key is removed from the return map.
        /// </remarks>
        public override ImmSortedMap <TKey, TValue> Subtract <TValue2>(IEnumerable <KeyValuePair <TKey, TValue2> > other,
                                                                       ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
        {
            other.CheckNotNull("other");
            var map = other as ImmSortedMap <TKey, TValue2>;

            if (map != null && Comparer.Equals(map.Comparer))
            {
                return(Root.Except(map.Root, Lineage.Mutable(), subtraction).WrapMap(Comparer));
            }
            return(base.Subtract(other, subtraction));
        }
Beispiel #11
0
        /// <summary>
        ///     Subtracts the key-value pairs in the specified map from this one, applying the subtraction function on each key shared between the maps.
        /// </summary>
        /// <param name="other">A sequence of key-value pairs. This operation is much faster if it's a map compatible with this one.</param>
        /// <param name="subtraction">Optionally, a subtraction function that generates the value in the resulting key-value map. Otherwise, key-value pairs are always removed.</param>
        /// <remarks>
        ///	Subtraction over maps is anaologous to Except over sets.
        ///	If the subtraction function is not specified (or is null), the operation simply subtracts all the keys present in the other map from this one.
        /// If a subtraction function is supplied, the operation invokes the function on each key-value pair shared with the other map. If the function returns a value,
        /// that value is used in the return map. If the function returns None, the key is removed from the return map.
        /// </remarks>
        public override ImmMap <TKey, TValue> Subtract <TValue2>(IEnumerable <KeyValuePair <TKey, TValue2> > other,
                                                                 ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
        {
            other.CheckNotNull("other");
            var map = other as ImmMap <TKey, TValue2>;

            if (map != null && _equality.Equals(map._equality))
            {
                return(Except(map, subtraction));
            }
            return(base.Subtract(other, subtraction));
        }
Beispiel #12
0
        public ThresholdDimension(ValueSelector selector, DimensionFormatter formatter, params TDuration[] thresholds)
        {
            if (formatter == null)
            {
                throw new ArgumentNullException(nameof(formatter));
            }
            _selector   = selector ?? throw new ArgumentNullException(nameof(selector));
            _thresholds = thresholds ?? throw new ArgumentNullException(nameof(thresholds));

            Array.Sort(_thresholds);
            _thresholdStrings = _thresholds.Select(t => formatter(t)).ToArray();
        }
Beispiel #13
0
        /// <summary>
        ///     Joins this map with another map by key, returning a map consisting of the keys present in both maps, the value of each such key being determined by the specified collision resolution function.
        /// </summary>
        /// <typeparam name="TValue2">The type of value of the second map.</typeparam>
        /// <param name="other">A sequence of key-value pairs. This operation is much faster if it's a map compatible with this one.</param>
        /// <param name="selector">The function that determines the value associated with each key in the new map.</param>
        /// <remarks>
        /// A map join operation is an operation over maps of key-value pairs, which is analogous to an intersection operation over sets.
        ///	The operation returns a new key-value map consisting of only those keys present in both maps,
        /// with the value associated with each key being determined by the collision resolution function.
        ///	The collision resolution function takes as input the key, and the values associated with that key in the two maps.
        /// This method is optimized when the input collection is a map compatible with this one.
        /// </remarks>
        /// <returns></returns>
        public TMap Join <TValue2>(IEnumerable <KeyValuePair <TKey, TValue2> > other,
                                   ValueSelector <TKey, TValue, TValue2, TValue> selector)
        {
            other.CheckNotNull("other");
            selector.CheckNotNull("selector");
            //NOTE: other can be TMap when TValue = TValue2.
            var map = other as TMap;

            if (map != null && IsCompatibleWith(map))
            {
                return(Join(map, (ValueSelector <TKey, TValue, TValue, TValue>)(object) selector));
            }
            return(Join_Unchecked(other, selector));
        }
Beispiel #14
0
        /// <summary>
        ///     Merges the two maps, applying the selector function for keys appearing in both maps.
        /// </summary>
        /// <param name="other">A sequence of key-value pairs. This operation is much faster if it's a map compatible with this one.</param>
        /// <param name="collision">
        ///     The collision resolution function. If null, the values in the other map overwrite the values in this map.
        /// </param>
        /// <remarks>
        /// The merge operation is analogous to a union operation over sets.
        ///
        /// This operation returns all key-value pairs present in either map. If a key is shared between both maps, the collision resolution function is applied to determine the value in the result map.
        /// </remarks>
        public virtual TMap Merge(IEnumerable <KeyValuePair <TKey, TValue> > other, ValueSelector <TKey, TValue, TValue, TValue> collision = null)
        {
            other.CheckNotNull("other");
            if (collision == null && ReferenceEquals(this, other))
            {
                return(this);
            }
            var map = other as TMap;

            if (map != null && IsCompatibleWith(map))
            {
                return(Merge(map, collision));
            }
            return(Merge_Unchecked(other, collision));
        }
Beispiel #15
0
 private TMap Join_Unchecked <TValue2>(IEnumerable <KeyValuePair <TKey, TValue2> > other,
                                       ValueSelector <TKey, TValue, TValue2, TValue> collision)
 {
     using (var builder = EmptyBuilder) {
         other.ForEach(pair => {
             var myKvp = builder.TryGetKvp(pair.Key).Or(TryGetKvp(pair.Key));
             if (myKvp.IsSome)
             {
                 var kvp      = myKvp.Value;
                 var newValue = collision(kvp.Key, kvp.Value, pair.Value);
                 builder.Set(kvp.Key, newValue);
             }
         });
         return(builder.Produce());
     }
 }
Beispiel #16
0
            public Bucket Intersect(Bucket other, Lineage lineage, ValueSelector <TKey, TValue, TValue, TValue> collision = null)
            {
                var newBucket = Empty;

                foreach (var item in Items)
                {
                    var otherItem = other.Find(item.Key);
                    if (otherItem.IsNone)
                    {
                        continue;
                    }
                    var valueToAdd = collision == null ? item.Value : collision(item.Key, item.Value, otherItem.Value);
                    newBucket = NewBucket(item.Key, valueToAdd, newBucket, lineage);
                }
                return(newBucket);
            }
Beispiel #17
0
            public Node Union(Node b, Lineage lin, ValueSelector <TKey, TValue, TValue, TValue> collision = null)
            {
                if (IsEmpty)
                {
                    return(b);
                }
                if (b.IsEmpty)
                {
                    return(this);
                }
                if (ReferenceEquals(this, b) && collision == null)
                {
                    return(this);
                }
                var myCount = Count;
                var bCount  = b.Count;

#if ASSERTS
                var expected    = Pairs.Select(x => x.Key).ToHashSet(Eq);
                var oldContents = b.Pairs.Select(x => x.Key).ToArray();
                expected.UnionWith(oldContents);
#endif
                Node aLesser, aGreater;
                Node centerNode;
                Split(b.Hash, out aLesser, out centerNode, out aGreater, lin);
                var unitedLeft = aLesser.Union(b.Left, lin, collision);
                if (centerNode == null)
                {
                    centerNode = b;
                }
                else
                {
                    var newBucket = centerNode.Bucket.Union(b.Bucket, collision, lin);
                    centerNode = centerNode.WithBucket(newBucket, lin);
                }
                var unitedRight = aGreater.Union(b.Right, lin, collision);
                var concated    = Concat(unitedLeft, centerNode, unitedRight, lin);
#if ASSERTS
                AssertEx.AssertTrue(concated.Count <= myCount + bCount);
                AssertEx.AssertTrue(concated.Count >= myCount);
                AssertEx.AssertTrue(concated.Count >= bCount);
                AssertEx.AssertTrue(concated.IsBalanced);
                var hs = concated.Pairs.Select(x => x.Key).ToHashSet(Eq);
                hs.SetEquals(expected).AssertTrue();
#endif
                return(concated);
            }
Beispiel #18
0
            /// <summary>
            ///     Returns the set-thereotic intersection between the two trees, and applies the collision resolution function on each
            ///     shared key-value pair. O(min(m+n,nlogm)) where n ≤ m. <br />
            ///     If the collision resolution function is null, it is ignored and the value is kept is arbitrary.
            /// </summary>
            /// <param name="other"></param>
            /// <param name="lineage"></param>
            /// <param name="collision"></param>
            /// <returns></returns>
            public Node Intersect(Node other, Lineage lineage, ValueSelector <TKey, TValue, TValue, TValue> collision = null)
            {
                var intersection = IntersectElements(other);
                var list         = new List <KeyValuePair <TKey, TValue> >();

                foreach (var pair in intersection)
                {
                    var newValue = collision == null
                                                ? pair.First.Value : collision(pair.First.Key, pair.First.Value, pair.Second.Value);
                    list.Add(Kvp.Of(pair.First.Key, newValue));
                }
#if ASSERTS
                list.Count.AssertEqual(x => x <= Count && x <= other.Count);
                Debug_Intersect(list.Select(x => x.Key).ToList(), other);
#endif
                return(FromSortedList(list, 0, list.Count - 1, Comparer, lineage));
            }
Beispiel #19
0
 public void RenderPreset(IRenderPanel target, Preset preset)
 {
     target.ClearItems();
     foreach (var controller in preset.Controllers)
     {
         FrameworkElement?rendered = null;
         rendered = controller switch
         {
             Presets.Controls.Slider bitrateSlider => RenderBitrateSlider(bitrateSlider),
             VideoScale videoScale => RenderVideoScale(videoScale),
             VideoTime videoTime => RenderVideoTime(videoTime),
             ValueSelector valueSelector => RenderValueSelector(valueSelector),
             _ => throw new InvalidOperationException(),
         };
         target.Render(RenderLabel(controller.Label));
         target.Render(rendered);
     }
 }
Beispiel #20
0
        public CustomTextLayer()
        {
            Text = new ValueSelector <string>();

            Text.Single = "Example";

            Text.CountryNone    = "";
            Text.CountryUSSR    = "СССР";
            Text.CountryGermany = "Deutschland";
            Text.CountryUSA     = "USA";
            Text.CountryFrance  = "France";
            Text.CountryChina   = "中国";
            Text.CountryUK      = "UK";
            Text.CountryJapan   = "日本";
            Text.CountryCzech   = "Česko";
            Text.CountrySweden  = "Sverige";
            Text.CountryPoland  = "Polska";
            Text.CountryItaly   = "Italia";

            Text.ClassNone      = "";
            Text.ClassLight     = "LT";
            Text.ClassMedium    = "MT";
            Text.ClassHeavy     = "HT";
            Text.ClassDestroyer = "D";
            Text.ClassArtillery = "A";

            Text.CategNormal    = "•";
            Text.CategPremium   = "♦";
            Text.CategSpecial   = "∞";
            Text.CategCollector = "❖";

            Text.TierNone = "";
            Text.Tier1    = "I";
            Text.Tier2    = "II";
            Text.Tier3    = "III";
            Text.Tier4    = "IV";
            Text.Tier5    = "V";
            Text.Tier6    = "VI";
            Text.Tier7    = "VII";
            Text.Tier8    = "VIII";
            Text.Tier9    = "IX";
            Text.Tier10   = "X";
        }
Beispiel #21
0
            /// <summary>
            ///     Returns the set-theoretic union, and applies a function on the values in case of a collision.  <br />
            ///     If the collision resolution function is null, the value of 'b' is used.
            /// </summary>
            /// <param name="b"></param>
            /// <param name="collision"></param>
            /// <param name="lin"></param>
            /// <returns></returns>
            public Node Union(Node b, ValueSelector <TKey, TValue, TValue, TValue> collision, Lineage lin)
            {
                if (IsEmpty)
                {
                    return(b);
                }
                if (b.IsEmpty)
                {
                    return(this);
                }
#if ASSERTS
                var expected = Pairs.Select(x => x.Key).Union(b.Pairs.Select(x => x.Key)).ToSortedSet(Comparer);
#endif
                Node aLesser, aGreater;
                Node centerNode;
                var  oldThisCount = Count;
                var  oldBCount    = b.Count;
                Split(b.Key, out aLesser, out centerNode, out aGreater, lin);
                var bLeft       = b.Left;
                var bRight      = b.Right;
                var unitedLeft  = aLesser.Union(bLeft, collision, lin);
                var newValue    = collision == null || centerNode == null ? b.Value : collision(b.Key, centerNode.Value, b.Value);
                var unitedRight = aGreater.Union(bRight, collision, lin);
                if (centerNode == null)
                {
                    centerNode = b.WithChildren(unitedLeft, unitedRight, lin);
                }
                else
                {
                    var chosenNode = b.CanMutateBy(lin) ? b : centerNode;
                    centerNode = chosenNode.MutateOrCreate(newValue, unitedLeft, unitedRight, lin);
                }
                var concated = Concat(unitedLeft, centerNode, unitedRight, lin);
#if ASSERTS
                AssertEx.AssertTrue(concated.Count <= oldThisCount + oldBCount);
                AssertEx.AssertTrue(concated.Count >= oldThisCount);
                AssertEx.AssertTrue(concated.Count >= oldBCount);
                AssertEx.AssertTrue(concated.IsBalanced);
                var result = concated.Pairs.Select(x => x.Key).ToSortedSet(Comparer);
                result.SetEquals(expected).AssertTrue();
#endif
                return(concated);
            }
Beispiel #22
0
        /// <summary>
        ///     Subtracts the key-value pairs in the specified map from this one, applying the subtraction function on each key shared between the maps.
        /// </summary>
        /// <param name="other">A sequence of key-value pairs. This operation is much faster if it's a map compatible with this one.</param>
        /// <param name="subtraction">Optionally, a subtraction function that generates the value in the resulting key-value map. Otherwise, key-value pairs are always removed.</param>
        /// <remarks>
        ///	Subtraction over maps is anaologous to Except over sets.
        ///	If the subtraction function is not specified (or is null), the operation simply subtracts all the keys present in the other map from this one.
        /// If a subtraction function is supplied, the operation invokes the function on each key-value pair shared with the other map. If the function returns a value,
        /// that value is used in the return map. If the function returns None, the key is removed from the return map.
        /// </remarks>
        public virtual TMap Subtract <TValue2>(IEnumerable <KeyValuePair <TKey, TValue2> > other,
                                               ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
        {
            if (subtraction == null && ReferenceEquals(other, this))
            {
                return(Empty);
            }
            other.CheckNotNull("other");

            //NOTE: other can be a TMap when TValue2 = TValue! ReSharper can't seem to understand this...
            var map = other as TMap;

            if (map != null && IsCompatibleWith(map))
            {
                return(Subtract(map, (ValueSelector <TKey, TValue, TValue, Optional <TValue> >)(object) subtraction));
            }

            return(Subtract_Unchecked(other, subtraction));
        }
Beispiel #23
0
 TMap Merge_Unchecked(IEnumerable <KeyValuePair <TKey, TValue> > other,
                      ValueSelector <TKey, TValue, TValue, TValue> collision = null)
 {
     other.CheckNotNull("other");
     using (var builder = BuilderFrom(this)) {
         other.ForEach(item => {
             if (collision == null)
             {
                 builder.Set(item.Key, item.Value);
             }
             else
             {
                 var myElement = builder.TryGetKvp(item.Key);
                 var value     = myElement.IsSome ? collision(myElement.Value.Key, myElement.Value.Value, item.Value) : item.Value;
                 builder.Set(item.Key, value);
             }
         });
         return(builder.Produce());
     }
 }
Beispiel #24
0
            /// <summary>
            ///     Removes the keys of the other tree from this tree. Keys are ignored. <br />
            ///     Corresponds to a set theoretic relative complement: this ∖ other.
            /// </summary>
            /// <param name="other"></param>
            /// <param name="lin"></param>
            /// <param name="subtraction"></param>
            /// <returns></returns>
            public Node Except <TValue2>(OrderedAvlTree <TKey, TValue2> .Node other, Lineage lin,
                                         ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
            {
                if (IsEmpty || other.IsEmpty)
                {
                    return(this);
                }
                Node thisLesser, thisGreater;
                Node centralNode;

                Split(other.Key, out thisLesser, out centralNode, out thisGreater, lin);
                var thisLesserCount  = thisLesser.Count;
                var thisGreaterCount = thisGreater.Count;
                var exceptLesser     = thisLesser.Except(other.Left, lin, subtraction);
                var subtracted       = centralNode != null && subtraction != null
                                        ? subtraction(other.Key, centralNode.Value, other.Value) : Optional.None;

                var exceptGreater = thisGreater.Except(other.Right, lin, subtraction);

                var  exceptLesserCount  = exceptLesser.Count;
                var  exceptGreaterCount = exceptGreater.Count;
                Node ret;

                if (subtracted.IsNone)
                {
                    ret = Concat(exceptLesser, exceptGreater, lin);
                }
                else
                {
                    centralNode = centralNode.WithValue(subtracted.Value, lin);
                    ret         = Concat(exceptLesser, centralNode, exceptGreater, lin);
                }
#if ASSERTS
                AssertEx.AssertTrue(exceptLesserCount <= thisLesserCount);
                AssertEx.AssertTrue(exceptGreaterCount <= thisGreaterCount);
                AssertEx.AssertTrue(exceptGreaterCount + exceptLesserCount <= thisLesserCount + thisGreaterCount);
                AssertEx.AssertTrue(exceptGreater.IsBalanced);
#endif
                return(ret);
            }
Beispiel #25
0
            public Node Except <TValue2>(HashedAvlTree <TKey, TValue2> .Node other, Lineage lin,
                                         ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
            {
                if (IsEmpty || other.IsEmpty)
                {
                    return(this);
                }
                if (ReferenceEquals(this, other) && subtraction == null)
                {
                    return(Empty);
                }
                Node thisLesser, thisGreater;
                Node central;

                Split(other.Hash, out thisLesser, out central, out thisGreater, lin);
                var  thisLesserCount    = thisLesser.Count;
                var  thisGreaterCount   = thisGreater.Count;
                var  exceptLesser       = thisLesser.Except(other.Left, lin, subtraction);
                var  exceptBucket       = central == null ? null : central.Bucket.Except(other.Bucket, lin, subtraction);
                var  exceptGreater      = thisGreater.Except(other.Right, lin, subtraction);
                var  exceptLesserCount  = exceptLesser.Count;
                var  exceptGreaterCount = exceptGreater.Count;
                Node ret;

                if (exceptBucket == null || exceptBucket.IsEmpty)
                {
                    ret = Concat(exceptLesser, exceptGreater, lin);
                }
                else
                {
                    ret = Concat(exceptLesser, central.WithBucket(exceptBucket, lin), exceptGreater, lin);
                }
#if ASSERTS
                AssertEx.AssertTrue(exceptLesserCount <= thisLesserCount);
                AssertEx.AssertTrue(exceptGreaterCount <= thisGreaterCount);
                AssertEx.AssertTrue(exceptGreaterCount + exceptLesserCount <= thisLesserCount + thisGreaterCount);
                AssertEx.AssertTrue(ret.IsBalanced);
#endif
                return(ret);
            }
Beispiel #26
0
 TMap Subtract_Unchecked <TValue2>(IEnumerable <KeyValuePair <TKey, TValue2> > other,
                                   ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
 {
     other.CheckNotNull("other");
     using (var builder = BuilderFrom(this)) {
         var len = Length;
         other.ForEachWhile(item => {
             if (subtraction == null)
             {
                 if (builder.Remove(item.Key))
                 {
                     len--;
                 }
             }
             else
             {
                 var tryGet = builder.TryGetKvp(item.Key).Map(x => x.Value);
                 if (tryGet.IsNone)
                 {
                     return(len > 0);
                 }
                 var newValue = subtraction(item.Key, tryGet.Value, item.Value);
                 if (newValue.IsSome)
                 {
                     builder.Set(item.Key, newValue.Value);
                 }
                 else
                 {
                     if (builder.Remove(item.Key))
                     {
                         len--;
                     }
                 }
             }
             return(len > 0);
         });
         return(builder.Produce());
     }
 }
Beispiel #27
0
        public CustomTextLayer()
        {
            Text = new ValueSelector<string>();

            Text.Single = "Example";

            Text.CountryNone = "";
            Text.CountryUSSR = "СССР";
            Text.CountryGermany = "Deutschland";
            Text.CountryUSA = "USA";
            Text.CountryFrance = "France";
            Text.CountryChina = "中国";
            Text.CountryUK = "UK";
            Text.CountryJapan = "日本";

            Text.ClassNone = "";
            Text.ClassLight = "LT";
            Text.ClassMedium = "MT";
            Text.ClassHeavy = "HT";
            Text.ClassDestroyer = "D";
            Text.ClassArtillery = "A";

            Text.CategNormal = "•";
            Text.CategPremium = "♦";
            Text.CategSpecial = "∞";

            Text.TierNone = "";
            Text.Tier1 = "I";
            Text.Tier2 = "II";
            Text.Tier3 = "III";
            Text.Tier4 = "IV";
            Text.Tier5 = "V";
            Text.Tier6 = "VI";
            Text.Tier7 = "VII";
            Text.Tier8 = "VIII";
            Text.Tier9 = "IX";
            Text.Tier10 = "X";
        }
Beispiel #28
0
            public Bucket Except <TValue2>(HashedAvlTree <TKey, TValue2> .Bucket other, Lineage lineage,
                                           ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
            {
                var newBucket = Empty;

                foreach (var item in Items)
                {
                    var findOther = other.Find(item.Key);
                    if (findOther.IsNone)
                    {
                        newBucket = NewBucket(item.Key, item.Value, newBucket, lineage);
                    }
                    else if (subtraction != null)
                    {
                        var newValue = subtraction(item.Key, item.Value, findOther.Value);
                        if (newValue.IsSome)
                        {
                            newBucket = NewBucket(item.Key, newValue.Value, newBucket, lineage);
                        }
                    }
                }
                return(newBucket);
            }
Beispiel #29
0
            public Bucket Union(Bucket other, ValueSelector <TKey, TValue, TValue, TValue> collision, Lineage lineage)
            {
                var newBucket = Empty;

                foreach (var item in Items)
                {
                    var findOther  = other.Find(item.Key);
                    var valueToAdd = item.Value;
                    if (findOther.IsSome)
                    {
                        other      = other.Remove(item.Key, lineage);
                        valueToAdd = collision == null ? findOther.Value : collision(item.Key, item.Value, findOther.Value);
                    }
                    newBucket = NewBucket(item.Key, valueToAdd, newBucket, lineage);
                }

                foreach (var item in other.Items)
                {
                    newBucket = NewBucket(item.Key, item.Value, newBucket, lineage);
                }

                return(newBucket);
            }
                protected void initialiseOverlay(TextureEditGUI gui)
                {
                    _alphaSelector = new ValueSelector<byte, ByteField>(_overlay._alpha, 0, 255, 1, "Alpha", Color.white);

                    _textureAlphaSelector = new ValueSelector<byte, ByteField>(_overlay._textureAlpha, 0, 255, 1, "Texture Alpha", Color.white);
                    _normalScaleSelector = new ValueSelector<float, FloatField>(_overlay._normalScale, 0, 5.0f, 0.1f, "Normal Scale", Color.white);

                    if (gui.kspTextureInfo().isSpecular) _textureAlphaSelector.setLabel("Specularity");
                    else if (gui.kspTextureInfo().isTransparent) _textureAlphaSelector.setLabel("Transparency");
                }
        public void initialise(ASPTextureEdit textureEdit, int count)
        {
            _windowID = _nextID;
            ++_nextID;

            _textureEdit = textureEdit;
            _windowPosition = new Rect(700, 200 -((count) * 100), 400, 400);
            _locked = false;
            _remakePreview = true;

            _imageModifiers = _textureEdit.cloneImageModifiers();
            _baseTexture = _textureEdit.cloneBaseTexture();
            _baseTexture.gui().initialise(this);
            _imageModifiers.guiInit(this);

            _boundingBox = _textureEdit.cloneBoundingBox();
            _bbXselector = new ValueSelector<int, IntField>(_boundingBox.x, 0, 999999, 1, "Bottom Left X", Color.white);
            _bbYselector = new ValueSelector<int, IntField>(_boundingBox.y, 0, 999999, 1, "Bottom Left Y", Color.white);
            _bbWselector = new ValueSelector<int, IntField>(_boundingBox.w, 0, 999999, 1, "Width", Color.white);
            _bbHselector = new ValueSelector<int, IntField>(_boundingBox.h, 0, 999999, 1, "Height", Color.white);

            _selectedModifier = -2;

            Global.LastButtonPress = 0f;
            Global.AutoRepeatGap = 0.4f;
        }
Beispiel #32
0
 protected override ImmMap <TKey, TValue> Subtract(ImmMap <TKey, TValue> other, ValueSelector <TKey, TValue, TValue, Optional <TValue> > subtraction = null)
 {
     return(Except(other, subtraction));
 }
Beispiel #33
0
 ImmMap <TKey, TValue> Except <TValue2>(ImmMap <TKey, TValue2> other,
                                        ValueSelector <TKey, TValue, TValue2, Optional <TValue> > subtraction = null)
 {
     other.CheckNotNull("other");
     return(_root.Except(other._root, Lineage.Mutable(), subtraction).WrapMap(_equality));
 }
 public void colorSelector(TextureEditGUI gui, ref ValueSelector<byte, ByteField> redSelector, ref ValueSelector<byte, ByteField> greenSelector,
                           ref ValueSelector<byte, ByteField> blueSelector, ref ValueSelector<byte, ByteField> alphaSelector)
 {
     if (redSelector.draw()) gui.setRemakePreview();
     GUILayout.Space(10f);
     if (greenSelector.draw()) gui.setRemakePreview();
     GUILayout.Space(10f);
     if (blueSelector.draw()) gui.setRemakePreview();
     GUILayout.Space(10f);
     if (alphaSelector.draw()) gui.setRemakePreview();
 }
Beispiel #35
0
 protected override ImmMap <TKey, TValue> Join(ImmMap <TKey, TValue> other,
                                               ValueSelector <TKey, TValue, TValue, TValue> collision = null)
 {
     return(_root.Intersect(other._root, Lineage.Mutable(), collision).WrapMap(_equality));
 }
Beispiel #36
0
 public EffectBase()
 {
     Visible = true;
     VisibleFor = new ValueSelector<BoolWithPassthrough>(BoolWithPassthrough.Yes);
 }
 protected void initialiseMonoOverlay(TextureEditGUI gui)
 {
     initialiseOverlay(gui);
     _redSelector = new ValueSelector<byte, ByteField>(_overlay._red, 0, 255, 1, "Red", Color.red);
     _greenSelector = new ValueSelector<byte, ByteField>(_overlay._green, 0, 255, 1, "Green", Color.green);
     _blueSelector = new ValueSelector<byte, ByteField>(_overlay._blue, 0, 255, 1, "Blue", Color.blue);
 }
Beispiel #38
0
 protected override ImmSortedMap <TKey, TValue> Subtract(ImmSortedMap <TKey, TValue> other, ValueSelector <TKey, TValue, TValue, Optional <TValue> > subtraction = null)
 {
     return(Root.Except(other.Root, Lineage.Mutable(), subtraction).WrapMap(Comparer));
 }
Beispiel #39
0
 public CustomImageLayer()
 {
     ImageFile = new ValueSelector<Filename>("");
 }