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 Float
those are given emphasis. Currently the following methods are available.
w(r)
- Widthh(r)
- Heightarea(r)
- Areaperimeter(r)
- Perimeter- 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 rectangler1
andr2
intersect each other.intersects(r, l)
- If rectangler
and linel
intersect each other.inside(p, r)
- Pointp
is inside rectangler
inside(ri, ro)
- Rectangleri
is fully enclosed inro
cg(r)
- Center of gravity of the rectangler
to_plot_shape(r)
-Shape
object to be used inPlots
library.projectX(r1, r2)
- Find overlap regions when projected onto X-axis.projectY(r1, r2)
- Find overlap regions when projected onto Y-axisvisibleX(r1, r2)
,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_x_overlap(r1, r2)
,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 inr1
fromr2
. Similar, distance would also exist for every point inr2
fromr1
.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=1
orders the rectangles byx-axis
first and2
byy-axis
.reverseMax
parameter provides the primary index to be sorted by reverse order. If the value ofreverseMax > 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 withrect
.insert_rect!(ordered_rect_map, rect, value)
- Insert value associated with therect
.delete_rect!(ordered_rect_map, rect)
- Delete associated value for therect
. 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.
Line
- Representation of a line in 2-D.isHorizontal(l)
,isVertical(l)
- Returns if the line are horizontal or verticallength(l)
- Length of the linereverse(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 pointp
lies on linel
, then it will divide the line at a ratior : (1-r)
otherwisenothing
div(l, r)
- the point that divides the linel
at ratior : (1-r)
intersects(l1, l2)
- if linel1
intersectsl2
.vert_asc(l1, l2)
-isless
function that can be used to sort vertical lines in ascending order (left to right).horiz_desc(l1, l2)
-isless
function that can be used to sort horizonal lines in descending order (top to bottom).
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
insert!
and delete!
operations are supported.
Pull Requests and Issues are ways to submit changes and enhancements.