private RectNeighbor[] getEdgeAndOffsets(Direction direction, RectifyRectangle neighbor, out int startOffset, out int endIndex) { RectNeighbor[] myEdge; //calculate overlapping areas. e.g. for West: //if neighbor.bottom < this.bottom, start at neighbor.right[this.bottom] //if neighbor.bottom > this.bottom, start at neighbor.right[0] //if neighbor.top > this.top, end at neighbor.right[this.top] //if neighbor.top < this.top, end at neighbor.right[N] int neighborStartOffset = 0; startOffset = 0; endIndex = 0; switch (direction) { case Direction.East: //neighborEdge = neighbor.LeftEdge; myEdge = RightEdge; //start offsets if (neighbor.Bottom < this.Bottom) { neighborStartOffset = this.Bottom - neighbor.Bottom; startOffset = 0; } else if (neighbor.Bottom > this.Bottom) { neighborStartOffset = 0; startOffset = neighbor.Bottom - this.Bottom; } //end index if (neighbor.Top >= this.Top) { endIndex = this.Top - (this.Bottom + startOffset); } else if (neighbor.Top < this.Top) { endIndex = neighbor.Top - (neighbor.Bottom + neighborStartOffset); } break; case Direction.West: //neighborEdge = neighbor.RightEdge; myEdge = LeftEdge; //start offsets if (neighbor.Bottom < this.Bottom) { neighborStartOffset = this.Bottom - neighbor.Bottom; startOffset = 0; } else if (neighbor.Bottom > this.Bottom) { neighborStartOffset = 0; startOffset = neighbor.Bottom - this.Bottom; } //end index if (neighbor.Top >= this.Top) { endIndex = this.Top - (this.Bottom + startOffset); } else if (neighbor.Top < this.Top) { endIndex = neighbor.Top - (neighbor.Bottom + neighborStartOffset); } break; case Direction.South: //neighborEdge = neighbor.TopEdge; myEdge = BottomEdge; //start offsets if (neighbor.Left < this.Left) { neighborStartOffset = this.Left - neighbor.Left; startOffset = 0; } else if (neighbor.Left > this.Left) { neighborStartOffset = 0; startOffset = neighbor.Left - this.Left; } //end index if (neighbor.Right >= this.Right) { endIndex = this.Right - (this.Left + startOffset); } else if (neighbor.Right < this.Right) { endIndex = neighbor.Right - (neighbor.Left + neighborStartOffset); } break; case Direction.North: //neighborEdge = neighbor.BottomEdge; myEdge = TopEdge; //start offsets if (neighbor.Left < this.Left) { neighborStartOffset = this.Left - neighbor.Left; startOffset = 0; } else if (neighbor.Left > this.Left) { neighborStartOffset = 0; startOffset = neighbor.Left - this.Left; } //end index if (neighbor.Right >= this.Right) { endIndex = this.Right - (this.Left + startOffset); } else if (neighbor.Right < this.Right) { endIndex = neighbor.Right - (neighbor.Left + neighborStartOffset); } break; default: throw new Exception("Unknown direction for neighbors"); } return(myEdge); }
public RectNeighbor(RectifyRectangle neighbor, EdgeType edgeType) { this.Neighbor = neighbor; this.EdgeType = edgeType; }