mirror of
https://github.com/gumyr/build123d.git
synced 2026-04-25 22:32:56 -07:00
More pylint improvements
This commit is contained in:
parent
f9af5af09b
commit
2ab41e4b7c
4 changed files with 46 additions and 47 deletions
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
|
|
@ -11,4 +11,4 @@ jobs:
|
|||
python-version: 3.10
|
||||
|
||||
- name: lint
|
||||
run: pylint --rcfile=.pylintrc src/build123d
|
||||
run: pylint --rcfile=.pylintrc --fail-under=9.5 src/build123d
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import platform
|
|||
import sys
|
||||
import warnings
|
||||
from abc import ABC, abstractmethod
|
||||
from anytree import Node, RenderTree, NodeMixin, PreOrderIter
|
||||
from io import BytesIO
|
||||
from itertools import combinations
|
||||
from math import degrees, inf, pi, radians, sqrt
|
||||
|
|
@ -59,13 +58,12 @@ from typing import (
|
|||
from typing import cast as tcast
|
||||
from typing import overload
|
||||
|
||||
from anytree import NodeMixin, PreOrderIter, RenderTree
|
||||
from svgpathtools import svg2paths
|
||||
from typing_extensions import Literal
|
||||
from vtkmodules.vtkCommonDataModel import vtkPolyData
|
||||
from vtkmodules.vtkFiltersCore import vtkPolyDataNormals, vtkTriangleFilter
|
||||
|
||||
from build123d.build_enums import Align, Until
|
||||
|
||||
import OCP.GeomAbs as ga # Geometry type enum
|
||||
import OCP.IFSelect
|
||||
import OCP.TopAbs as ta # Topology type enum
|
||||
|
|
@ -255,6 +253,7 @@ from OCP.TopTools import (
|
|||
TopTools_ListOfShape,
|
||||
)
|
||||
from build123d.build_enums import (
|
||||
Align,
|
||||
AngularDirection,
|
||||
CenterOf,
|
||||
Direction,
|
||||
|
|
@ -265,6 +264,7 @@ from build123d.build_enums import (
|
|||
PositionMode,
|
||||
SortBy,
|
||||
Transition,
|
||||
Until,
|
||||
)
|
||||
|
||||
# Create a build123d logger to distinguish these logs from application logs.
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ Yue, Y., Murray, J. L., Corney, J. R., & Clark, D. E. R. (1999).
|
|||
Convex hull of a planar set of straight and circular line segments. Engineering Computations.
|
||||
|
||||
"""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
Arcs = List["Arc"]
|
||||
Points = List["Point"]
|
||||
Entity = Union["Arc", "Point"]
|
||||
|
|
@ -18,41 +18,33 @@ Hull = List[Union["Arc", "Point", "Segment"]]
|
|||
|
||||
|
||||
class Point:
|
||||
|
||||
x: float
|
||||
y: float
|
||||
|
||||
def __init__(self, x: float, y: float):
|
||||
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
return f"( {self.x},{self.y} )"
|
||||
|
||||
def __hash__(self):
|
||||
|
||||
return hash((self.x, self.y))
|
||||
|
||||
def __eq__(self, other):
|
||||
|
||||
return (self.x, self.y) == (other.x, other.y)
|
||||
|
||||
|
||||
class Segment:
|
||||
|
||||
a: Point
|
||||
b: Point
|
||||
|
||||
def __init__(self, a: Point, b: Point):
|
||||
|
||||
self.a = a
|
||||
self.b = b
|
||||
|
||||
|
||||
class Arc:
|
||||
|
||||
c: Point
|
||||
s: Point
|
||||
e: Point
|
||||
|
|
@ -62,7 +54,6 @@ class Arc:
|
|||
ac: float
|
||||
|
||||
def __init__(self, c: Point, r: float, a1: float, a2: float):
|
||||
|
||||
self.c = c
|
||||
self.r = r
|
||||
self.a1 = a1
|
||||
|
|
@ -74,7 +65,6 @@ class Arc:
|
|||
|
||||
|
||||
def atan2p(x, y):
|
||||
|
||||
rv = atan2(y, x)
|
||||
|
||||
if rv < 0:
|
||||
|
|
@ -84,7 +74,6 @@ def atan2p(x, y):
|
|||
|
||||
|
||||
def convert_and_validate(edges: Iterable[Edge]) -> Tuple[List[Arc], List[Point]]:
|
||||
|
||||
arcs: Set[Arc] = set()
|
||||
points: Set[Point] = set()
|
||||
|
||||
|
|
@ -111,7 +100,6 @@ def convert_and_validate(edges: Iterable[Edge]) -> Tuple[List[Arc], List[Point]]
|
|||
|
||||
|
||||
def select_lowest_point(points: Points) -> Tuple[Point, int]:
|
||||
|
||||
x = []
|
||||
y = []
|
||||
|
||||
|
|
@ -126,12 +114,10 @@ def select_lowest_point(points: Points) -> Tuple[Point, int]:
|
|||
|
||||
|
||||
def select_lowest_arc(arcs: Arcs) -> Tuple[Point, Arc]:
|
||||
|
||||
x = []
|
||||
y = []
|
||||
|
||||
for a in arcs:
|
||||
|
||||
if a.a1 < 1.5 * pi and a.a2 > 1.5 * pi:
|
||||
x.append(a.c.x)
|
||||
y.append(a.c.y - a.r)
|
||||
|
|
@ -146,7 +132,6 @@ def select_lowest_arc(arcs: Arcs) -> Tuple[Point, Arc]:
|
|||
|
||||
|
||||
def select_lowest(arcs: Arcs, points: Points) -> Entity:
|
||||
|
||||
rv: Entity
|
||||
|
||||
p_lowest = select_lowest_point(points) if points else None
|
||||
|
|
@ -166,7 +151,6 @@ def select_lowest(arcs: Arcs, points: Points) -> Entity:
|
|||
|
||||
|
||||
def pt_pt(p1: Point, p2: Point) -> Tuple[float, Segment]:
|
||||
|
||||
angle = 0
|
||||
|
||||
dx, dy = p2.x - p1.x, p2.y - p1.y
|
||||
|
|
@ -178,7 +162,6 @@ def pt_pt(p1: Point, p2: Point) -> Tuple[float, Segment]:
|
|||
|
||||
|
||||
def _pt_arc(p: Point, a: Arc) -> Tuple[float, float, float, float]:
|
||||
|
||||
x, y = p.x, p.y
|
||||
|
||||
r = a.r
|
||||
|
|
@ -195,7 +178,6 @@ def _pt_arc(p: Point, a: Arc) -> Tuple[float, float, float, float]:
|
|||
|
||||
|
||||
def pt_arc(p: Point, a: Arc) -> Tuple[float, Segment]:
|
||||
|
||||
x, y = p.x, p.y
|
||||
x1, y1, x2, y2 = _pt_arc(p, a)
|
||||
|
||||
|
|
@ -207,7 +189,6 @@ def pt_arc(p: Point, a: Arc) -> Tuple[float, Segment]:
|
|||
|
||||
|
||||
def arc_pt(a: Arc, p: Point) -> Tuple[float, Segment]:
|
||||
|
||||
x, y = p.x, p.y
|
||||
x1, y1, x2, y2 = _pt_arc(p, a)
|
||||
|
||||
|
|
@ -220,7 +201,6 @@ def arc_pt(a: Arc, p: Point) -> Tuple[float, Segment]:
|
|||
|
||||
|
||||
def arc_arc(a1: Arc, a2: Arc) -> Tuple[float, Segment]:
|
||||
|
||||
r1 = a1.r
|
||||
xc1, yc1 = a1.c.x, a1.c.y
|
||||
|
||||
|
|
@ -294,7 +274,6 @@ def arc_arc(a1: Arc, a2: Arc) -> Tuple[float, Segment]:
|
|||
|
||||
|
||||
def get_angle(current: Entity, e: Entity) -> Tuple[float, Segment]:
|
||||
|
||||
if current is e:
|
||||
return inf, Segment(Point(inf, inf), Point(inf, inf))
|
||||
|
||||
|
|
@ -318,7 +297,6 @@ def update_hull(
|
|||
segments: List[Segment],
|
||||
hull: Hull,
|
||||
) -> Tuple[Entity, float, bool]:
|
||||
|
||||
next_e = entities[ix]
|
||||
connecting_seg = segments[ix]
|
||||
|
||||
|
|
@ -331,11 +309,9 @@ def update_hull(
|
|||
|
||||
|
||||
def finalize_hull(hull: Hull) -> Wire:
|
||||
|
||||
rv = []
|
||||
|
||||
for el_p, el, el_n in zip(hull, hull[1:], hull[2:]):
|
||||
|
||||
if isinstance(el, Segment):
|
||||
rv.append(Edge.make_line(Vector(el.a.x, el.a.y), Vector(el.b.x, el.b.y)))
|
||||
elif (
|
||||
|
|
@ -367,7 +343,6 @@ def finalize_hull(hull: Hull) -> Wire:
|
|||
|
||||
|
||||
def find_hull(edges: Iterable[Edge]) -> Wire:
|
||||
|
||||
# initialize the hull
|
||||
rv: Hull = []
|
||||
|
||||
|
|
@ -389,7 +364,6 @@ def find_hull(edges: Iterable[Edge]) -> Wire:
|
|||
|
||||
# march around
|
||||
while not finished:
|
||||
|
||||
angles = []
|
||||
segments = []
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,28 @@
|
|||
"""
|
||||
|
||||
name: jupyter_tools.py
|
||||
|
||||
desc:
|
||||
Based on CadQuery version.
|
||||
|
||||
license:
|
||||
|
||||
Copyright 2022 Gumyr
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
"""
|
||||
# pylint: disable=no-name-in-module
|
||||
from typing import Dict, Any, List
|
||||
from json import dumps
|
||||
|
||||
|
|
@ -12,19 +37,19 @@ DEFAULT_COLOR = [1, 0.8, 0, 1]
|
|||
TEMPLATE_RENDER = """
|
||||
|
||||
function render(data, parent_element, ratio){{
|
||||
|
||||
|
||||
// Initial setup
|
||||
const renderWindow = vtk.Rendering.Core.vtkRenderWindow.newInstance();
|
||||
const renderer = vtk.Rendering.Core.vtkRenderer.newInstance({{ background: [1, 1, 1 ] }});
|
||||
renderWindow.addRenderer(renderer);
|
||||
|
||||
|
||||
// iterate over all children children
|
||||
for (var el of data){{
|
||||
for (var el of data){{
|
||||
var trans = el.position;
|
||||
var rot = el.orientation;
|
||||
var rgba = el.color;
|
||||
var shape = el.shape;
|
||||
|
||||
|
||||
// load the inline data
|
||||
var reader = vtk.IO.XML.vtkXMLPolyDataReader.newInstance();
|
||||
const textEncoder = new TextEncoder();
|
||||
|
|
@ -42,26 +67,26 @@ function render(data, parent_element, ratio){{
|
|||
// set color and position
|
||||
actor.getProperty().setColor(rgba.slice(0,3));
|
||||
actor.getProperty().setOpacity(rgba[3]);
|
||||
|
||||
|
||||
actor.rotateZ(rot[2]*180/Math.PI);
|
||||
actor.rotateY(rot[1]*180/Math.PI);
|
||||
actor.rotateX(rot[0]*180/Math.PI);
|
||||
|
||||
|
||||
actor.setPosition(trans);
|
||||
|
||||
renderer.addActor(actor);
|
||||
|
||||
}};
|
||||
|
||||
|
||||
renderer.resetCamera();
|
||||
|
||||
|
||||
const openglRenderWindow = vtk.Rendering.OpenGL.vtkRenderWindow.newInstance();
|
||||
renderWindow.addView(openglRenderWindow);
|
||||
|
||||
// Add output to the "parent element"
|
||||
var container;
|
||||
var dims;
|
||||
|
||||
|
||||
if(typeof(parent_element.appendChild) !== "undefined"){{
|
||||
container = document.createElement("div");
|
||||
parent_element.appendChild(container);
|
||||
|
|
@ -72,14 +97,14 @@ function render(data, parent_element, ratio){{
|
|||
}};
|
||||
|
||||
openglRenderWindow.setContainer(container);
|
||||
|
||||
|
||||
// handle size
|
||||
if (ratio){{
|
||||
openglRenderWindow.setSize(dims.width, dims.width*ratio);
|
||||
}}else{{
|
||||
openglRenderWindow.setSize(dims.width, dims.height);
|
||||
}};
|
||||
|
||||
|
||||
// Interaction setup
|
||||
const interact_style = vtk.Interaction.Style.vtkInteractorStyleManipulator.newInstance();
|
||||
|
||||
|
|
@ -154,19 +179,19 @@ new Promise(
|
|||
"""
|
||||
)
|
||||
|
||||
def to_vtkpoly_string(
|
||||
shape: Shape, tolerance: float = 1e-3, angularTolerance: float = 0.1
|
||||
) -> str:
|
||||
|
||||
def to_vtkpoly_string(
|
||||
shape: Shape, tolerance: float = 1e-3, angular_tolerance: float = 0.1
|
||||
) -> str:
|
||||
writer = vtkXMLPolyDataWriter()
|
||||
writer.SetWriteToOutputString(True)
|
||||
writer.SetInputData(shape.to_vtk_poly_data(tolerance, angularTolerance, True))
|
||||
writer.SetInputData(shape.to_vtk_poly_data(tolerance, angular_tolerance, True))
|
||||
writer.Write()
|
||||
|
||||
return writer.GetOutputString()
|
||||
|
||||
def display(shape):
|
||||
|
||||
def display(shape):
|
||||
payload: List[Dict[str, Any]] = []
|
||||
|
||||
if isinstance(shape, Shape):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue