B-spline curve container.
| 136 | |
| 137 | |
| 138 | class Curve(NamedTuple): |
| 139 | """ |
| 140 | B-spline curve container. |
| 141 | """ |
| 142 | |
| 143 | pts: Array |
| 144 | knots: Array |
| 145 | order: int |
| 146 | periodic: bool |
| 147 | |
| 148 | def curve(self) -> Geom_BSplineCurve: |
| 149 | |
| 150 | if self.periodic: |
| 151 | mults = _colIntArray(np.ones_like(self.knots, dtype=int)) |
| 152 | knots = _colRealArray(self.knots) |
| 153 | else: |
| 154 | unique_knots, mults_arr = np.unique(self.knots, return_counts=True) |
| 155 | knots = _colRealArray(unique_knots) |
| 156 | mults = _colIntArray(mults_arr) |
| 157 | |
| 158 | return Geom_BSplineCurve( |
| 159 | _colPtsArray(self.pts), knots, mults, self.order, self.periodic, |
| 160 | ) |
| 161 | |
| 162 | def edge(self) -> Edge: |
| 163 | |
| 164 | return Edge(BRepBuilderAPI_MakeEdge(self.curve()).Shape()) |
| 165 | |
| 166 | @classmethod |
| 167 | def fromEdge(cls, e: Edge): |
| 168 | |
| 169 | assert ( |
| 170 | e.geomType() == "BSPLINE" |
| 171 | ), "B-spline geometry required, try converting first." |
| 172 | |
| 173 | g = e._geomAdaptor().BSpline() |
| 174 | |
| 175 | knots = np.repeat(list(g.Knots()), list(g.Multiplicities())) |
| 176 | pts = np.array([(p.X(), p.Y(), p.Z()) for p in g.Poles()]) |
| 177 | order = g.Degree() |
| 178 | periodic = g.IsPeriodic() |
| 179 | |
| 180 | return cls(pts, knots, order, periodic) |
| 181 | |
| 182 | def __call__(self, us: Array) -> Array: |
| 183 | |
| 184 | return nbCurve( |
| 185 | np.atleast_1d(us), self.order, self.knots, self.pts, self.periodic |
| 186 | ) |
| 187 | |
| 188 | def der(self, us: NDArray, dorder: int) -> NDArray: |
| 189 | |
| 190 | return nbCurveDer( |
| 191 | np.atleast_1d(us), self.order, dorder, self.knots, self.pts, self.periodic |
| 192 | ) |
| 193 | |
| 194 | |
| 195 | class Surface(NamedTuple): |
no outgoing calls