This package is used to generates x, y coordinate pairs for basic shapes:
Line.vertical,Line.horizontalRectangleTriangleCircleTrapezoidSegment
Note: Structural validation of input specifications is done before generating the coordinates.
This package also contains a set of utility functions that make working with shapes easier. Utilities include:
get.width: Get the width of a shape.get.height: Get the height of a shape.translate: Translate a shape by using an offset.translate.x: Translate a shape along the x-axis.translate.y: Translate a shape along the y-axis.shrink.height: Shrink a shape height by an amount.join: Join two shapes together.
This package is not available on CRAN. Use devtools to either install from GitHub or build from source and install locally.
- Use the following command to install the package from GitHub:
devtools::install_github("https://github.com/FlippieCoetser/Shapes")- Clone the repository to your local machine.
git clone https://github.com/FlippieCoetser/Shapes.git-
Navigate to the directory where the repository was cloned.
-
Build the package.
devtools::build()- Install
.tar.gzfile.
install.packages("path_to_file/tar_gz_file", repos = NULL, type = "source")There are two ways to load the package: using the library function or the package namespace.
- Using the
libraryfunction.
library(Shapes)
generate <- Generator()
validate <- Validator()- Using the package namespace.
generate <- Shapes::Generator()
validate <- Shapes::Validator()Generate Shape Coordinates for the following shapes:
- Line (vertical and horizontal)
specifications <- list()
specifications[['length']] <- 1
line <- specifications |> generate[['Line.horizontal']]()- Rectangle
specifications <- list()
specifications[['width']] <- 1
specifications[['height']] <- 0.5
rectangle <- specifications |> generate[['Rectangle']]()- Triangle
specifications <- list()
specifications[['base']] <- 1
specifications[['height']] <- 1.5
triangle <- specifications |> generate[['Triangle']]()- Circle
specifications <- list()
specifications[['radius']] <- 1
circle <- specifications |> generate[['Circle']]()- Trapezoid
specifications <- list()
specifications[['bottom']] <- 1
specifications[['top']] <- 0.5
specifications[['height']] <- 1
trapezoid <- specifications |> generate[['Trapezoid']]()- Segment
specifications <- list()
specifications[['radius']] <- 1
segment <- specifications |> generate[['Segment']]()Note: An optional align parameter can be passed to the generator function.
The align parameter can be one of the following:
corner: The Left Bottom Corner of shapes will be at the origin (0,0) and also the default valuecenter: The center of shapes will be at the origin (0,0)horizontal: The shapes will be centred horizontally with the bottom at y = 0vertical: The shapes will be centred vertically with the left side at x = 0
Generate Shape Coordinates for the following shapes:
- Centered Aligned Rectangle
specifications <- list()
specifications[['width']] <- 1
specifications[['height']] <- 0.5
rectangle <- specifications |> generate[['Rectangle']](align = 'center')Validate specifications of shapes and throw exception with meaningful message, for example:
- Define a specification with missing parameters.
specifications <- list()
specifications[['width']] <- 1- Validate the specifications.
specifications |> validate[['Rectangle']]()- The following exception will be thrown:
"Error: Attribute.NULL: 'height' does not exist."