def test_offset_zero(): a = Wire(1, 2, 0.5) assert a.offset(1, 2) == approx(0)
def test_plane_height(): a = Wire(0, 2.0, 0.5) p = Plane() assert p.height_of(a) == approx(2.0)
def test_angle_to_ortho(): a = Wire(1, 0, 0.5) b = Wire(0, 1, 0.5) assert a.angle_to(b) == approx(0.5 * np.pi)
def test_offset(): a = Wire(1, 1, 0.5) assert a.offset() == approx(np.sqrt(2))
def test_gap_two_radii(): a = Wire(-1, 0, 0.5) b = Wire(1, 0, 1) assert a.gap_to(b) == approx(0.5)
def test_angle_to(): a = Wire(-1, 0, 0.5) b = Wire(1, 0, 0.5) assert a.angle_to(b) == approx(-np.pi) assert b.angle_to(a) == approx(np.pi)
def test_gap(): a = Wire(-1, 0, 0.5) b = Wire(1, 0, 0.5) assert a.gap_to(b) == approx(1)
def test_distance_diag(): a = Wire(-1, -1, 0.5) b = Wire(1, 1, 0.5) assert a.distance_to(b) == approx(np.sqrt(8))
def test_distance(): a = Wire(-1, 0, 0.5) b = Wire(1, 0, 0.5) assert a.distance_to(b) == approx(2.0)
def test_bad_ref(): with pytest.raises(TypeError): mtl.WireMtl([Wire(0, 0, 0.5)], 'Ref!')
self.ax.add_patch(shape) self.ax.autoscale_view() self.ax.set_aspect(1) def clear_shapes(self): self.ax.cla() def redraw(self): self.figure.canvas.draw() if __name__ == '__main__': class MtlCanvasFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, -1, "Mtl Canvas Frame", size=(800, 600)) self.canvas = MtlCanvas(self) app = wx.App(redirect=False) frame = MtlCanvasFrame(None) frame.canvas.add_conductor(Plane()) frame.canvas.add_conductor(Wire(0, 0, 2.5)) frame.canvas.add_conductor(Wire(-0.75, 0, 0.5)) frame.canvas.add_conductor(Wire(0.75, 0.25, 0.5)) frame.Show(True) app.MainLoop()