コード例 #1
0
ファイル: Shape.cs プロジェクト: Oleg-Avdeev/EmojiSearch-Fork
        public override bool Equals(object p_obj)
        {
            var v_complexShape = p_obj as ComplexShape;

            if (v_complexShape == null || v_complexShape.IsEmpty())
            {
                return(IsEmpty());
            }
            else if (Shapes.Count == v_complexShape.Shapes.Count && RectBounds.Equals(v_complexShape.RectBounds))
            {
                Shapes.RemoveNulls();
                List <PolygonShape> v_shapesToCheck = new List <PolygonShape>(v_complexShape.Shapes);
                v_shapesToCheck.RemoveNulls();
                foreach (var v_shape in Shapes)
                {
                    bool v_hasEqual = false;
                    for (int i = 0; i < v_shapesToCheck.Count; i++)
                    {
                        if (v_shape.Equals(v_shapesToCheck[i]))
                        {
                            v_hasEqual = true;
                            v_shapesToCheck.RemoveAt(i);
                            break;
                        }
                    }
                    if (!v_hasEqual)
                    {
                        break;
                    }
                }
                //If we removed all checked shapes, it means that both shapes are equal
                return(v_shapesToCheck.Count == 0);
            }
            return(false);
        }
コード例 #2
0
ファイル: Shape.cs プロジェクト: Oleg-Avdeev/EmojiSearch-Fork
        public override bool Equals(object p_obj)
        {
            var v_polygonShape = p_obj as PolygonShape;

            if (p_obj == this)
            {
                return(true);
            }
            else if (v_polygonShape == null || v_polygonShape.IsEmpty())
            {
                return(IsEmpty());
            }
            else if (v_polygonShape.Vertices.Count == Vertices.Count && RectBounds.Equals(v_polygonShape.RectBounds))
            {
                var v_firstSelfVertice         = Vertices[0];
                var v_verticeIndexInOtherShape = v_polygonShape.Vertices.IndexOf(v_firstSelfVertice);
                if (v_verticeIndexInOtherShape < 0)
                {
                    return(false);
                }
                else
                {
                    var v_sucess = true;
                    for (int i = 0; i < Vertices.Count; i++)
                    {
                        var v_currentVertice    = Vertices[i];
                        var v_otherVerticeIndex = i + v_verticeIndexInOtherShape;
                        if (v_otherVerticeIndex >= v_polygonShape.Vertices.Count)
                        {
                            v_otherVerticeIndex -= v_polygonShape.Vertices.Count;
                        }
                        var v_otherVertice = v_polygonShape.Vertices[v_otherVerticeIndex];
                        if (v_currentVertice != v_otherVertice)
                        {
                            v_sucess = false;
                            break;
                        }
                    }
                    return(v_sucess);
                }
            }
            return(false);
        }