Skip to content

MrGolden1/FastLine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastLine

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.

Installation

You can install FastLine using pip:

pip install FastLine

Alternatively, install it directly from the source repository:

git clone https://github.com/MrGolden1/FastLine.git
cd FastLine
pip install .

Usage

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)

Methods

solve

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.25

distance_to

Computes the shortest distance from a given point to the line.

>>> line1.distance_to((20, 50))
21.213203435596427

>>> line2.distance_to((-15, 17))
18.91777875283397

crossed_by

Determines 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
-1

intersection

Finds the intersection point with another line. Returns None if the lines are parallel.

>>> line1.intersection(line2)
(0.3333333333333333, 0.3333333333333333)

Acknowledgements

Author

M. Ali Zarrinzadeh

Speed Benchmarks

FastLine has been benchmarked against pure Python, NumPy, and Numba implementations to evaluate its performance in checking intersections between M and N line segments.

Running the Benchmarks

  1. Install Dependencies:

    Ensure you have the necessary dependencies installed:

    pip install numpy numba
  2. Execute the Benchmark Script:

    Run the benchmark script to compare performance:

    python benchmark.py

Benchmark Results

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.

About

Python module for geometric Line operations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published