11# -*- coding: utf-8 -*-
22
33import math
4+ from typing import List
5+
6+ from quantized_mesh_tile .exceptions import TerrainTileError
47
58from . import cartesian3d as c3d
69
710
811class BoundingSphere (object ):
9- def __init__ (self , * args , ** kwargs ):
10- MAX = float (' infinity' )
11- MIN = float (' -infinity' )
12+ def __init__ (self , * _ , ** kwargs ):
13+ MAX = float (" infinity" )
14+ MIN = float (" -infinity" )
1215
13- self .center = kwargs .get (' center' , [])
14- self .radius = kwargs .get (' radius' , 0 )
16+ self .center = kwargs .get (" center" , [])
17+ self .radius = kwargs .get (" radius" , 0 )
1518 self .minPointX = [MAX , MAX , MAX ]
1619 self .minPointY = [MAX , MAX , MAX ]
1720 self .minPointZ = [MAX , MAX , MAX ]
@@ -20,11 +23,10 @@ def __init__(self, *args, **kwargs):
2023 self .maxPointZ = [MIN , MIN , MIN ]
2124
2225 # Based on Ritter's algorithm
23- def fromPoints (self , points ):
24-
26+ def fromPoints (self , points : List ):
2527 nbPositions = len (points )
2628 if nbPositions < 2 :
27- raise Exception ( ' Your list of points must contain at least 2 points' )
29+ raise TerrainTileError ( " Your list of points must contain at least 2 points" )
2830
2931 for i in range (0 , nbPositions ):
3032 point = points [i ]
@@ -69,7 +71,7 @@ def fromPoints(self, points):
6971 ritterCenter = [
7072 (diameter1 [0 ] + diameter2 [0 ]) * 0.5 ,
7173 (diameter1 [1 ] + diameter2 [1 ]) * 0.5 ,
72- (diameter1 [2 ] + diameter2 [2 ]) * 0.5
74+ (diameter1 [2 ] + diameter2 [2 ]) * 0.5 ,
7375 ]
7476
7577 radiusSquared = c3d .magnitudeSquared (c3d .subtract (diameter2 , ritterCenter ))
@@ -99,12 +101,12 @@ def fromPoints(self, points):
99101 # Calculate center of new Ritter sphere
100102 oldToNew = oldCenterToPoint - ritterRadius
101103 ritterCenter = [
102- (ritterRadius * ritterCenter [0 ] +
103- oldToNew * currentP [ 0 ]) / oldCenterToPoint ,
104- (ritterRadius * ritterCenter [1 ] +
105- oldToNew * currentP [ 1 ]) / oldCenterToPoint ,
106- (ritterRadius * ritterCenter [2 ] +
107- oldToNew * currentP [ 2 ]) / oldCenterToPoint
104+ (ritterRadius * ritterCenter [0 ] + oldToNew * currentP [ 0 ])
105+ / oldCenterToPoint ,
106+ (ritterRadius * ritterCenter [1 ] + oldToNew * currentP [ 1 ])
107+ / oldCenterToPoint ,
108+ (ritterRadius * ritterCenter [2 ] + oldToNew * currentP [ 2 ])
109+ / oldCenterToPoint ,
108110 ]
109111
110112 # Keep the naive sphere if smaller
0 commit comments