Ejemplo n.º 1
0
        //
        // static factory method(s)
        //

        #region public static DBBooleanOp Compare(DBClause left, BooleanOp op, DBClause right)

        /// <summary>
        /// Creates a new DBBooleanOp to compare the left and right clauses using the specified boolean operator
        /// </summary>
        /// <param name="left"></param>
        /// <param name="op"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public static DBBooleanOp Compare(DBClause left, BooleanOp op, DBClause right)
        {
            DBBooleanOpRef oref = new DBBooleanOpRef();

            oref.Left     = left;
            oref.Right    = right;
            oref.Operator = op;
            return(oref);
        }
Ejemplo n.º 2
0
        public void TestCreateBooleanOp02()
        {
            BooleanOp booleanOp = CreateBooleanOp02();

            Assert.IsNotNull(booleanOp);
            #region Record State
            ValueRecorder recorder = new ValueRecorder();
            recorder.Record((OperatorPriority)booleanOp.Priority);
            recorder.FinishRecording();
            #endregion
        }
Ejemplo n.º 3
0
 private static CompoundTest BinaryBoolOperator(CompoundTest a, IFlagTest b, BooleanOp op)
 {
     IFlagTest[] tests;
     if (a.mode == op && b is CompoundTest bc)
     {
         tests = new IFlagTest[bc.tests.Length + 1];
         a.tests.CopyTo(tests, 0);
         tests[tests.Length - 1] = b;
     }
     else
     {
         tests = new IFlagTest[] { a, b };
     }
     return(new CompoundTest(tests, op));
 }
Ejemplo n.º 4
0
        public static List <GeneralPolygon2d> PolygonBoolean(
            ICollection <GeneralPolygon2d> poly1, ICollection <GeneralPolygon2d> poly2,
            BooleanOp opType, double minArea = -1)
        {
            // handle cases where one list is empty
            if (poly1.Count == 0)
            {
                if (opType == BooleanOp.Difference || opType == BooleanOp.Intersection)
                {
                    return(new List <GeneralPolygon2d>());
                }
                else
                {
                    return(DeepCopy.List(poly2));
                }
            }
            else if (poly2.Count == 0)
            {
                if (opType == BooleanOp.Intersection)
                {
                    return(new List <GeneralPolygon2d>());
                }
                else
                {
                    return(DeepCopy.List(poly1));
                }
            }


            double nIntScale = Math.Max(GetIntScale(poly1), GetIntScale(poly2));

            if (minArea < 0)
            {
                minArea = DiscardMinArea;
            }

            try {
                Clipper clipper = new Clipper(Clipper.ioStrictlySimple);

                foreach (GeneralPolygon2d sub in poly1)
                {
                    CPolygonList cpoly = ConvertToClipper(sub, nIntScale);
                    clipper.AddPaths(cpoly, PolyType.ptSubject, true);
                }
                foreach (GeneralPolygon2d clip in poly2)
                {
                    CPolygonList cpoly = ConvertToClipper(clip, nIntScale);
                    clipper.AddPaths(cpoly, PolyType.ptClip, true);
                }

                ClipType cType = ClipType.ctUnion;
                if (opType == BooleanOp.Difference)
                {
                    cType = ClipType.ctDifference;
                }
                else if (opType == BooleanOp.Intersection)
                {
                    cType = ClipType.ctIntersection;
                }
                else if (opType == BooleanOp.Xor)
                {
                    cType = ClipType.ctXor;
                }

                PolyTree tree = new PolyTree();
                bool     bOK  = clipper.Execute(cType, tree);
                if (bOK == false)
                {
                    //System.Diagnostics.Debug.WriteLine("ClipperUtil.PolygonBoolean: Clipper failed");
                    return(new List <GeneralPolygon2d>());
                }

                List <GeneralPolygon2d> result = new List <GeneralPolygon2d>();
                for (int ci = 0; ci < tree.ChildCount; ++ci)
                {
                    Convert(tree.Childs[ci], result, nIntScale, minArea);
                }
                return(result);
            } catch /*(Exception e)*/ {
                //System.Diagnostics.Debug.WriteLine("ClipperUtil.PolygonBoolean: Clipper threw exception: " + e.Message);
                return(new List <GeneralPolygon2d>());
            }
        }
Ejemplo n.º 5
0
 public static List <GeneralPolygon2d> PolygonBoolean(
     List <GeneralPolygon2d> poly1, List <GeneralPolygon2d> poly2,
     BooleanOp opType, double minArea = -1)
 {
     return(PolygonBoolean((ICollection <GeneralPolygon2d>)poly1, (ICollection <GeneralPolygon2d>)poly2, opType, minArea));
 }
Ejemplo n.º 6
0
 public static List <GeneralPolygon2d> PolygonBoolean(List <GeneralPolygon2d> poly1, GeneralPolygon2d poly2, BooleanOp opType, double minArea = -1)
 {
     return(PolygonBoolean(poly1, new List <GeneralPolygon2d>()
     {
         poly2
     }, opType, minArea));
 }
Ejemplo n.º 7
0
 public static List <GeneralPolygon2d> PolygonBoolean(ICollection <GeneralPolygon2d> poly1, GeneralPolygon2d poly2, BooleanOp opType, double minArea = -1)
 {
     return(PolygonBoolean(poly1, new GeneralPolygon2d[] { poly2 }, opType, minArea));
 }
Ejemplo n.º 8
0
 public static List <GeneralPolygon2d> PolygonBoolean(GeneralPolygon2d poly1, ICollection <GeneralPolygon2d> poly2, BooleanOp opType, double minArea = -1)
 {
     return(PolygonBoolean(new List <GeneralPolygon2d>()
     {
         poly1
     }, poly2, opType, minArea));
 }
Ejemplo n.º 9
0
        void OnGUI()
        {
            Event e = Event.current;
            screen.x = (int)position.width;
            screen.y = (int)position.height;

            // Since image wells eat mouse clicks, listen for a mouse up when hovering over 'reverse operation order' button
            switch (e.type)
            {
                case EventType.MouseDown:
                    if (swapOrderRect.Contains(e.mousePosition))
                    {
                        mouseClickedSwapRect = true;
                        e.Use();
                    }
                    break;

                case EventType.MouseUp:
                    if (mouseClickedSwapRect && swapOrderRect.Contains(Event.current.mousePosition))
                    {
                        ReverseOperationOrder();
                        e.Use();
                    }
                    mouseClickedSwapRect = false;
                    break;

                case EventType.Ignore:
                    mouseClickedSwapRect = false;
                    break;
            }

            DrawPreviewWells();

            if (ListenForDragAndDrop())
                return;

            swapOrderRect.x = (screen.x / 2f) - (swapOrderRect.width / 2f);
            swapOrderRect.y = k_Padding + m_PreviewHeight / 2f - (swapOrderRect.width / 2f);

            // http://xahlee.info/comp/unicode_arrows.html
            if (GUI.Button(swapOrderRect, ((char)8644).ToString(), unicodeIconStyle))
            {
                ReverseOperationOrder();
            }

            GUILayout.Space(m_PreviewHeight + k_Padding * 2);

            GUILayout.BeginHorizontal();
            ProBuilderMesh lpb = m_LeftGameObject != null ? m_LeftGameObject.GetComponent<ProBuilderMesh>() : null;
            ProBuilderMesh rpb = m_RightGameObject != null ? m_RightGameObject.GetComponent<ProBuilderMesh>() : null;

            lpb = (ProBuilderMesh)EditorGUILayout.ObjectField(lpb, typeof(ProBuilderMesh), true);
            rpb = (ProBuilderMesh)EditorGUILayout.ObjectField(rpb, typeof(ProBuilderMesh), true);

            m_LeftGameObject = lpb != null ? lpb.gameObject : null;
            m_RightGameObject = rpb != null ? rpb.gameObject : null;
            GUILayout.EndHorizontal();

            // Boolean controls
            GUILayout.Space(4);

            GUI.backgroundColor = PreferenceKeys.proBuilderDarkGray;
            UI.EditorGUIUtility.DrawSeparator(2);
            GUI.backgroundColor = Color.white;

            operation = (BooleanOp)EditorGUILayout.EnumPopup("Operation", operation);

            if (GUILayout.Button("Apply", GUILayout.MinHeight(32)))
            {
                switch (operation)
                {
                    case BooleanOp.Union:
                        MenuUnion(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
                        break;

                    case BooleanOp.Intersection:
                        MenuIntersect(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
                        break;

                    case BooleanOp.Subtraction:
                        MenuSubtract(m_LeftGameObject.GetComponent<ProBuilderMesh>(), m_RightGameObject.GetComponent<ProBuilderMesh>());
                        break;
                }
            }
        }
Ejemplo n.º 10
0
    void OnGUI()
    {
        Event e = Event.current;

        // Since image wells eat mouse clicks, listen for a mouse up when hovering over 'reverse operation order' button
        switch (e.type)
        {
        case EventType.MouseDown:
            if (swapOrderRect.Contains(e.mousePosition))
            {
                mouseClickedSwapRect = true;
                e.Use();
            }
            break;

        case EventType.MouseUp:
            if (mouseClickedSwapRect && swapOrderRect.Contains(Event.current.mousePosition))
            {
                ReverseOperationOrder();
                e.Use();
            }
            mouseClickedSwapRect = false;
            break;

        case EventType.Ignore:
            mouseClickedSwapRect = false;
            break;
        }

        DrawPreviewWells();

        if (ListenForDragAndDrop())
        {
            return;
        }

        swapOrderRect.x = (Screen.width / 2f) - (swapOrderRect.width / 2f);
        swapOrderRect.y = PAD + previewHeight / 2f - (swapOrderRect.width / 2f);

        // http://xahlee.info/comp/unicode_arrows.html
        if (GUI.Button(swapOrderRect, ((char)8644).ToString(), unicodeIconStyle))
        {
            ReverseOperationOrder();
        }

        GUILayout.Space(previewHeight + PAD * 2);

        GUILayout.BeginHorizontal();
        pb_Object lpb = lhs != null?lhs.GetComponent <pb_Object>() : null;

        pb_Object rpb = rhs != null?rhs.GetComponent <pb_Object>() : null;

        lpb = (pb_Object)EditorGUILayout.ObjectField(lpb, typeof(pb_Object), true);
        rpb = (pb_Object)EditorGUILayout.ObjectField(rpb, typeof(pb_Object), true);

        lhs = lpb != null ? lpb.gameObject : null;
        rhs = rpb != null ? rpb.gameObject : null;
        GUILayout.EndHorizontal();

        // Boolean controls
        GUILayout.Space(4);

        GUI.backgroundColor = pb_Constant.ProBuilderDarkGray;
        pb_GUI_Utility.DrawSeparator(2);
        GUI.backgroundColor = Color.white;

        operation = (BooleanOp)EditorGUILayout.EnumPopup("Operation", operation);

        if (GUILayout.Button("Apply", GUILayout.MinHeight(32)))
        {
            switch (operation)
            {
            case BooleanOp.Union:
                pb_Menu_Commands.MenuUnion(lhs.GetComponent <pb_Object>(), rhs.GetComponent <pb_Object>());
                break;

            case BooleanOp.Intersection:
                pb_Menu_Commands.MenuIntersect(lhs.GetComponent <pb_Object>(), rhs.GetComponent <pb_Object>());
                break;

            case BooleanOp.Subtraction:
                pb_Menu_Commands.MenuSubtract(lhs.GetComponent <pb_Object>(), rhs.GetComponent <pb_Object>());
                break;
            }
        }
    }
	void OnGUI()
	{	
		Event e = Event.current;

		// Since image wells eat mouse clicks, listen for a mouse up when hovering over 'reverse operation order' button
		switch(e.type)
		{
			case EventType.MouseDown:
					if(swapOrderRect.Contains(e.mousePosition))
					{
						mouseClickedSwapRect = true;
						e.Use();
					}
				break;

			case EventType.MouseUp:
				if(mouseClickedSwapRect && swapOrderRect.Contains(Event.current.mousePosition))
				{
					ReverseOperationOrder();
					e.Use();
				}
				mouseClickedSwapRect = false;
				break;

			case EventType.Ignore:
				mouseClickedSwapRect = false;
				break;
		}

		DrawPreviewWells();

		if(ListenForDragAndDrop())
		{
			return;
		}

		swapOrderRect.x = (Screen.width/2f)-(swapOrderRect.width/2f);
		swapOrderRect.y = PAD + previewHeight/2f - (swapOrderRect.width/2f);

		// http://xahlee.info/comp/unicode_arrows.html
		if(GUI.Button( swapOrderRect, ((char)8644).ToString(), unicodeIconStyle))
		{
			ReverseOperationOrder();
		}

		GUILayout.Space(previewHeight + PAD*2);

		GUILayout.BeginHorizontal();
			pb_Object lpb = lhs != null ? lhs.GetComponent<pb_Object>() : null;
			pb_Object rpb = rhs != null ? rhs.GetComponent<pb_Object>() : null;

			lpb = (pb_Object) EditorGUILayout.ObjectField(lpb, typeof(pb_Object), true);
			rpb = (pb_Object) EditorGUILayout.ObjectField(rpb, typeof(pb_Object), true);

			lhs = lpb != null ? lpb.gameObject : null;
			rhs = rpb != null ? rpb.gameObject : null;
		GUILayout.EndHorizontal();

		// Boolean controls
		GUILayout.Space(4);

		GUI.backgroundColor = pb_Constant.ProBuilderDarkGray;
		pb_GUI_Utility.DrawSeparator(2);
		GUI.backgroundColor = Color.white;

		operation = (BooleanOp) EditorGUILayout.EnumPopup("Operation", operation);

		if(GUILayout.Button("Apply", GUILayout.MinHeight(32)))
		{
			switch(operation)
			{
				case BooleanOp.Union:
					pb_Menu_Commands.MenuUnion(lhs.GetComponent<pb_Object>(), rhs.GetComponent<pb_Object>());
					break;

				case BooleanOp.Intersection:
					pb_Menu_Commands.MenuIntersect(lhs.GetComponent<pb_Object>(), rhs.GetComponent<pb_Object>());
					break;

				case BooleanOp.Subtraction:
					pb_Menu_Commands.MenuSubtract(lhs.GetComponent<pb_Object>(), rhs.GetComponent<pb_Object>());
					break;
			}
		}
	}
Ejemplo n.º 12
0
 public WhereClause(string clause, BooleanOp booleanOp, string parameterName, object parameterValue)
 {
     m_clause = clause;
     m_booleanOp = booleanOp;
     m_parameterName = parameterName;
     m_parameterValue = parameterValue;
 }
Ejemplo n.º 13
0
        void OnGUI()
        {
            DoContextMenu();

            Event e = Event.current;

            screen.x = (int)position.width;
            screen.y = (int)position.height;

            // Since image wells eat mouse clicks, listen for a mouse up when hovering over 'reverse operation order' button
            switch (e.type)
            {
            case EventType.MouseDown:
                if (m_ReverseOperationOrderRect.Contains(e.mousePosition))
                {
                    mouseClickedSwapRect = true;
                    e.Use();
                }
                break;

            case EventType.MouseUp:
                if (mouseClickedSwapRect && m_ReverseOperationOrderRect.Contains(Event.current.mousePosition))
                {
                    ReverseOperationOrder();
                    e.Use();
                }
                mouseClickedSwapRect = false;
                break;

            case EventType.Ignore:
                mouseClickedSwapRect = false;
                break;
            }

            DrawPreviewWells();

            if (ListenForDragAndDrop())
            {
                return;
            }

            GUILayout.BeginHorizontal();
            ProBuilderMesh lpb = m_LeftGameObject != null?m_LeftGameObject.GetComponent <ProBuilderMesh>() : null;

            ProBuilderMesh rpb = m_RightGameObject != null?m_RightGameObject.GetComponent <ProBuilderMesh>() : null;

            EditorGUI.BeginChangeCheck();

            lpb = (ProBuilderMesh)EditorGUILayout.ObjectField(lpb, typeof(ProBuilderMesh), true);
            rpb = (ProBuilderMesh)EditorGUILayout.ObjectField(rpb, typeof(ProBuilderMesh), true);

            if (EditorGUI.EndChangeCheck())
            {
                DestroyImmediate(m_LeftPreviewEditor);
                DestroyImmediate(m_RightPreviewEditor);
            }

            m_LeftGameObject  = lpb != null ? lpb.gameObject : null;
            m_RightGameObject = rpb != null ? rpb.gameObject : null;
            GUILayout.EndHorizontal();

            // Boolean controls
            GUILayout.Space(4);

            GUI.backgroundColor = PreferenceKeys.proBuilderDarkGray;
            UI.EditorGUIUtility.DrawSeparator(2);
            GUI.backgroundColor = Color.white;

            operation = (BooleanOp)EditorGUILayout.EnumPopup("Operation", operation);

            if (GUILayout.Button("Apply"))
            {
                switch (operation)
                {
                case BooleanOp.Union:
                    MenuUnion(m_LeftGameObject.GetComponent <ProBuilderMesh>(), m_RightGameObject.GetComponent <ProBuilderMesh>());
                    break;

                case BooleanOp.Intersection:
                    MenuIntersect(m_LeftGameObject.GetComponent <ProBuilderMesh>(), m_RightGameObject.GetComponent <ProBuilderMesh>());
                    break;

                case BooleanOp.Subtraction:
                    MenuSubtract(m_LeftGameObject.GetComponent <ProBuilderMesh>(), m_RightGameObject.GetComponent <ProBuilderMesh>());
                    break;
                }
            }
        }
Ejemplo n.º 14
0
 internal static BooleanOp OppositeMode(BooleanOp mode)
 {
     return(mode == BooleanOp.And ? BooleanOp.Or : BooleanOp.And);
 }
Ejemplo n.º 15
0
 public MaskTest(UInt64 flags, BooleanOp mode = BooleanOp.And)
     : this(flags, flags, mode)
 {
 }
Ejemplo n.º 16
0
 public MaskTest(UInt64 flags, UInt64 mask, BooleanOp mode = BooleanOp.And)
 {
     this.Flags = flags;
     this.Mask  = mask;
     this.Mode  = mode;
 }
Ejemplo n.º 17
0
 public CompoundTest(IEnumerable <IFlagTest> tests, BooleanOp mode = BooleanOp.And)
 {
     this.tests = tests.ToArray();
     this.mode  = mode;
 }