Example #1
0
 public bool Contains(float x, float y, ContainsMode mode, out IBaseShape rootShape, out IBaseShape childShape)
 {
     rootShape  = null;
     childShape = null;
     for (int i = 0; i < Children.Count; i++)
     {
         if (mode == ContainsMode.Geometry)
         {
             if (Children[i].Geometry.Contains(x, y))
             {
                 rootShape  = this.Shape;
                 childShape = Children[i].Shape;
                 return(true);
             }
         }
         else if (mode == ContainsMode.Bounds)
         {
             if (Children[i].Bounds.Contains(x, y))
             {
                 rootShape  = this.Shape;
                 childShape = Children[i].Shape;
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Example #2
0
        public static Expression <Func <TEntity, IEnumerable <TItem> > > BuildWhereContainsExpression <TEntity, TItem, TProperty>(
            Expression <Func <TEntity, IEnumerable <TItem> > > collectionAccessorExpression,
            Expression <Func <TItem, TProperty> > propertyExpression,
            ICollection <TProperty> collection,
            ContainsMode containsMode,
            int cachableLevel = 20)
            where TItem : class
        {
            if (collectionAccessorExpression == null)
            {
                throw new ArgumentNullException(nameof(collectionAccessorExpression));
            }

            // x.values
            Expression collectionAccessor = collectionAccessorExpression.Body;

            // y => y.property == value op y.property == value2 ...
            Expression <Func <TItem, bool> > innerExpression = BuildContainsExpression(propertyExpression, collection, containsMode, cachableLevel);

            // x.values.Where(y => y.property == value op y.property == value2 ..)
            MethodCallExpression memberCall = Expression.Call(null, GetGenericMethodInfo <TItem>("Where", 2), collectionAccessor, innerExpression);

            // x => x.values.Where(y => y.property == value op y.property == value2 ..)
            return(Expression.Lambda <Func <TEntity, IEnumerable <TItem> > >(memberCall, collectionAccessorExpression.Parameters));
        }
Example #3
0
 public bool Contains(float x, float y, ContainsMode mode)
 {
     if (mode == ContainsMode.Geometry)
     {
         return(Geometry.Contains(x, y));
     }
     else if (mode == ContainsMode.Bounds)
     {
         return(Bounds.Contains(x, y));
     }
     return(false);
 }
Example #4
0
 public bool Contains(float x, float y, ContainsMode mode, out IBaseShape rootShape, out IBaseShape childShape)
 {
     rootShape  = null;
     childShape = null;
     for (int i = 0; i < _renderer._rootNodes.Count; i++)
     {
         if (_renderer._rootNodes[i].Contains(x, y, mode, out rootShape, out childShape))
         {
             return(true);
         }
     }
     return(false);
 }
Example #5
0
        public static bool Contains(this IInterval self, int index,
                                    ContainsMode mode = ContainsMode.NON_STRICT)
        {
            var s = self.ToInterval();

            if (mode == ContainsMode.NON_STRICT)
            {
                return(s.Start <= index && index <= s.End);
            }
            else
            {
                return(s.Start < index && index < s.End);
            }
        }
Example #6
0
        /// <summary>
        /// Converts all wildcard modes to WildCardRight and all non wildcard modes to Default
        /// </summary>
        private ContainsMode SingleWordContainsMode(ContainsMode containsMode)
        {
            switch (containsMode)
            {
            case ContainsMode.WildcardRight:
            case ContainsMode.AnyWordWildcardRight:
            case ContainsMode.AllWordsWildcardRight:
            case ContainsMode.FreeText:
                return(ContainsMode.WildcardRight);

            default:
                return(ContainsMode.Default);
            }
        }
Example #7
0
        public static bool Contains(this IInterval self, IInterval other,
                                    ContainsMode mode = ContainsMode.NON_STRICT)
        {
            var s = self.ToInterval();
            var o = other.ToInterval();

            if (mode == ContainsMode.NON_STRICT)
            {
                return(s.Start <= o.Start && o.End <= s.End);
            }
            else
            {
                return(s.Start < o.Start && o.End < s.End);
            }
        }
Example #8
0
        public static bool IsAfter(this IInterval self, IInterval other,
                                   ContainsMode mode = ContainsMode.NON_STRICT)
        {
            var s = self.ToInterval();
            var o = other.ToInterval();

            if (mode == ContainsMode.NON_STRICT)
            {
                return(s.Start >= o.End);
            }
            else
            {
                return(s.Start > o.End);
            }
        }
Example #9
0
        private static IEnumerable <Interval <T> > RemoveCoveredEnumerator <T>(this SortedIntervals <T> intervals,
                                                                               ContainsMode mode = ContainsMode.NON_STRICT)
        {
            IInterval <T> current = null;

            foreach (var interval in intervals)
            {
                if (current == null)
                {
                    current = interval;
                }
                else if (!current.Contains(interval, mode))
                {
                    yield return(interval);

                    current = interval;
                }
            }
        }
Example #10
0
 public static SelectQuery WhereColumnContains(this SelectQuery query, string leftTableAlias, string leftField, string text, ContainsMode mode = ContainsMode.Default)
 {
     query.WhereFilters.WhereColumnContains(leftTableAlias, leftField, text, mode);
     return(query);
 }
Example #11
0
        public static Expression <Func <TEntity, bool> > BuildContainsExpression <TEntity, TProperty>(
            Expression <Func <TEntity, TProperty> > propertyExpression, ICollection <TProperty> collection, ContainsMode containsMode, int cachableLevel = 20)
            where TEntity : class
        {
            if (propertyExpression == null)
            {
                throw new ArgumentNullException(nameof(propertyExpression));
            }

            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            if (!(propertyExpression.Body is MemberExpression))
            {
                throw new ArgumentException(
                          "Property expression should be correct and type of property and collection should be equals. When property types is nullable, collection type also shoud be nullable.",
                          nameof(propertyExpression));
            }

            ParameterExpression parameterExpression = propertyExpression.Parameters[0];
            var memberExpression = (MemberExpression)propertyExpression.Body;

            if (collection.Count > cachableLevel)
            {
                return(containsMode == ContainsMode.In
                    ? CreateContainsExpression <TEntity, TProperty>(parameterExpression, memberExpression, collection)
                    : CreateNotContainsExpression <TEntity, TProperty>(parameterExpression, memberExpression, collection));
            }

            return(containsMode == ContainsMode.In
                ? CreateOrExpression <TEntity, TProperty>(parameterExpression, memberExpression, collection)
                : CreateAndExpression <TEntity, TProperty>(parameterExpression, memberExpression, collection));
        }
Example #12
0
        public static IQueryable <TEntity> ApplyContainsExpression <TEntity, TProperty>(this IQueryable <TEntity> source,
                                                                                        Expression <Func <TEntity, TProperty> > propertyExpression, ICollection <TProperty> collection, ContainsMode containsMode, int cachableLevel = 20)
            where TEntity : class
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (!collection.Any())
            {
                if (containsMode == ContainsMode.In)
                {
                    throw new Exception($"${nameof(collection)} must not be empty");
                }
                else
                {
                    return(source);
                }
            }

            Expression <Func <TEntity, bool> > expression = BuildContainsExpression(propertyExpression, collection, containsMode, cachableLevel);

            return(source.Where(expression));
        }
Example #13
0
 public static WhereFilterCollection WhereColumnContains(this WhereFilterCollection query, string leftTableAlias, string leftField, string text, ContainsMode mode = ContainsMode.Default)
 {
     query.Add(new ColumnContainsWhereFilter()
     {
         LeftColumn   = new Column(leftTableAlias, leftField),
         ContainsMode = mode,
         Text         = text
     });
     return(query);
 }
Example #14
0
 public static WhereFilterCollection WhereColumnContains(this WhereFilterCollection query, Table leftTable, string leftField, string text, ContainsMode mode = ContainsMode.Default)
 {
     query.WhereColumnContains(leftTable.Alias, leftField, text, mode);
     return(query);
 }
Example #15
0
 /// <summary>
 /// Filter out the intervals that are entirely covered by another interval, if provided
 /// condition is satisfied. The condition's first parameter is the covering interval,
 /// the second one is the covered interval. If the condition function returns `true` the
 /// covered interval will be removed.
 /// </summary>
 public static SortedIntervals <T> RemoveCovered <T>(this SortedIntervals <T> intervals,
                                                     Func <T, T, bool> condition, ContainsMode mode = ContainsMode.NON_STRICT)
 {
     return(new SortedIntervals <T>(RemoveCoveredEnumerator(intervals, condition, mode)));
 }
Example #16
0
 public static SortedIntervals <T> IntersectingWith <T>(this SortedIntervals <T> intervals,
                                                        IEnumerable <IInterval> others, ContainsMode mode = ContainsMode.NON_STRICT)
 {
     return(new SortedIntervals <T>(intervals.AsEnumerable().IntersectingWith(others, mode)));
 }
Example #17
0
 /// <summary>
 /// Filter out the intervals that are entirely covered by another interval.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="intervals"></param>
 /// <returns></returns>
 public static SortedIntervals <T> RemoveCovered <T>(this SortedIntervals <T> intervals,
                                                     ContainsMode mode = ContainsMode.NON_STRICT)
 {
     return(new SortedIntervals <T>(RemoveCoveredEnumerator(intervals, mode)));
 }