Exemplo n.º 1
0
        internal virtual bool IntersecWith(double minVal, double maxVal)
        {
            foreach (BorderNumberPair pair in Endpoints)
            {
                BorderNumberPair bnp = Utility.SortEndpointOrder(pair);

                if ((bnp.coordinate1 <= minVal && bnp.coordinate2 >= minVal) ||
                    (bnp.coordinate1 <= maxVal && bnp.coordinate2 >= maxVal)
                    )
                {
                    return(true);
                }
            }


            //foreach (BorderNumberPair pair in Endpoints)
            //{
            //    if ((pair.coordinate1 <= minVal && pair.coordinate2 >= minVal) ||
            //         (pair.coordinate1 <= maxVal && pair.coordinate2 >= maxVal)
            //        )
            //    {

            //        return true;
            //    }
            //}

            return(false);
        }
Exemplo n.º 2
0
        internal static BorderNumberPair SortEndpointOrder(Model.BorderControl.BorderNumberPair ep)
        {
            BorderNumberPair ret = new BorderNumberPair();

            ret.coordinate1 = ep.coordinate1;
            if (ep.coordinate2 < ret.coordinate1)
            {
                ret.coordinate1 = ep.coordinate2;
                ret.coordinate2 = ep.coordinate1;
            }
            else
            {
                ret.coordinate2 = ep.coordinate2;
            }

            return(ret);
        }
Exemplo n.º 3
0
        //This method update the second value of the endpoint to an existing border
        private void updateCoordinates(ColoBox boxBelongTo, double mainCoordinate, double endPoint, int index)
        {
            List <Border> localBorders;

            if (IsTransformed)
            {
                localBorders = transformed_borders;
            }
            else
            {
                localBorders = borders;
            }

            Border           borderToUpdate = null;
            BorderNumberPair pair           = null;

            foreach (Border b in localBorders)
            {
                if (b.Coordinate == mainCoordinate)
                {
                    borderToUpdate = b;
                    break;
                }
            }

            if (borderToUpdate == null)
            {
                borderToUpdate = new Border();
                borderToUpdate.BoxWhichBelongTo = boxBelongTo;
                localBorders.Add(borderToUpdate);
                pair = new BorderNumberPair(index);
                borderToUpdate.Endpoints.Add(pair);
                borderToUpdate.Coordinate = mainCoordinate;
            }

            //this is the case with existing borderToUpdate, so we need to extract the last pair
            if (pair == null)
            {
                //first we looking for a pair with a null value on coordinate2
                pair = borderToUpdate.Endpoints.FirstOrDefault(e => !e.coordinate2.HasValue);

                if (pair == null)
                {
                    pair = borderToUpdate.Endpoints.FirstOrDefault(e => e.coordinate1 == endPoint || e.coordinate2 == endPoint);
                }

                //checking if this pair is full, if it is, create a new pair
                if (pair == null)
                {
                    pair = new BorderNumberPair(index);
                    borderToUpdate.Endpoints.Add(pair);
                }
            }

            if (!pair.coordinate1.HasValue)
            {
                pair.coordinate1 = endPoint;
            }
            else if (!pair.coordinate2.HasValue)
            {
                pair.coordinate2 = endPoint;
            }
            else
            {
                BorderNumberPair newPair = new BorderNumberPair(index);
                newPair.coordinate1 = endPoint;
                borderToUpdate.Endpoints.Add(newPair);
            }
        }