public Border(RawBorder b, ColoBox box) { BoxWhichBelongTo = box; Endpoints = new List <BorderNumberPair>(); BorderNumberPair bnp = new BorderNumberPair(); BorderType = b.BorderType; Endpoints.Add(bnp); switch (b.BorderType) { case Orientation.Horizontal: Coordinate = b.Point1.Y; bnp.coordinate1 = b.Point1.X; if (b.Point2.X < b.Point1.X) { bnp.coordinate1 = b.Point2.X; bnp.coordinate2 = b.Point1.X; } else { bnp.coordinate2 = b.Point2.X; } break; case Orientation.Vertical: Coordinate = b.Point1.X; bnp.coordinate1 = b.Point1.Y; if (b.Point2.Y < b.Point1.Y) { bnp.coordinate1 = b.Point2.Y; bnp.coordinate2 = b.Point1.Y; } else { bnp.coordinate2 = b.Point2.Y; } break; default: Coordinate = 0; bnp.coordinate1 = b.Point1.X; bnp.coordinate2 = b.Point1.Y; bnp = new BorderNumberPair(); bnp.coordinate1 = b.Point2.X; bnp.coordinate2 = b.Point2.Y; Endpoints.Add(bnp); break; } }
internal static BorderNumberPair SortEndpointOrderDelMe(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); }
//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); } int indexChange = 0; if (pair != null) { indexChange = pair.index - index; } //this is a protection not to connect dots that are way far apart (incase they happen to have the same vertical or horizontal) if (indexChange < -5) { pair = null; } //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); } }