From 8793d4a4cd2f50aa482d3e358f5c6b28ca56eedc Mon Sep 17 00:00:00 2001 From: Zach Burnett Date: Fri, 30 Dec 2022 16:13:15 -0500 Subject: [PATCH] add more attribution --- src/stcal/jump/circle.py | 33 ++++++++++++++------------------- tests/test_circle.py | 21 +-------------------- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/src/stcal/jump/circle.py b/src/stcal/jump/circle.py index 376d2ec75..18e2c096e 100644 --- a/src/stcal/jump/circle.py +++ b/src/stcal/jump/circle.py @@ -1,5 +1,3 @@ -# from https://www.nayuki.io/page/smallest-enclosing-circle - import math import random from typing import Union, Tuple, List @@ -18,6 +16,7 @@ def __init__(self, center: Tuple[float, float], radius: float): def from_points(cls, points: List[Tuple[float, float]]) -> 'Circle': """ Returns the smallest circle that encloses all the given points. + from https://www.nayuki.io/page/smallest-enclosing-circle If 0 points are given, `None` is returned. If 1 point is given, a circle of radius 0 is returned. @@ -92,6 +91,7 @@ def _expand_circle_from_one_point( ) -> Circle: """ One boundary point known + from https://www.nayuki.io/page/smallest-enclosing-circle """ circle = Circle(a, 0.0) @@ -111,6 +111,7 @@ def _expand_circle_from_two_points( ) -> Circle: """ Two boundary points known + from https://www.nayuki.io/page/smallest-enclosing-circle """ circ = Circle.from_points([a, b]) @@ -125,27 +126,15 @@ def _expand_circle_from_two_points( continue # Form a circumcircle and classify it on left or right side - cross = _cross_product(((px, py), (qx, qy), (r[0], r[1]))) + cross = _triangle_cross_product(((px, py), (qx, qy), (r[0], r[1]))) c = circumcircle(a, b, r) - cross_2 = _cross_product(((px, py), (qx, qy), (c.center[0], c.center[1]))) + cross_2 = _triangle_cross_product(((px, py), (qx, qy), (c.center[0], c.center[1]))) if c is None: continue - elif cross > 0.0 and (left is None or cross_2 > _cross_product(((px, py), (qx, qy), left.center))): + elif cross > 0.0 and (left is None or cross_2 > _triangle_cross_product(((px, py), (qx, qy), left.center))): left = c - elif cross < 0.0 and (right is None or cross_2 < _cross_product(((px, py), (qx, qy), right.center))): + elif cross < 0.0 and (right is None or cross_2 < _triangle_cross_product(((px, py), (qx, qy), right.center))): right = c - # cross = _cross_product(((px, py), (qx, qy), (r[0], r[1]))) - # c = Circle.from_points([p, q, r]) - # if c is None: - # continue - # elif cross > 0.0 and ( - # left is None or _cross_product(px, py, qx, qy, c[0], c[1]) > _cross_product(px, py, qx, qy, left[0], - # left[1])): - # left = c - # elif cross < 0.0 and ( - # right is None or _cross_product(px, py, qx, qy, c[0], c[1]) < _cross_product(px, py, qx, qy, right[0], - # right[1])): - # right = c # Select which circle to return if left is None and right is None: @@ -163,6 +152,10 @@ def circumcircle( b: Tuple[float, float], c: Tuple[float, float], ) -> Circle: + """ + from https://www.nayuki.io/page/smallest-enclosing-circle + """ + # Mathematical algorithm from Wikipedia: Circumscribed circle ox = (min(a[0], b[0], c[0]) + max(a[0], b[0], c[0])) / 2 oy = (min(a[1], b[1], c[1]) + max(a[1], b[1], c[1])) / 2 @@ -185,8 +178,10 @@ def circumcircle( return Circle((x, y), max(ra, rb, rc)) -def _cross_product(triangle: Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]) -> float: +def _triangle_cross_product(triangle: Tuple[Tuple[float, float], Tuple[float, float], Tuple[float, float]]) -> float: """ + from https://www.nayuki.io/page/smallest-enclosing-circle + :param triangle: three points defining a triangle :return: twice the signed area of triangle """ diff --git a/tests/test_circle.py b/tests/test_circle.py index 16615bfa8..66c01dcfa 100644 --- a/tests/test_circle.py +++ b/tests/test_circle.py @@ -1,23 +1,4 @@ -# -# Smallest enclosing circle - Test suite (Python) -# -# Copyright (c) 2017 Project Nayuki -# https://www.nayuki.io/page/smallest-enclosing-circle -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program (see COPYING.txt and COPYING.LESSER.txt). -# If not, see . -# +# from https://www.nayuki.io/page/smallest-enclosing-circle import random from typing import Tuple, List