This is a simplified rectangle library for simple tasks with 2-D rectangles.
While the library will be enhanced for further functionalities, this will not be made to
work for higher dimensions. The numeric data types for most operations are preserved to the
extent practicable. However, where there is a natural affinity for the results to be
those are given emphasis. Currently the following methods are available.
Methods for 2-D Rectangles
- Lines methods for rectangle ABCD
vlines(r)- returns line segments (AB, DC)
hlines(r)- returns line segments (AD, BC)
lines(r)- returns line segments [AB, DC, AD, BC]
olines(r)- returns line segments [AB, BC, CD, DA]
diags(r)- returns line segments [AC, BD]
union(r1, r2)- Union of two rectangles resulting in a larger rectangle.
intersect(r1, r2)- Intersection of two rectangles.
intersects(r1, r2)- If rectangle
r2intersect each other.
intersects(r, l)- If rectangle
lintersect each other.
inside(p, r)- Point
pis inside rectangle
inside(ri, ro)- Rectangle
riis fully enclosed in
cg(r)- Center of gravity of the rectangle
Shapeobject to be used in
projectX(r1, r2)- Find overlap regions when projected onto X-axis.
projectY(r1, r2)- Find overlap regions when projected onto Y-axis
visibleY(r1, r2)- Projects the rectangles along the X-axis (Y-axis) and returns a rectangle area which is completely visible from both rectangles.
has_y_overlap(r1, r2)- If rectangles have overlap along the x-direction (y-direction).
avg_min_dist(r1, r2)- Rectangles are essentially point sets. Hence, one can perceive existence of a minimum distance of one point in
r2. Similar, distance would also exist for every point in
min_dist(r1, r2)- The gap between two rectangular regions. If there is overlap along a specific direction 0 will be returned.
create_ordered_map(rects, values; dir=1, reverseMax=zero(T))- Ordered list of rectangles and associate data values.
dir=1orders the rectangles by
reverseMaxparameter provides the primary index to be sorted by reverse order. If the value of
reverseMax > zero(T)then the ranges are subtracted from the range parameters so that they are sorted in a reverse order. This is particularly useful to return values of intersect in a reverse order from top to bottom or right to left.
intersect(ordered_rect_map, rect)- Return all the values for rectangles that intersect with
insert_rect!(ordered_rect_map, rect, value)- Insert value associated with the
delete_rect!(ordered_rect_map, rect)- Delete associated value for the
rect. Returns the associated value.
vline_xsection(rect, vlines)- Given a Rectangle and a set of already sorted set of vertical lines ordered left to right, provides the indices that intersect the rectangle.
hline_xsection(rect, hlines)- Given a Rectangle and a set of a sorted set of horizontal lines ordered top to bottom, provides the indices that intersect the rectangle.
Methods for 2-D Lines
Line- Representation of a line in 2-D.
isVertical(l)- Returns if the line are horizontal or vertical
length(l)- Length of the line
reverse(l)- for a line AB returns line BA.
parallelogram_area(l, p)- The area formed by the parallelogram formed by the line and a point.
ratio(l,p)- if point
plies on line
l, then it will divide the line at a ratio
r : (1-r)otherwise
div(l, r)- the point that divides the line
r : (1-r)
intersects(l1, l2)- if line
islessfunction that can be used to sort vertical lines in ascending order (left to right).
islessfunction that can be used to sort horizonal lines in descending order (top to bottom).
Methods for Commonly Used Data Structures
Searching and sorting the data are very common with simple geometrical objects like lines
and rectangles in 2-D. Hence, simplified implementations of the following data structures
are provided here. If you are looking out for more elaborate packages you can look at
DataStructures.jl or other such advanced data structure packages. Currently, only
delete! operations are supported.
Binary Search Tree
Red and Black Tree
Pull Requests and Issues are ways to submit changes and enhancements.