Skip to main content

README

This project enables the creation of different geometric objects, on which we can perform different operations, like calculation of their perimeter.

Features

  • Create and visualise various geometric objects: Triangle, Rectangle, Polygon, Circle and Ellipse
  • Calculate their perimeter and their area
  • Check if two objects intersect
  • Save and load geometric objects to and from JSON files

Installation

Download the project with pip install SimpleShape and then call it in your python document with from SimpleShape import SimpleShape. Alternatively, download and expand the .zip (.tar.gz) file and insert the SimpleShape.py function, located in the SimpleShape subfolder, to location of your python document and then write import SimpleShape in it.

1. Instructions

To start using this project, create the Geometric object with available classes and perform different methods (see section 1.1). You can also check example.py, located in the SimpleShape subfolder, for a quick overwiev on how to use this package.

This package also provides various functions that are described in section 1.2.

1.1 Geometric Classes and Methods

Class Geometry(coordinates):

Parent class for creating geometric objects. Here, coordinates is 2-D array of arrays that represent points in x-y plane (one example being coordinates = [(0,0), (2,0), (4,4), (0,4)]). In case of Ellipse and Circle, different parameters are inserted (see below), for example the coordinates of their center.

Parent class has following methods:
  • __init__(self, coordinates): Initialization method for the object.
  • __str__(self) -> str: String representation of the object, obtained using print(object)
  • perimeter(self) -> float: Returns the perimeter of the geometric object
  • area(self) -> float: Returns the area of the geometric object
  • intersect(self, other) -> bool: Check if two objects intersect. Note that tangency also counts as intersection
  • visualize(self): Visualize the object using matplotlib module

Aside from these methods, there are various functions to convert geometric objects to and from JSON format. See section 1.2 for more details.

Class Triangle(coordinates):

A class for creating triangles using three points (f.e. coordinates = [(0,0), (2,0), (4,4)]).

Class Rectangle(coordinates):

A class for creating rectangles using four points that need to be inserted in clockwise or counter-clockwise order.

Class Polygon(coordinates):

A class for creating polygons using three or more points that need to be inserted in fixed order. If the polygon is self-intersecting, the .area() method does not return correct values.

Class Circle(r, center = (0, 0)):

A class for creating circles. Here, r is radius (r > 0) and center (default value (0,0)) represents center of the circle on x-y plane.

Class Ellipse(width, height, f = 0, center = (0, 0)):

A class for creating ellipses. Here, width is width of the ellipse, height is its height (width, height > 0), f is the rotation in counter-clockwise direction (in degrees, default value 0) and center represents center of ellipse on x-y plane (default value (0,0)).

1.2 Functions

This package contains functions for working with JSON data as well as other functions that perform different operations on geometric objects.

JSON functions:
  • to_json(object_list): Convert the list of objects to JSON string using object attributes
  • save_shapes(json_data, filename): Write JSON string to a .json file
  • load_shapes(filename): Create JSON string from a .json file
  • from_json(json_data): Create a list of objects from a JSON string
Other functions:
  • random_shape(shape): Create a geometric object of random dimensions. If the shape parameter is not specified, an arbitrary geometric object will be returned. Otherwise, insert one of the following as an argument: "Rectangle", "Triangle", "Circle", "Ellipse", "Polygon".
  • rotate(P1, P2, f): Rotate point P1 (x1,y1) around point P2 (x2,y2) for angle f in radians.
  • line_intersect(A,B,C,D): Check if two line segments (AB and CD, where each capital letter represents a point (x, y) on x-y plane) intersect
  • parallel(A,B,C,D): Check if two line segments (AB and CD, where each capital letter represents a point (x, y) on x-y plane) are parallel
  • line_intersect_circle(A, B, c, r): Check if line segment AB intersect a circle with radius r > 0 and central point c (x, y).

Note: Tangency also counts as intersection!

Metadata

Release files for SimpleShape 1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for SimpleShape 1.5
File Size Uploaded Provenance Actions
SimpleShape-1.5.tar.gz 8.0 kB Without provenance Details for SimpleShape-1.5.tar.gz

Release files / SimpleShape-1.5.tar.gz

Download URL SimpleShape-1.5.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
acb38f4a05a28ae4449576baee478b25a9c74e80561d00cb0718b1107fa1bf0d
BLAKE2b-256 checksum
How to use checksums
090664d0eea9adfb01e92212f664cebbf13306caffb6bb03b72a7ed40e11c5b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for SimpleShape 1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page