public override ISearchCriteria CreateSearchCriteria(string type, BooleanOperation defaultOperation) { //TODO: It would be nice to be able to pass in the existing field definitions here so // we'd know what fields have sorting enabled so we don't have to use the special sorting syntax for field types return new LuceneSearchCriteria(type, IndexingAnalyzer, GetSearchFields(), EnableLeadingWildcards, defaultOperation); }
private Set BinaryOperation(Set set, BooleanOperation bop) { Set result = new Set(); for (int i = 0; i < data.Count; ++i) result.data[i] = bop(this.data[i], set.data[i]); return result; }
internal LuceneSearchCriteria(string type, Analyzer analyzer, string[] fields, bool allowLeadingWildcards, BooleanOperation occurance) { Enforcer.ArgumentNotNull(fields, "fields"); SearchIndexType = type; Query = new BooleanQuery(); this.BooleanOperation = occurance; this.QueryParser = new MultiFieldQueryParser(_luceneVersion, fields, analyzer); this.QueryParser.SetAllowLeadingWildcard(allowLeadingWildcards); this._occurance = occurance.ToLuceneOccurance(); }
protected LuceneSearchQueryBase( string category, Analyzer analyzer, string[] fields, LuceneSearchOptions searchOptions, BooleanOperation occurance) { Category = category; AllFields = fields ?? throw new ArgumentNullException(nameof(fields)); SearchOptions = searchOptions; Queries.Push(new BooleanQuery()); BooleanOperation = occurance; _queryParser = new CustomMultiFieldQueryParser(LuceneVersion, fields, analyzer); _queryParser.AllowLeadingWildcard = searchOptions.AllowLeadingWildcard; }
private IQuery InitialiseMemberQuery(BooleanOperation operation = BooleanOperation.And, string indexType = UmbracoIndexes.MembersIndexName) { if (examineManager.TryGetIndex(indexType, out var index)) { #if NET5_0_OR_GREATER var searcher = index.Searcher; #else var searcher = index.GetSearcher(); #endif return(searcher.CreateQuery(IndexTypes.Member, defaultOperation: operation)); } logger.LogWarning("Could not retrieve index {indexType}", indexType); return(null); }
public ExamineSearchBuilder(UmbracoHelper uHelper, string[] nodeTypeAlias) { _searchCriteria = ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.And); _queryNodes = null; _uHelper = uHelper; _NotProperties = new List <string>(); _NotFields = new List <string>(); _nodeTypeAlias = nodeTypeAlias.ToList(); _queryNodes = _searchCriteria.GroupedOr(new string[] { _docTypeAliasFieldName }, _nodeTypeAlias.ToArray()); _wildCardQuery = new StringBuilder(); _enumBooleanOperation = (BooleanOperation.And); _searchTerm = ""; _searchFields = new List <string>(); _nodeTypeAlias = new List <string>(); }
/// <summary> /// Converts an Examine boolean operation to a Lucene representation /// </summary> /// <param name="o">The operation.</param> /// <returns>The translated Boolean operation</returns> public static Occur ToLuceneOccurrence(this BooleanOperation o) { switch (o) { case BooleanOperation.And: return(Occur.MUST); case BooleanOperation.Not: return(Occur.MUST_NOT); case BooleanOperation.Or: default: return(Occur.SHOULD); } }
private static void TestBooleanOperation(BooleanOperation booleanOperation) { var sut = new ExpressionNode(booleanOperation.ToOperatorName(), new ReferenceExpression("a"), new ReferenceExpression("b")); var actual = Generate(sut); var expected = new List <IntermediateCode> { new BoolExpressionAssignment(booleanOperation, new Reference("T1"), new Reference("a"), new Reference("b")) }; actual.ShouldDeepEqual(expected); }
static ActionResult MenuBooleanOperation(BooleanOperation operation, ProBuilderMesh lhs, ProBuilderMesh rhs) { if (lhs == null || rhs == null) { return(new ActionResult(ActionResult.Status.Failure, "Must Select 2 Objects")); } string op_string = operation == BooleanOperation.Union ? "Union" : (operation == BooleanOperation.Subtract ? "Subtract" : "Intersect"); ProBuilderMesh[] sel = new ProBuilderMesh[] { lhs, rhs }; UndoUtility.RecordSelection(sel, op_string); UnityEngine.ProBuilder.Csg.Model result; switch (operation) { case BooleanOperation.Union: result = Boolean.Union(lhs.gameObject, rhs.gameObject); break; case BooleanOperation.Subtract: result = Boolean.Subtract(lhs.gameObject, rhs.gameObject); break; default: result = Boolean.Intersect(lhs.gameObject, rhs.gameObject); break; } var materials = result.materials.ToArray(); ProBuilderMesh pb = ProBuilderMesh.Create(); pb.GetComponent <MeshFilter>().sharedMesh = (Mesh)result; pb.GetComponent <MeshRenderer>().sharedMaterials = materials; MeshImporter importer = new MeshImporter(pb.gameObject); importer.Import(new MeshImportSettings() { quads = true, smoothing = true, smoothingAngle = 1f }); pb.Rebuild(); pb.CenterPivot(null); Selection.objects = new Object[] { pb.gameObject }; return(new ActionResult(ActionResult.Status.Success, op_string)); }
public static string ToOperatorName(this BooleanOperation op) { if (op == BooleanOperation.IsEqual) { return(Operator.Eq); } if (op == BooleanOperation.IsLessThan) { return(Operator.Lt); } if (op == BooleanOperation.IsGreaterThan) { return(Operator.Gt); } throw new ArgumentOutOfRangeException(nameof(op)); }
public static bool Calculate(bool value1, BooleanOperation operation, bool value2) { switch (operation) { case BooleanOperation.And: return(value1 && value2); case BooleanOperation.Or: return(value1 || value2); case BooleanOperation.Xor: return(value1 ^ value2); default: Debug.LogErrorFormat("unexpected operation type {0}", operation); return(true); } }
public ExamineSearchBuilder SearchContentPicker(string Category, List <string> CategoryValues, int enumBooleanOperation = 0) { BooleanOperation CategoryBooleanOperation = (BooleanOperation)enumBooleanOperation; if (!String.IsNullOrWhiteSpace(_wildCardQuery.ToString())) { _wildCardQuery.Append(CategoryBooleanOperation.ToString().ToUpper()); } _wildCardQuery.Append(Category + ":("); foreach (var value in CategoryValues.Distinct()) { _wildCardQuery.Append("*" + value.Replace("-", "") + "*" + (CategoryValues.Distinct().Count() > 1 && CategoryValues.Distinct().Last() != value? CategoryBooleanOperation.ToString().ToUpper() : "")); } _wildCardQuery.Append(")"); _searchCriteria.RawQuery(_wildCardQuery.ToString()); return(this); }
static ActionResult MenuBooleanOperation(BooleanOperation operation, ProBuilderMesh lhs, ProBuilderMesh rhs) { if (lhs == null || rhs == null) { return(new ActionResult(ActionResult.Status.Failure, "Must Select 2 Objects")); } string op_string = operation == BooleanOperation.Union ? "Union" : (operation == BooleanOperation.Subtract ? "Subtract" : "Intersect"); ProBuilderMesh[] sel = new ProBuilderMesh[] { lhs, rhs }; UndoUtility.RecordSelection(sel, op_string); Mesh c; switch (operation) { case BooleanOperation.Union: c = CSG.Union(lhs.gameObject, rhs.gameObject); break; case BooleanOperation.Subtract: c = CSG.Subtract(lhs.gameObject, rhs.gameObject); break; default: c = CSG.Intersect(lhs.gameObject, rhs.gameObject); break; } GameObject go = new GameObject(); go.AddComponent <MeshRenderer>().sharedMaterial = EditorMaterialUtility.GetUserMaterial(); go.AddComponent <MeshFilter>().sharedMesh = c; ProBuilderMesh pb = InternalMeshUtility.CreateMeshWithTransform(go.transform, false); DestroyImmediate(go); Selection.objects = new Object[] { pb.gameObject }; return(new ActionResult(ActionResult.Status.Success, op_string)); }
public static void MadeUnity() //Unite { Document document = TFlex.Application.ActiveDocument; document.BeginChanges("Сложение - быстрая булева"); int i = 0; Operation mOp1 = null; Operation mOp2 = null; BooleanOperation bo = new BooleanOperation(document); BooleanOperation.OperandsArray.Operand op1; BooleanOperation.OperandsArray.Operand op2; foreach (Operation my_op in document.Selection.GetAllObjects()) { i++; if (i == 1) { mOp1 = my_op; op1 = new BooleanOperation.OperandsArray.Operand(mOp1, false); bo.FirstOperands.Add(op1); } if (i >= 2) { mOp2 = my_op; op2 = new BooleanOperation.OperandsArray.Operand(mOp2, false); bo.SecondOperands.Add(op2); } //my_op.Name = my_op.Name+"_123"; } //Булева //тип операции - объединение bo.Function = BooleanOperation.FunctionType.Unite; bo.Regenerate(true); document.EndChanges(); }
protected internal new LuceneBooleanOperationBase Op( Func <INestedQuery, INestedBooleanOperation> inner, BooleanOperation outerOp, BooleanOperation?defaultInnerOp = null) { this._search.Queries.Push(new BooleanQuery()); BooleanOperation booleanOperation1 = this._search.BooleanOperation; if (defaultInnerOp.HasValue) { this._search.BooleanOperation = defaultInnerOp.Value; } INestedBooleanOperation booleanOperation2 = inner((INestedQuery)this._search); if (defaultInnerOp.HasValue) { this._search.BooleanOperation = booleanOperation1; } return(this._search.LuceneQuery((Query)this._search.Queries.Pop(), new BooleanOperation?(outerOp))); }
private string Compile(BooleanOperation booleanOperation) { var query = String.Empty; var type = booleanOperation.GetType(); if (type == typeof(ClauseOperation)) { query = CompileClause(((ClauseOperation)booleanOperation).Clause); } else if (type == typeof(FieldOperation)) { query = Compile((FieldOperation)booleanOperation); } else if (type == typeof(RangeOperation)) { query = Compile((RangeOperation)booleanOperation); } return(query); }
public static void MadeIntersect() //Intersection { Document document = TFlex.Application.ActiveDocument; document.BeginChanges("Пересечение - быстрая булева"); int i = 0; Operation mOp1 = null; Operation mOp2 = null; foreach (Operation my_op in document.Selection.GetAllObjects()) { i++; //назначить имя объекту //Пока только для двух операндов. if (i == 1) { mOp1 = my_op; } if (i >= 2) { mOp2 = my_op; } //my_op.Name = my_op.Name+"_123"; } //Булева BooleanOperation bo = new BooleanOperation(document); BooleanOperation.OperandsArray.Operand op1 = new BooleanOperation.OperandsArray.Operand(mOp1, false); BooleanOperation.OperandsArray.Operand op2 = new BooleanOperation.OperandsArray.Operand(mOp2, false); bo.FirstOperands.Add(op1); bo.SecondOperands.Add(op2); //тип операции - объединение bo.Function = BooleanOperation.FunctionType.Intersect; bo.Regenerate(true); document.EndChanges(); }
public static BooleanOperator ToOperator(this BooleanOperation op) { if (op == BooleanOperation.IsEqual) { return(BooleanOperator.Equal); } if (op == BooleanOperation.IsLessThan) { return(BooleanOperator.LessThan); } if (op == BooleanOperation.IsGreaterThan) { return(BooleanOperator.GreaterThan); } if (op == BooleanOperation.IsGreaterOrEqual) { return(BooleanOperator.GreaterOrEqual); } if (op == BooleanOperation.IsLessOrEqual) { return(BooleanOperator.LessThanOrEqual); } if (op == BooleanOperation.And) { return(BooleanOperator.And); } if (op == BooleanOperation.Or) { return(BooleanOperator.Or); } throw new ArgumentOutOfRangeException(); }
INestedBooleanOperation INestedBooleanOperation.AndNot(Func <INestedQuery, INestedBooleanOperation> inner, BooleanOperation defaultOp) => Op(inner, BooleanOperation.Not, defaultOp);
INestedBooleanOperation INestedBooleanOperation.Or(Func <INestedQuery, INestedBooleanOperation> inner, BooleanOperation defaultOp) => Op(inner, BooleanOperation.Or, defaultOp);
public IBooleanOperation Or(Func <INestedQuery, INestedBooleanOperation> inner, BooleanOperation defaultOp = BooleanOperation.And) => Op(inner, BooleanOperation.Or, defaultOp);
public ElasticSearchQuery(ElasticSearchQuery previous, BooleanOperation op) : base(previous.Category, previous.DefaultAnalyzer, previous._searcher.AllFields, EmptyOptions, op) { _searcher = previous._searcher; _indexName = previous._indexName; }
public static BooleanExpression FindMininalExpressionInBasis(int n, BooleanOperation[] ops, BooleanVariable[] vars, ExpressionSearchMode mode = ExpressionSearchMode.CountOps) { var queue = new ImprovisedPriorityQueue<BooleanExpression>(20); var knownTruthTables = new HashSet<byte>(); var knownExpressions = new HashSet<BooleanExpression>(); foreach(var variable in vars) { queue.TryEnqueue(new VarExpression(variable), 1); } while(queue.Count != 0) { var curExperession = queue.Dequeue(); byte truthTable = curExperession.Eval(); if(knownTruthTables.Contains(truthTable)) { continue; } if(curExperession.Eval() == n) { return curExperession; } knownExpressions.Add(curExperession); knownTruthTables.Add(truthTable); foreach(var anotherExpression in knownExpressions) { foreach(var neighbourExpression in curExperession.CombineWith(anotherExpression, ops)) { queue.TryEnqueue(neighbourExpression, mode == ExpressionSearchMode.CountBlocks ? neighbourExpression.CountBlocks() : neighbourExpression.CountOps()); } } } throw new CouldntFindExpressionException(); }
public BooleanExpression(Filter <T> left, Filter <T> right, BooleanOperation op) { Left = left; Right = right; Operator = op; }
public OpExpression(BooleanOperation op, BooleanVariable left, BooleanVariable right) { Op = op; Left = new VarExpression(left); Right = new VarExpression(right); }
public AzureQuery(AzureQuery previous, BooleanOperation op) : base(previous.Category, previous.DefaultAnalyzer, null, EmptyOptions, op) { IndexClient = previous.IndexClient; ServiceClient = previous.ServiceClient; }
public static string PrintOperation(BooleanOperation op) { return OpSymbols[(int)op]; }
/// <summary> /// Override in order to set the nodeTypeAlias field name of the underlying SearchCriteria to __NodeTypeAlias /// </summary> /// <param name="type"></param> /// <param name="defaultOperation"></param> /// <returns></returns> public override ISearchCriteria CreateSearchCriteria(string type, BooleanOperation defaultOperation) { var criteria = base.CreateSearchCriteria(type, defaultOperation) as LuceneSearchCriteria; criteria.NodeTypeAliasField = UmbracoContentIndexer.NodeTypeAliasFieldName; return criteria; }
public abstract ISearchCriteria CreateSearchCriteria(string type, BooleanOperation defaultOperation);
protected internal IBooleanOperation GroupedFlexibleInternal(string[] fields, BooleanOperation[] operations, IExamineValue[] fieldVals, BooleanClause.Occur occurance) { //if there's only 1 query text we want to build up a string like this: //(field1:query field2:query field3:query) //but Lucene will bork if you provide an array of length 1 (which is != to the field length) var flags = new BooleanClause.Occur[operations.Count()]; for (int i = 0; i < flags.Length; i++) flags[i] = operations.ElementAt(i).ToLuceneOccurance(); var queryVals = new IExamineValue[fields.Length]; if (fieldVals.Length == 1) { for (int i = 0; i < queryVals.Length; i++) queryVals[i] = fieldVals[0]; } else { queryVals = fieldVals; } var qry = new BooleanQuery(); for (int i = 0; i < fields.Length; i++) { var q = GetFieldInternalQuery(fields[i], queryVals[i], true); if (q != null) { qry.Add(q, flags[i]); } } this.Query.Add(qry, occurance); return new LuceneBooleanOperation(this); }
public SearchFilters(BooleanOperation booleanOperation) { _booleanOperation = booleanOperation; Filters = new List<SearchFilter>(); }
static void MenuBooleanOperation(BooleanOperation operation, pb_Object lhs, pb_Object rhs) { if(lhs == null || rhs == null) { pb_Editor_Utility.ShowNotification("Must Select 2 Objects"); return; } string op_string = operation == BooleanOperation.Union ? "Union" : (operation == BooleanOperation.Subtract ? "Subtract" : "Intersect"); pb_Object[] sel = new pb_Object[] { lhs, rhs }; pbUndo.RecordObjects(sel, op_string); Mesh c; switch(operation) { case BooleanOperation.Union: c = Parabox.CSG.CSG.Union(lhs.gameObject, rhs.gameObject); break; case BooleanOperation.Subtract: c = Parabox.CSG.CSG.Subtract(lhs.gameObject, rhs.gameObject); break; default: c = Parabox.CSG.CSG.Intersect(lhs.gameObject, rhs.gameObject); break; } GameObject go = new GameObject(); go.AddComponent<MeshRenderer>().sharedMaterial = pb_Constant.DefaultMaterial; go.AddComponent<MeshFilter>().sharedMesh = c; pb_Object pb = pbMeshOps.CreatePbObjectWithTransform(go.transform, false); DestroyImmediate(go); Selection.objects = new Object[] { pb.gameObject }; pb_Editor_Utility.ShowNotification(op_string); }
public CSGInnerNode( SetOperation op ) { switch ( op ) { case SetOperation.Intersection: bop = ( x, y ) => x && y; break; case SetOperation.Difference: bop = ( x, y ) => x && !y; break; case SetOperation.Xor: bop = ( x, y ) => x ^ y; break; case SetOperation.Union: default: bop = ( x, y ) => x || y; break; } // set accelerator flags: shortCurcuit = !(bop( false, false ) || bop( false, true )); // does empty left operand kill the result? trivial = bop( true, false ) && !bop( false, false ); // empty right operand doesn't change anything.. }
//---------------------------------------------------------------------------------------------------------------------------------------------------------- // Merge 2 Textures by apply Boolean operation(based on Alpha-channel) to them. Result-texture size will be expanded if needed. // Union - result Texture will contains all non-transparent pixels of both textures // Intersection - result Texture will contains only overlapped non-transparent pixels of textures // Subtraction - result Texture will contains only non-transparent pixels which aren't overlapped public static Texture2D ApplyBooleanOperation(BooleanOperation _operationType, Texture2D _base, Texture2D _addition, Vector2 _additionOffset) { _additionOffset = new Vector2(Mathf.CeilToInt(_additionOffset.x), Mathf.CeilToInt(_additionOffset.y)); Vector2 sizeIncrement = new Vector2(Mathf.Clamp(_addition.width + Mathf.Abs(_additionOffset.x) - _base.width, 0, Mathf.Infinity), Mathf.Clamp(_addition.height + Mathf.Abs(_additionOffset.y) - _base.height, 0, Mathf.Infinity)); Vector2 resultSize = new Vector2(_base.width + sizeIncrement.x, _base.height + sizeIncrement.y); Vector2 basePosition = new Vector2(_additionOffset.x > 0 ? 0 : sizeIncrement.x, _additionOffset.y > 0 ? 0 : sizeIncrement.y); Vector2 additionPosition = new Vector2(_additionOffset.x > 0 ? Mathf.Abs(_additionOffset.x) : 0, _additionOffset.y > 0 ? Mathf.Abs(_additionOffset.y) : 0); Texture2D result = new Texture2D(Mathf.CeilToInt(resultSize.x), Mathf.CeilToInt(resultSize.y)); Color[] resultPixels = new Color[Mathf.CeilToInt(resultSize.x * resultSize.y)]; Color[] basePixels = _base.GetPixels(); Color[] additionPixels = _addition.GetPixels(); result.SetPixels(0, 0, Mathf.CeilToInt(resultSize.x), Mathf.CeilToInt(resultSize.y), resultPixels); result.SetPixels(Mathf.CeilToInt(basePosition.x), Mathf.CeilToInt(basePosition.y), Mathf.CeilToInt(_base.width), Mathf.CeilToInt(_base.height), basePixels); resultPixels = result.GetPixels(); Color currentPixelColor; if (_operationType == BooleanOperation.Intersection) { Texture2D texture = new Texture2D(Mathf.CeilToInt(resultSize.x), Mathf.CeilToInt(resultSize.y)); Color[] pixels = new Color[Mathf.CeilToInt(resultSize.x * resultSize.y)]; texture.SetPixels(0, 0, Mathf.CeilToInt(resultSize.x), Mathf.CeilToInt(resultSize.y), pixels); texture.SetPixels(Mathf.CeilToInt(additionPosition.x), Mathf.CeilToInt(additionPosition.y), Mathf.CeilToInt(_addition.width), Mathf.CeilToInt(_addition.height), additionPixels); pixels = texture.GetPixels(); for (int i = 0; i < pixels.Length; i++) { resultPixels[i] = (resultPixels[i].a == 0 || pixels[i].a == 0) ? new Color(0, 0, 0, 0) : pixels[i]; } result.SetPixels(0, 0, Mathf.CeilToInt(resultSize.x), Mathf.CeilToInt(resultSize.y), resultPixels); } else if (_operationType == BooleanOperation.Union) { for (int y = 0; y < _addition.height; ++y) { for (int x = 0; x < _addition.width; ++x) { currentPixelColor = additionPixels[y * _addition.width + x].a == 0 ? resultPixels[Mathf.CeilToInt((y + additionPosition.y) * resultSize.x + (x + additionPosition.x))] : additionPixels[Mathf.CeilToInt(y * _addition.width + x)]; result.SetPixel(Mathf.CeilToInt(x + additionPosition.x), Mathf.CeilToInt(y + additionPosition.y), currentPixelColor); } } } else { for (int y = 0; y < _addition.height; ++y) { for (int x = 0; x < _addition.width; ++x) { currentPixelColor = additionPixels[y * _addition.width + x].a == 0 ? resultPixels[Mathf.CeilToInt((y + additionPosition.y) * resultSize.x + (x + additionPosition.x))] : additionPixels[Mathf.CeilToInt(y * _addition.width + x)]; if (resultPixels[Mathf.CeilToInt((y + additionPosition.y) * resultSize.x + (x + additionPosition.x))].a != 0 && additionPixels[Mathf.CeilToInt(y * _addition.width + x)].a != 0) { currentPixelColor.a = 0; } result.SetPixel(Mathf.CeilToInt(x + additionPosition.x), Mathf.CeilToInt(y + additionPosition.y), currentPixelColor); } } } result.Apply(); return(result); }
public ElasticSearchQuery(ElasticSearchSearcher searcher, string category, string[] fields, BooleanOperation op, string indexName) : base(category, new StandardAnalyzer(Version.LUCENE_29), fields, EmptyOptions, op) { _searcher = searcher; _indexName = indexName; _queryParser = new CustomMultiFieldQueryParser(LuceneVersion, fields, new StandardAnalyzer(Version.LUCENE_29)); _queryParser.AllowLeadingWildcard = true; }
public OpExpression(BooleanOperation op, BooleanExpression left, BooleanExpression right) { Op = op; Left = left; Right = right; }
public LuceneSearchQuery( ISearchContext searchContext, string category, Analyzer analyzer, string[] fields, LuceneSearchOptions searchOptions, BooleanOperation occurance) : base(CreateQueryParser(searchContext, fields, analyzer), category, fields, searchOptions, occurance) { _searchContext = searchContext; }
public override ISearchCriteria CreateSearchCriteria(string type, BooleanOperation defaultOperation) { return new LuceneSearchCriteria(type, IndexingAnalyzer, GetSearchFields(), EnableLeadingWildcards, defaultOperation); }
public override ISearchCriteria CreateSearchCriteria(BooleanOperation defaultOperation) { return(CreateSearchCriteria(string.Empty, defaultOperation)); }
public ISearchCriteria CreateSearchCriteria(BooleanOperation defaultOperation) { return this.CreateSearchCriteria(string.Empty, defaultOperation); }
public BoboFacetQuery(ISearchContext searchContext, string category, Analyzer analyzer, string[] fields, LuceneSearchOptions searchOptions, BooleanOperation occurance) : base(searchContext, category, analyzer, fields, searchOptions, occurance) { _searchContext = searchContext; }
public ISearchCriteria CreateSearchCriteria(BooleanOperation defaultOperation) { return(this.CreateSearchCriteria(string.Empty, defaultOperation)); }
public static List <List <MyVector2> > ClipPolygons(List <MyVector2> polyVector2, List <MyVector2> clipPolyVector2, BooleanOperation booleanOperation) { List <List <MyVector2> > finalPoly = new List <List <MyVector2> >(); //Step 0. Create the data structure needed List <ClipVertex> poly = InitDataStructure(polyVector2); List <ClipVertex> clipPoly = InitDataStructure(clipPolyVector2); //Step 1. Find intersection points //Need to test if we have found an intersection point, //if none is found, the polygons dont intersect, or one polygon is inside the other bool hasFoundIntersection = false; for (int i = 0; i < poly.Count; i++) { ClipVertex currentVertex = poly[i]; //Important to use iPlusOne because poly.next may change int iPlusOne = MathUtility.ClampListIndex(i + 1, poly.Count); MyVector2 a = poly[i].coordinate; MyVector2 b = poly[iPlusOne].coordinate; //Gizmos.DrawWireSphere(poly[i].coordinate, 0.02f); //Gizmos.DrawWireSphere(poly[i].next.coordinate, 0.02f); for (int j = 0; j < clipPoly.Count; j++) { int jPlusOne = MathUtility.ClampListIndex(j + 1, clipPoly.Count); MyVector2 c = clipPoly[j].coordinate; MyVector2 d = clipPoly[jPlusOne].coordinate; //Are these lines intersecting? if (_Intersections.LineLine(a, b, c, d, true)) { hasFoundIntersection = true; MyVector2 intersectionPoint2D = _Intersections.GetLineLineIntersectionPoint(a, b, c, d); //Vector3 intersectionPoint = new Vector3(intersectionPoint2D.x, 0f, intersectionPoint2D.y); //Gizmos.color = Color.red; //Gizmos.DrawWireSphere(intersectionPoint, 0.04f); //We need to insert this intersection vertex into both polygons //Insert into the polygon ClipVertex vertexOnPolygon = InsertIntersectionVertex(a, b, intersectionPoint2D, currentVertex); //Insert into the clip polygon ClipVertex vertexOnClipPolygon = InsertIntersectionVertex(c, d, intersectionPoint2D, clipPoly[j]); //Also connect the intersection vertices with each other vertexOnPolygon.neighbor = vertexOnClipPolygon; vertexOnClipPolygon.neighbor = vertexOnPolygon; } } } //Debug in which order the vertices are in the linked list //InWhichOrderAreVerticesAdded(poly); //InWhichOrderAreVerticesAdded(clipPoly); //If the polygons are intersecting if (hasFoundIntersection) { //Step 2. Trace each polygon and mark entry and exit points to the other polygon's interior MarkEntryExit(poly, clipPolyVector2); MarkEntryExit(clipPoly, polyVector2); //Debug entry exit points DebugEntryExit(poly); //DebugEntryExit(clipPoly); //Step 3. Create the desired clipped polygon if (booleanOperation == BooleanOperation.Intersection) { //Where the two polygons intersect List <ClipVertex> intersectionVertices = GetClippedPolygon(poly, true); //Debug.Log(intersectionVertices.Count); AddPolygonToList(intersectionVertices, finalPoly, false); //Debug.Log(); } else if (booleanOperation == BooleanOperation.Difference) { //Whats outside of the polygon that doesnt intersect List <ClipVertex> outsidePolyVertices = GetClippedPolygon(poly, false); AddPolygonToList(outsidePolyVertices, finalPoly, true); } else if (booleanOperation == BooleanOperation.ExclusiveOr) { //Whats outside of the polygon that doesnt intersect List <ClipVertex> outsidePolyVertices = GetClippedPolygon(poly, false); AddPolygonToList(outsidePolyVertices, finalPoly, true); //Whats outside of the polygon that doesnt intersect List <ClipVertex> outsideClipPolyVertices = GetClippedPolygon(clipPoly, false); AddPolygonToList(outsideClipPolyVertices, finalPoly, true); } else if (booleanOperation == BooleanOperation.Union) { //Where the two polygons intersect List <ClipVertex> intersectionVertices = GetClippedPolygon(poly, true); AddPolygonToList(intersectionVertices, finalPoly, false); //Whats outside of the polygon that doesnt intersect List <ClipVertex> outsidePolyVertices = GetClippedPolygon(poly, false); AddPolygonToList(outsidePolyVertices, finalPoly, true); //Whats outside of the polygon that doesnt intersect List <ClipVertex> outsideClipPolyVertices = GetClippedPolygon(clipPoly, false); AddPolygonToList(outsideClipPolyVertices, finalPoly, true); } //Where the two polygons intersect //List<ClipVertex> intersectionVertices = GetClippedPolygon(poly, true); //Whats outside of the polygon that doesnt intersect //These will be in clockwise order so remember to change to counter clockwise //List<ClipVertex> outsidePolyVertices = GetClippedPolygon(poly, false); //List<ClipVertex> outsideClipPolyVertices = GetClippedPolygon(clipPoly, false); } //Check if one polygon is inside the other else { //Is the polygon inside the clip polygon? //Depending on the type of boolean operation, we might get a hole if (IsPolygonInsidePolygon(polyVector2, clipPolyVector2)) { Debug.Log("Poly is inside clip poly"); } else if (IsPolygonInsidePolygon(clipPolyVector2, polyVector2)) { Debug.Log("Clip poly is inside poly"); } else { Debug.Log("Polygons are not intersecting"); } } return(finalPoly); }
private void BooleanPaste(BooleanOperation operation) { if (_systemInterface.Clipboard == null) { return; } var clipboard = _systemInterface.Clipboard; var height = clipboard.GetLength(Utils.IndexRowsOrHeight); var width = clipboard.GetLength(Utils.IndexColsOrWidth); var left = _selectedCells.Left; var top = _selectedCells.Top; AddUndoItem(new Rectangle(left, top, width, height), UndoOriginalBehavior.Overwrite, Resources.UndoText_BooleanPaste); for (var row = 0; row < height && top + row < _sequence.ChannelCount; row++) { var currentRow = GetEventFromChannelNumber(top + row); for (var col = 0; col < width && left + col < _sequence.TotalEventPeriods; col++) { var currentCol = left + col; var currentValue = _sequence.EventValues[currentRow, currentCol]; var clipValue = clipboard[row, col]; switch (operation) { case BooleanOperation.OR: { currentValue |= clipValue; break; } case BooleanOperation.AND: { currentValue &= clipValue; break; } case BooleanOperation.XOR: { currentValue ^= clipValue; break; } case BooleanOperation.NOR: currentValue = (byte) ~(currentValue | clipValue); break; case BooleanOperation.NAND: currentValue = (byte) ~(currentValue & clipValue); break; case BooleanOperation.XNOR: currentValue = (byte) ~(currentValue ^ clipValue); break; } _sequence.EventValues[currentRow, currentCol] = currentValue; } } IsDirty = true; pictureBoxGrid.Refresh(); }
public override IQuery CreateQuery(string category = null, BooleanOperation defaultOperation = BooleanOperation.And) { return(new AzureQuery(_indexClient.Value, _serviceClient.Value, category, AllFields, defaultOperation)); }
public CombinedFilter(string filterTypeName, string label, BooleanOperation operation) { FilterTypeName = filterTypeName; Label = label; Operation = operation; Filters = Enumerable.Empty<Filter>(); }
public ISearchCriteria CreateSearchCriteria(string type, BooleanOperation defaultOperation) { return this.DefaultSearchProvider.CreateSearchCriteria(type, defaultOperation); }
public IEnumerable<BooleanExpression> CombineWith(BooleanExpression anotherExpression, BooleanOperation[] ops) { foreach(var op in ops) { yield return new OpExpression(op, Clone(), anotherExpression.Clone()); yield return new OpExpression(op, anotherExpression.Clone(), Clone()); } }
public ISearchCriteria CreateSearchCriteria(string type, BooleanOperation defaultOperation) { return(this.DefaultSearchProvider.CreateSearchCriteria(type, defaultOperation)); }
public override ISearchCriteria CreateSearchCriteria(BooleanOperation defaultOperation) { return CreateSearchCriteria(string.Empty, defaultOperation); }