Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Nov 12, 2024
1 parent 9594a4b commit 8fd47d0
Show file tree
Hide file tree
Showing 41 changed files with 610 additions and 615 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**

!/docs/requirements.txt
!/requirements.txt
15 changes: 0 additions & 15 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Linux

on: [push, pull_request]

jobs:
deploy:
runs-on: ubuntu-24.04
strategy:
matrix:
python:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
- 'pypy3.10'

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{matrix.python}}
cache: 'pip'
cache-dependency-path: requirements.txt

- name: Setup Dependencies
run: |
pip install --verbose --editable .
- name: Test
run: |
coverage run -m pytest --junit-xml=report.xml
- name: Generate Coverage
run: |
coverage report
coverage xml
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
fail_ci_if_error: true
verbose: true
35 changes: 35 additions & 0 deletions .github/workflows/wheels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Publish to PyPI

on:
schedule:
- cron: '42 1 * * *'
push:
# release:
# types: [published]

jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: PyPI
url: https://pypi.org/p/conics
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.13'

- name: Setup Dependencies
run: |
pip install build
- name: Build
run: python -m build

- name: Publish
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
*.orig
*.py[cod]
/.coverage
/.env/
/dist/
/docs/_build/
/docs/references.bib.blg
__pycache__/
14 changes: 14 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2

build:
os: ubuntu-24.04
tools:
python: "3.12"

sphinx:
configuration: docs/conf.py
fail_on_warning: true

python:
install:
- requirements: requirements.txt
12 changes: 12 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cff-version: 1.2.0
message: If you use conics in your work, please reference it as below.
title: conics
abstract: Library for managing conic sections
authors:
- family-names: Deitsch
given-names: Sergiu
orcid: https://orcid.org/0000-0001-8865-8066
version: 0.1.0
date-released: 2019-05-21
license: Apache-2.0
repository-code: https://github.com/sergiud/conics
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Conics

[![codecov](https://codecov.io/gh/sergiud/conics/graph/badge.svg?token=89OIQDFWHV)](https://codecov.io/gh/sergiud/conics)
[![Documentation Status](https://readthedocs.org/projects/conics/badge/?version=latest)](https://conics.readthedocs.io/en/latest/?badge=latest)


.. image:: https://pyup.io/repos/github/sergiud/conics/shield.svg
:target: https://pyup.io/repos/github/sergiud/conics/
:alt: Updates

Conics is a library for managing conic sections (or simply *conics*).

## Features

* Creation of conics
* Transformation
* Computing intersections of conics
* 5-D pose estimation of the supporting plane of an ellipse

## License

The library is provided under the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
36 changes: 0 additions & 36 deletions README.rst

This file was deleted.

5 changes: 5 additions & 0 deletions conics/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024-present Sergiu Deitsch <sergiu.deitsch@gmail.com>
#
# SPDX-License-Identifier: Apache-2.0

__version__ = "0.1.0a1.dev1"
27 changes: 16 additions & 11 deletions conics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Top-level package for Conics."""
__author__ = 'Sergiu Deitsch'

__author__ = """Sergiu Deitsch"""
__email__ = 'sergiu.deitsch@gmail.com'
__version__ = '0.1.0'
from ._conic import concentric_conics_vanishing_line
from ._conic import Conic
from ._conic import estimate_pose
from ._conic import projected_center
from ._conic import surface_normal
from ._ellipse import Ellipse
from ._parabola import Parabola

from ._conic import concentric_conics_vanishing_line # noqa: F401
from ._conic import Conic # noqa: F401
from ._conic import estimate_pose # noqa: F401
from ._conic import projected_center # noqa: F401
from ._conic import surface_normal # noqa: F401
from ._ellipse import Ellipse # noqa: F401
from ._parabola import Parabola # noqa: F401
__all__ = ('concentric_conics_vanishing_line',
'Conic',
'estimate_pose',
'projected_center',
'surface_normal',
'Ellipse',
'Parabola',
)
102 changes: 1 addition & 101 deletions conics/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from ._conic import Conic
from ._harker import fit_harker # noqa: F401
from ._nievergelt import fit_nievergelt
from ._nievergelt import fit_nievergelt # noqa: F401
from .geometry import hnormalized
from .geometry import line_intersection
from .geometry import line_through
Expand Down Expand Up @@ -102,103 +102,3 @@ def parabola_to_bezier(parabola, start, end):
inter = hnormalized(inter)

return np.column_stack((s1, inter, s2))


if __name__ == '__main__':
from . import Parabola
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt

x = [-7, -3, 0, 0, 1, 1]
y = [9, 5, 4, 8, 3, 5]

# x = [-6.6, -2.8, -0.2, 0.4, 1.2, 1.4]
# y = [8.8, 5.4, 3.6, 7.8, 3.4, 4.8]

y = [-2, -0.1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
x = [1, 0.5, 0.1, 0, 0, 0, 0.2, 0.3, 0.4, 0.5, 0.6]

# x = [-1, 2, 5, 10, -4]
# y = [1, -2, 3, -4, -3]

x = [-1.1, 0, 0, 0, -0.5]
y = [0, 1, 2, 3, 4]

# x = np.array([-4, -2, -1, 0, 1, 2, 4])
# y = 2*x**2+1*x+5 # +0.25*x**2+0
# y = np.array([-4, -2, -1, 0, 1, 2, 4])
# x = -2 * y**2 - 0.5 # +0.25*x**2+0
# x = [1, 0, 3, 4, 5]
# y = [3, -1, 10, 50, 100]

# x = [-34.75, -22, -15.5, -8.0, -4, -1.0, 1.5, 4.5, 9.25, 17, 23.5, 36, 64.5]
# y = [20.25, 17, 15.0, 13.5, 13, 12.5, 12.5, 13.0, 14.00, 16, 18.0, 21, 29.5]

pts = np.vstack((x, y)).astype(np.float)
# pts[1] *= 1e-2
# C = fit_nievergelt(pts, type='hyperbola')
C = fit_nievergelt(pts, type='parabola', scale=True)

C = C.constrain(pts, fix_angle=np.pi / 4)

vertex, p, alpha = C.to_parabola()
pb = Parabola(vertex, p, alpha)
pb1 = pb.refine(pts)

C = pb1.to_conic()
vertex, p, alpha = C.to_parabola()

# plt.figure()
# plt.axis('equal')

# R = rot2d(alpha)
# x = np.linspace(-10, 10)
# y2 = 2*p*x
# y = np.sqrt(y2)

# x, y = R @ np.vstack((x, y)) + vertex[..., np.newaxis]
# plt.plot(x, y)

# plt.show()

plt.figure()
plt.axis('equal')

x, y = pts

X, Y = np.meshgrid(np.linspace(np.min(x) - 1, np.max(x) + 1),
np.linspace(-1 + np.min(y), np.max(y) + 1))
Z = C(np.vstack((X.ravel(), Y.ravel())))

plt.contour(X, Y, Z.reshape(X.shape), levels=0)
plt.scatter(x, y)
plt.scatter(*vertex)

pb = Parabola(vertex, p, alpha)

s1, inter, s2 = parabola_to_bezier(pb, *pts[:, [0, -1]].T).T

pp1 = np.column_stack((s1, inter))
pp2 = np.column_stack((s2, inter))

plt.plot(pp1[0], pp1[1])
plt.plot(pp2[0], pp2[1])

path = mpatches.Path(np.vstack((s1.T, inter, s2.T)), [mpatches.Path.MOVETO,
mpatches.Path.CURVE3, mpatches.Path.CURVE3])
pp = mpatches.PathPatch(
path,
linestyle='--',
edgecolor='blue',
facecolor='none',
lw=3)

plt.gca().add_artist(pp)

plt.scatter(*inter)
plt.scatter(*np.column_stack((s1, s2)))

print(C(s1))
print(C(s2))

plt.show()
1 change: 0 additions & 1 deletion docs/authors.rst

This file was deleted.

5 changes: 5 additions & 0 deletions docs/bibliography.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Further Reading
===============

.. bibliography:: references.bib
:style: alpha
Loading

0 comments on commit 8fd47d0

Please sign in to comment.