/// <summary> /// Initializes a new instance of the <see cref="AbstractAreaOfInterest{TKey, TInterest}" /> class. /// </summary> /// <param name="map">The interest map to add and remove interests from.</param> /// <param name="interest">The interest to add and remove.</param> /// <param name="observableOrigin">The origin of the area of interest to follow.</param> /// <param name="keys">The keys of the cells to apply interests to.</param> public AbstractAreaOfInterest( IInterestMap <TKey, TInterest> map, TInterest interest, IObservable <TKey> observableOrigin, IReadOnlySet <TKey> keys) { Contracts.Requires.That(map != null); Contracts.Requires.That(observableOrigin != null); Contracts.Requires.That(keys != null); this.map = map; this.interest = interest; this.keys = keys; IObservable <TKey> firstKey, lastKey; var pairKeys = observableOrigin.TakeUntil(this.disposed).PairWithPrevious(out firstKey, out lastKey); this.subscriptions = new AggregateDisposable( pairKeys.Subscribe( origin => this.map.UpdateInterests( this.interest, addTo: this.GetKeys(origin.Next), removeFrom: this.GetKeys(origin.Previous))), firstKey.Subscribe( origin => this.map.AddInterests(this.interest, this.GetKeys(origin))), lastKey.Subscribe( origin => this.map.RemoveInterests(this.interest, this.GetKeys(origin)), () => this.Dispose())); }
public static bool HasAnyInterests <TKey, TInterest>( this IInterestMap <TKey, TInterest> map, TKey index) { Contracts.Requires.That(map != null); return(!map.Comparer.Equals(map[index], map.None)); }
/// <summary> /// Initializes a new instance of the <see cref="AreaOfInterest1D{TInterest}" /> class. /// </summary> /// <param name="map">The interest map to add and remove interests from.</param> /// <param name="interest">The interest to add and remove.</param> /// <param name="origin">The origin of the area of interest to follow.</param> /// <param name="indices">The indices of the cells to apply interests to.</param> public AreaOfInterest1D( IInterestMap <Index1D, TInterest> map, TInterest interest, IObservable <Index1D> origin, IReadOnlySet <Index1D> indices) : base(map, interest, origin, indices) { }
public static void UpdateInterests <TKey, TInterest>( IInterestMap <TKey, TInterest> instance, IReadOnlySet <TKey> addTo, IReadOnlySet <TKey> removeFrom) { Contracts.Requires.That(instance != null); Contracts.Requires.That(!instance.IsDisposed); Contracts.Requires.That(addTo.AllAndSelfNotNull()); Contracts.Requires.That(removeFrom.AllAndSelfNotNull()); }
public static IObservable <KeyValuePair <TKey, bool> > GetInterestActivity <TKey, TInterest>( this IInterestMap <TKey, TInterest> map) { Contracts.Requires.That(map != null); return(map.GetInterestOpened().Select(key => KeyValuePair.New(key, true)) .Merge(map.GetInterestClosed().Select(key => KeyValuePair.New(key, false)))); }
public static void RemoveInterests <TKey, TInterest>( this IInterestMap <TKey, TInterest> map, TInterest interest, IReadOnlySet <TKey> removeFrom) { Contracts.Requires.That(map != null); Contracts.Requires.That(removeFrom.AllAndSelfNotNull()); map.UpdateInterests(interest, ReadOnlySet.Empty <TKey>(), removeFrom); }
public static void AddInterests <TKey, TInterest>( this IInterestMap <TKey, TInterest> map, TInterest interest, IReadOnlySet <TKey> addTo) { Contracts.Requires.That(map != null); Contracts.Requires.That(addTo.AllAndSelfNotNull()); map.UpdateInterests(interest, addTo, ReadOnlySet.Empty <TKey>()); }
public ConverterInterestMap( IInterestMap <TSource, TInterest> map, ITwoWayConverter <TResult, TSource> converter) { Contracts.Requires.That(map != null); Contracts.Requires.That(converter != null); this.map = map; this.converter = converter; }
public static IObservable <TKey> GetInterestClosed <TKey, TInterest>(this IInterestMap <TKey, TInterest> map) { Contracts.Requires.That(map != null); return(map.InterestsChanged.Where(changed => !map.Comparer.Equals(changed.Value.Previous, map.None) && map.Comparer.Equals(changed.Value.Next, map.None)) .Select(changed => changed.Key)); }
public static IVisiblyDisposable CreateCenteredSpiral <TInterest>( IInterestMap <Index3D, TInterest> map, TInterest interest, IObservable <Index3D> origin, IBoundedIndexable <Index3D, bool> shape) { Contracts.Requires.That(map != null); Contracts.Requires.That(origin != null); Contracts.Requires.That(shape != null); return(new AreaOfInterest3D <TInterest>( map, interest, origin, Keys.CreateCenteredSpiral(shape))); }
public static IVisiblyDisposable CreateCenteredSpiral <TInterest>( IInterestMap <Index3D, TInterest> map, TInterest interest, IObservable <Vector3> origin, IRasterizableMask <Index3D, bool> shape, float cellLength) { Contracts.Requires.That(map != null); Contracts.Requires.That(origin != null); Contracts.Requires.That(shape != null); Contracts.Requires.That(cellLength > 0); var rasterizedShape = shape.Rasterize(cellLength, true, false); return(CreateCenteredSpiral( map, interest, origin.FilterToChunkKeys(new Vector3(cellLength), rasterizedShape.Dimensions), rasterizedShape)); }
public static void RemoveInterest <TKey, TInterest>(IInterestMap <TKey, TInterest> instance, TKey key) { Contracts.Requires.That(instance != null); Contracts.Requires.That(!instance.IsDisposed); Contracts.Requires.That(key != null); }