Skip to content

Commit 8793d4a

Browse files
add more attribution
1 parent 1620ebd commit 8793d4a

File tree

2 files changed

+15
-39
lines changed

2 files changed

+15
-39
lines changed

src/stcal/jump/circle.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# from https://www.nayuki.io/page/smallest-enclosing-circle
2-
31
import math
42
import random
53
from typing import Union, Tuple, List
@@ -18,6 +16,7 @@ def __init__(self, center: Tuple[float, float], radius: float):
1816
def from_points(cls, points: List[Tuple[float, float]]) -> 'Circle':
1917
"""
2018
Returns the smallest circle that encloses all the given points.
19+
from https://www.nayuki.io/page/smallest-enclosing-circle
2120
2221
If 0 points are given, `None` is returned.
2322
If 1 point is given, a circle of radius 0 is returned.
@@ -92,6 +91,7 @@ def _expand_circle_from_one_point(
9291
) -> Circle:
9392
"""
9493
One boundary point known
94+
from https://www.nayuki.io/page/smallest-enclosing-circle
9595
"""
9696

9797
circle = Circle(a, 0.0)
@@ -111,6 +111,7 @@ def _expand_circle_from_two_points(
111111
) -> Circle:
112112
"""
113113
Two boundary points known
114+
from https://www.nayuki.io/page/smallest-enclosing-circle
114115
"""
115116

116117
circ = Circle.from_points([a, b])
@@ -125,27 +126,15 @@ def _expand_circle_from_two_points(
125126
continue
126127

127128
# Form a circumcircle and classify it on left or right side
128-
cross = _cross_product(((px, py), (qx, qy), (r[0], r[1])))
129+
cross = _triangle_cross_product(((px, py), (qx, qy), (r[0], r[1])))
129130
c = circumcircle(a, b, r)
130-
cross_2 = _cross_product(((px, py), (qx, qy), (c.center[0], c.center[1])))
131+
cross_2 = _triangle_cross_product(((px, py), (qx, qy), (c.center[0], c.center[1])))
131132
if c is None:
132133
continue
133-
elif cross > 0.0 and (left is None or cross_2 > _cross_product(((px, py), (qx, qy), left.center))):
134+
elif cross > 0.0 and (left is None or cross_2 > _triangle_cross_product(((px, py), (qx, qy), left.center))):
134135
left = c
135-
elif cross < 0.0 and (right is None or cross_2 < _cross_product(((px, py), (qx, qy), right.center))):
136+
elif cross < 0.0 and (right is None or cross_2 < _triangle_cross_product(((px, py), (qx, qy), right.center))):
136137
right = c
137-
# cross = _cross_product(((px, py), (qx, qy), (r[0], r[1])))
138-
# c = Circle.from_points([p, q, r])
139-
# if c is None:
140-
# continue
141-
# elif cross > 0.0 and (
142-
# left is None or _cross_product(px, py, qx, qy, c[0], c[1]) > _cross_product(px, py, qx, qy, left[0],
143-
# left[1])):
144-
# left = c
145-
# elif cross < 0.0 and (
146-
# right is None or _cross_product(px, py, qx, qy, c[0], c[1]) < _cross_product(px, py, qx, qy, right[0],
147-
# right[1])):
148-
# right = c
149138

150139
# Select which circle to return
151140
if left is None and right is None:
@@ -163,6 +152,10 @@ def circumcircle(
163152
b: Tuple[float, float],
164153
c: Tuple[float, float],
165154
) -> Circle:
155+
"""
156+
from https://www.nayuki.io/page/smallest-enclosing-circle
157+
"""
158+
166159
# Mathematical algorithm from Wikipedia: Circumscribed circle
167160
ox = (min(a[0], b[0], c[0]) + max(a[0], b[0], c[0])) / 2
168161
oy = (min(a[1], b[1], c[1]) + max(a[1], b[1], c[1])) / 2
@@ -185,8 +178,10 @@ def circumcircle(
185178
return Circle((x, y), max(ra, rb, rc))
186179

187180

188-
def _cross_product(triangle: Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]) -> float:
181+
def _triangle_cross_product(triangle: Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]) -> float:
189182
"""
183+
from https://www.nayuki.io/page/smallest-enclosing-circle
184+
190185
:param triangle: three points defining a triangle
191186
:return: twice the signed area of triangle
192187
"""

tests/test_circle.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
#
2-
# Smallest enclosing circle - Test suite (Python)
3-
#
4-
# Copyright (c) 2017 Project Nayuki
5-
# https://www.nayuki.io/page/smallest-enclosing-circle
6-
#
7-
# This program is free software: you can redistribute it and/or modify
8-
# it under the terms of the GNU Lesser General Public License as published by
9-
# the Free Software Foundation, either version 3 of the License, or
10-
# (at your option) any later version.
11-
#
12-
# This program is distributed in the hope that it will be useful,
13-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
# GNU Lesser General Public License for more details.
16-
#
17-
# You should have received a copy of the GNU Lesser General Public License
18-
# along with this program (see COPYING.txt and COPYING.LESSER.txt).
19-
# If not, see <http://www.gnu.org/licenses/>.
20-
#
1+
# from https://www.nayuki.io/page/smallest-enclosing-circle
212

223
import random
234
from typing import Tuple, List

0 commit comments

Comments
 (0)