コード例 #1
0
ファイル: test_arc.py プロジェクト: ederag/geoptics
def test_orientations():
    # left to right, arc above segment
    arc = Arc(Point(10, 20), Point(50, 30), Vector(10, 20))
    assert arc.ccw is False
    line = Line(Point(30, 10), Vector(10, 30))
    intersections = arc.intersection(line, sign_of_s=1)
    assert len(intersections) == 1

    # right to left, arc above segment
    arc = Arc(Point(50, 30), Point(10, 20), Vector(-10, 20))
    assert arc.ccw is True
    line = Line(Point(30, 10), Vector(10, 30))
    intersections = arc.intersection(line, sign_of_s=1)
    assert len(intersections) == 1

    # left to right, arc below segment
    arc = Arc(Point(10, 20), Point(50, 30), Vector(10, -20))
    assert arc.ccw is True
    line = Line(Point(30, 10), Vector(10, -30))
    intersections = arc.intersection(line, sign_of_s=1)
    assert len(intersections) == 1

    # right to left, arc below segment
    arc = Arc(Point(50, 30), Point(10, 20), Vector(-10, -20))
    assert arc.ccw is False
    line = Line(Point(30, 20), Vector(10, -30))
    intersections = arc.intersection(line, sign_of_s=1)
    assert len(intersections) == 1
コード例 #2
0
ファイル: test_create_delete.py プロジェクト: ederag/geoptics
def creation(scene, creation_type):
	if creation_type == "direct creation":
		# une region
		m1 = Point(70, 60)
		# refractive index for rp1
		n = 1.5
		rp1 = regions.Polycurve(n=n, scene=scene)
		rp1.start(m1)
		m2 = Point(70, 190)
		rp1.add_line(m2)
		m3 = Point(110, 190)
		rp1.add_line(m3)
		m4 = Point(110, 60)
		tg4 = Vector(10, -20)
		#rp1.add_line(m4)
		rp1.add_arc(m4, tg4)
		rp1.close()
		del rp1
		
		p0 = Point(10, 20)
		u0 = Vector(108, 50)
		s0 = 3
		line0 = Line(p0, u0)
		source1 = sources.SingleRay(line0=line0, s0=s0, scene=scene)
		del line0
		del source1
		gc.collect()
		# !! comment ou this line => no crash !!
		scene.propagate()
	elif creation_type == "scene.load":
		filename = 'tests/shifted_polycurves+single_ray.geoptics'
		with open(filename, 'r') as f:
			config = yaml.safe_load(stream=f)
			logger.debug("config: {}".format(config))
			scene.clear()
			scene_config = config['Scene']
			scene.config = scene_config
			#gui.scene.load(config['Scene'])
			scene.propagate()
	elif creation_type == "load individually":
		filename = 'tests/shifted_polycurves+single_ray.geoptics'
		with open(filename, 'r') as f:
			config = yaml.safe_load(stream=f)
		config_rp1 = config['Scene']['Regions'][0]
		logger.debug("config: {}".format(config_rp1))
		rp1 = regions.Polycurve.from_config(config=config_rp1, scene=scene)
		del rp1
		#gc.collect()
		#qapp.processEvents()
		config_source1 = config['Scene']['Sources'][0]
		logger.debug("{}".format(config_source1['rays'][0]))
		source1 = sources.SingleRay.from_config(  # noqa: F841
		                                        config=config_source1,
		                                        scene=scene)
		logger.debug("{}".format(scene.sources))
		del source1
		gc.collect()
		#qapp.processEvents()
		# !! comment out this line => no crash !!
		scene.propagate()
コード例 #3
0
def test_create_line_handle(scene, parent_item):
    p = Point(10, 20)
    u = Vector(30, 60)
    line0 = Line(p, u)
    # The initial position should be free, even with move restrictions on
    scene.g.move_restrictions_on = True
    lh = LineHandle(line0, parent=parent_item)
    assert lh.h_p0.pos().x() == 10
    assert lh.h_p0.pos().y() == 20
コード例 #4
0
ファイル: sources.py プロジェクト: ederag/geoptics
    def set(self,
            line_start=None,
            line_end=None,
            s_start=None,
            s_end=None,
            N_inter=None):
        """Set beam parameters.
		
		The parameters are taken from the given arguments,
		or from existing rays if the corresponding argument is missing
		
		Args: same as :class:`.Beam`, except 'scene' (for now)
		
		"""
        if line_start is None:
            line_start = self.rays[0].parts[0].line
        if line_end is None:
            line_end = self.rays[-1].parts[0].line
        if s_start is None:
            s_start = self.rays[0].parts[0].s
        if s_end is None:
            s_end = self.rays[-1].parts[0].s
        if N_inter is None:
            self.N_inter = len(self.rays) - 2
        else:
            self.N_inter = N_inter

        N_total = self.N_inter + 2
        if N_total > len(self.rays):
            # need more rays
            N_add = N_total - len(self.rays)
            last_ray = self.rays.pop()
            new_rays = [self.ray_class(source=self) for _ in range(N_add)]
            self.rays.extend(new_rays)
            # keep the last ray at the end
            self.rays.append(last_ray)
        elif N_total < len(self.rays):
            N_remove = len(self.rays) - N_total
            # do not remove the last one
            del self.rays[(-1 - N_remove):-1]

        for i in range(N_total):
            x = i / (N_total - 1)
            # FIXME: line_start and line_end are the same for all x;
            #        a lot of calculations are made several times for nothing
            #        in Line.interpolate
            #        => it should be possible to pass a list instead
            #        or even better, a generator ?
            new_line_0 = Line.interpolate(line_start, line_end, x)
            self.rays[i].change_line_0(new_line_0)
            self.rays[i].change_s(0, (1 - x) * s_start + x * s_end)
コード例 #5
0
ファイル: regions.py プロジェクト: ederag/geoptics
    def contains(self, point=None, u=None, line=None):  # noqa: D400
        """Is a given point contained in this region ?
		
		Alternatively, `line` can be given,
		in which case `point` is taken from `line.p`,
		and `u` from `line.u`.
		
		Args:
			point (Point): The point of interest
			u (Vector): Searching direction
			line (Line):
				Contains both point and searching direction (see above)
		
		"""
        if line is None:
            line = Line(p=point, u=u)
        intersections = self.intersection(line, sign_of_s=1)
        if len(intersections) % 2:
            # odd number of intersections with the region
            # point is inside it
            return True
        else:
            return False
コード例 #6
0
ファイル: test_line.py プロジェクト: ederag/geoptics
def line():
    """Return a generic Line."""
    p = Point(10, 20)
    u = Vector(30, 60)
    return Line(p, u)
コード例 #7
0
ファイル: opl-tilt.py プロジェクト: ybnd/opl-tilt
    rp1.start(m1)
    m2 = Point(70, 190)
    rp1.add_line(m2)
    m3 = Point(110, 190)
    rp1.add_line(m3)
    m4 = Point(110, 60)
    tg4 = Vector(10, -20)
    rp1.add_arc(m4, tg4)
    rp1.close()

    # tracé d'un rayon
    p0 = Point(10, 50)
    u0 = Vector(108, 0)
    s0 = 3
    n0 = 1.0

    p1 = Point(10, 80)
    u1 = Vector(108, 0)
    source2 = QtBeamOPL(line_start=Line(p0, u0),
                        line_end=Line(p1, u1),
                        s_start=100,
                        s_end=100,
                        N_inter=6,
                        scene=scene)
    source2.translate(dy=40)

    scene.propagate()

    # launch the gui
    gui.start()
コード例 #8
0
ファイル: t_geo.py プロジェクト: ederag/geoptics
    #rp1.translate(Vector(0, 100))

    #rp2 = regions.Polycurve(n, scene=scene)
    #rp2.start(Point(121.0, 38.0))
    #rp2.add_line(Point(121.0, 168.0))
    #rp2.add_line(Point(161.0, 168.0))
    #rp2.add_line(Point(161.0, 38.0))
    #rp2.close()

    # tracé d'un rayon
    p0 = Point(10, 20)
    u0 = Vector(108, 50)
    s0 = 3
    n0 = 1.0
    source1 = sources.SingleRay(line0=Line(p0, u0), s0=s0, scene=scene)
    gui.print_(source1)

    p1 = Point(10, 50)
    u1 = Vector(108, 100)
    source2 = sources.Beam(line_start=Line(p0, u0),
                           line_end=Line(p1, u1),
                           s_start=100,
                           s_end=100,
                           N_inter=5,
                           scene=scene)
    source2.translate(dy=40)

    scene.propagate()

    # launch the gui