FastLine is a Python module for performing geometric line operations. Implemented in C++ and bound to Python, it is optimized for speed, making it suitable for projects that require numerous line calculations.
You can install FastLine using pip:
pip install FastLineAlternatively, install it directly from the source repository:
git clone https://github.com/MrGolden1/FastLine.git
cd FastLine
pip install .Import the Line class from the FastLine module and create line instances using either two points or slope-intercept form.
from FastLine import Line
# Define a line by two points
line1 = Line(p1=(0, 0), p2=(10, 10))
# Define a line by its slope and intercept
line2 = Line(m=4, b=-1)Calculates the corresponding y for a given x or x for a given y.
>>> line1.solve(x=20)
20.0
>>> line2.solve(y=20)
5.25Computes the shortest distance from a given point to the line.
>>> line1.distance_to((20, 50))
21.213203435596427
>>> line2.distance_to((-15, 17))
18.91777875283397Determines the side of the line on which a point lies. Returns -1, 0, or 1 indicating the opposite side, on the line, or a specific side, respectively. You will need to define the orientation of each side based on your application's context.
>>> line1.crossed_by((20, 50)) # Specific side
1
>>> line1.crossed_by((50, 50)) # On the line
0
>>> line1.crossed_by((-20, -50)) # Opposite side
-1Finds the intersection point with another line. Returns None if the lines are parallel.
>>> line1.intersection(line2)
(0.3333333333333333, 0.3333333333333333)M. Ali Zarrinzadeh
- Email: ali.zarrinzadeh@gmail.com
FastLine has been benchmarked against pure Python, NumPy, and Numba implementations to evaluate its performance in checking intersections between M and N line segments.
-
Install Dependencies:
Ensure you have the necessary dependencies installed:
pip install numpy numba
-
Execute the Benchmark Script:
Run the benchmark script to compare performance:
python benchmark.py
The following table summarizes the benchmark results comparing FastLine with pure Python, NumPy, and Numba implementations:
| Implementation | Time (seconds) |
|---|---|
| FastLine | 0.1523 |
| Pure Python | 0.4266 |
| NumPy (Non-Vectorized) | 2.8718 |
| Numba | 0.6909 |
For any questions or contributions, feel free to contact the author or submit an issue on the GitHub repository.