Esempio n. 1
0
def cubic_curve_example():
    # create the plot
    fig, ax = plt.subplots()
    # sample per segment
    num_samples = 100

    # first segment
    p0 = SPoint(1, 1, 0)
    p1 = SPoint(3, 2, 45)
    # compute the coeff to fit the points
    coeff = cubic_curve(p0, p1)
    # add the segment
    x_sample, y_segment = compute_segment_points(p0.x, p1.x, coeff)
    utils.add_points(x_sample, y_segment, ax)

    # second segment
    p0 = SPoint(3, 2, 45)
    p1 = SPoint(3.5, 3.5, 80)
    coeff = cubic_curve(p0, p1)
    x_sample, y_segment = compute_segment_points(p0.x, p1.x, coeff)
    utils.add_points(x_sample, y_segment, ax, "r")

    # plot everything
    utils.plot_build(fig, ax)
    plt.show()
Esempio n. 2
0
 def command_not8th(self, data):
     if on_cooldown(self.cooldowns['!not8th'], three_mins): return True
     for better in self.betters:
         add_points(self, better, 1)
     self.cooldowns['!not8th'] = set_cooldown()
     return 'Yay not 8th!  All betters get 1 %s! (%s)' % (
         self.fmt_currency_name(1), ', '.join(self.betters))
Esempio n. 3
0
def draw_long_spline(spline_sequence, xlim, ylim, plot_vectors=False):
    """Draw a spline_sequence on a plot

    spline_sequence = [all_points, all_points, ...]
    """
    logg = logging.getLogger(f"c.{__name__}.draw_long_spline")
    #  logg.setLevel("INFO")
    logg.debug(f"Starting draw_long_spline")

    fig, ax = plt.subplots()
    ax.set_xlim(*xlim)
    ax.set_ylim(*ylim)

    for all_points in spline_sequence:
        for i in range(len(all_points) - 1):
            p0 = all_points[i]
            p1 = all_points[i + 1]
            if plot_vectors:
                utils.add_vector(p0, ax, color="k", vec_len=20)

            #  spline_x, spline_y = compute_spline(p0, p1)
            spline_x, spline_y = compute_thick_spline(p0, p1, 40)
            utils.add_points(spline_x, spline_y, ax, color="y", marker=".", ls="")

    if plot_vectors:
        utils.add_vector(p1, ax, color="k", vec_len=20)

    utils.plot_build(fig, ax)
    plt.show()
Esempio n. 4
0
 def command_bonus(self, data):
     if on_cooldown(self.cooldowns['!bonus'], three_mins): return True
     for better in self.betters:
         add_points(self, better, 5)
     self.cooldowns['!bonus'] = set_cooldown()
     return 'Yay Bonus! All betters get 5 %s! (%s)' % (
         self.fmt_currency_name(5), ', '.join(self.betters))
Esempio n. 5
0
def example_spline():
    """
    """
    logg = logging.getLogger(f"c.{__name__}.example_spline")
    logg.setLevel("INFO")
    logg.debug(f"Starting example_spline")

    # create the plot
    fig, ax = plt.subplots()
    ax.set_xlim(0, 4)
    ax.set_ylim(-3, 4)

    # sample per segment
    num_samples = 100

    # first segment
    p0 = SPoint(1, 1, 30)
    #  p1 = SPoint(3, 2, 45)
    p1 = SPoint(2.6, 3, 60)
    logg.debug(f"p0: {p0} p1: {p1}")
    # plot the points
    utils.add_vector(p0, ax, color="k")
    utils.add_vector(p1, ax, color="k")

    # compute the spline
    spline_x, spline_y = compute_spline(p0, p1, ax=ax)

    # plot the finished spline
    utils.add_points(spline_x, spline_y, ax, color="y")

    # plot everything
    utils.plot_build(fig, ax)
    plt.show()
Esempio n. 6
0
def example_thick_spline(p0, p1, thickness, scale):
    """
    """
    logg = logging.getLogger(f"c.{__name__}.example_thick_spline")
    logg.setLevel("INFO")
    logg.debug(f"\nStarting example_thick_spline")

    logg.debug(f"p0: {p0} p1: {p1}")

    # create the plot
    fig, ax = plt.subplots()
    ax.set_xlim(-2 * scale, 5 * scale)
    ax.set_ylim(-3 * scale, 5 * scale)
    #  ax.set_xlim(-1 * scale, 1.5 * scale)
    #  ax.set_ylim(-2.5 * scale, 2.5 * scale)

    # compute the spline
    spline_x, spline_y = compute_thick_spline(p0, p1, thickness, ax=ax)
    #  spline_x, spline_y = compute_thick_spline(p0, p1, thickness)

    # plot the finished spline
    utils.add_points(spline_x, spline_y, ax, color="k", marker=".", ls="")

    # plot everything
    utils.plot_build(fig, ax)
    plt.show()
Esempio n. 7
0
def compute_spline(p0, p1, num_samples=100, ax=None):
    """Compute the cubic spline between two points

    * translate to the origin and rotate the points to have both on the x axis
    * compute the spline
    * rotate and translate to original position
    """
    logg = logging.getLogger(f"c.{__name__}.compute_spline")
    logg.setLevel("INFO")
    logg.debug(f"Starting compute_spline")

    # translate and rotate the point to the origin
    rot_p0, rot_p1, dir_01 = translate_points_to_origin(p0, p1)

    # plot the rotated vectors
    if not ax is None:
        utils.add_vector(rot_p0, ax, color="r")
        utils.add_vector(rot_p1, ax, color="r")

    # compute the spline points
    coeff = cubic_curve(rot_p0, rot_p1)
    x_sample, y_segment = compute_segment_points(rot_p0.x, rot_p1.x, coeff)
    if not ax is None:
        utils.add_points(x_sample, y_segment, ax, color="g")

    # rototranslate points to the original position
    rototran_x, rototran_y = rototranslate_points(
        x_sample, y_segment, -dir_01, p0.x, p0.y,
    )

    return rototran_x, rototran_y
def get_seat_for_direction(grid: Grid, point: Point,
                           direction: Point) -> Optional[str]:
    next_stop = add_points(point, direction)
    next_point = grid.get(next_stop, None)
    while True:
        if next_point is None or is_seat(next_point):
            return next_point
        next_stop = add_points(next_stop, direction)
        next_point = grid.get(next_stop, None)
Esempio n. 9
0
 def command_beg(self, data):
     if get_points(self, self.user) < 5:
         success = add_points(self, self.user, 5)
         if success:
             return '%s tosses %s 5 %s out of pity.' % (NICKNAME, self.user,
                                                        self.currency_name)
     else:
         return 'Get outta here %s!  You\'re not broke!' % self.user
Esempio n. 10
0
    def to_tile(self):
        tile_grid: Grid = Grid()
        for puzzle_point, tile in self.grid.items():
            stripped = tile.strip_border()
            scaled_point = (puzzle_point[0] * stripped.width, puzzle_point[1] * stripped.width)
            for child_point, value in stripped.grid.items():
                actual_point = add_points(scaled_point, child_point)
                tile_grid[actual_point] = value

        return Tile(-1, tile_grid, set())
Esempio n. 11
0
 def command_wipe(self, data):
     if not self.raid: return True
     gil = 1
     if not on_cooldown(self.cooldowns['!wipe'], one_min):
         gil = 5
         self.cooldowns['!wipe'] = set_cooldown()
     if add_points(self, self.user, gil):
         return 'Thanks %s! Have %s %s!' % (self.user, gil,
                                            self.fmt_currency_name(gil))
     else:
         return 'Thanks %s!' % self.user
Esempio n. 12
0
 def command_give(self, data):
     try:
         amount = int(data[2])
         recipient = data[1].lower()
         if user_exists(self, recipient):
             if self.user == CHANNEL_NAME:
                 if add_points(self, recipient, amount):
                     return '%s gives %s %s %s' % (
                         NICKNAME, data[1], amount,
                         self.fmt_currency_name(amount))
             if self.user == recipient: return True
             if amount < 0: return True
             if sub_points(self, self.user, amount):
                 if add_points(self, recipient, amount):
                     return '%s gives %s %s %s' % (
                         self.user, data[1], amount,
                         self.fmt_currency_name(amount))
     except:
         pass
     return True
Esempio n. 13
0
 def run_race(self):
     winners = list()
     all_winners = True
     for racer in self.racers.keys():
         result = choice(['win', 'lose'])
         if result == 'win':
             if add_points(self.instance, racer, int(self.racers[racer]) * 2):
                 winners.append(racer)
         else:
             all_winners = False
     self.racers = dict()
     self.instance.cooldowns['!race'] = set_cooldown()
     self.race_pending = False
     if len(winners) == 0:
         return "The briars were everywhere today.  No one won their race."
     if all_winners:
         return "Everyone won their race!  Congratulations %s!" % ', '.join(winners)
     else:
         return "The race is over.  Congratulations to the winners: %s!" % ', '.join(winners)
Esempio n. 14
0
def main():
  
  ROOT.gROOT.SetBatch()

  limits = [ 
    ( 'ExclusionContours_2HDMTypeI_tanb_vs_cba.root',  '#bf{2HDM Type I, #it{m_{H}} = 200 GeV}',      1,   10, 26, -0.9, 0.9, 'cos(#beta-#alpha)',    utils.h_to_zz_to + utils.lepp + utils.lepm + utils.lepp + utils.lepm, None ),  
    ( 'ExclusionContours_2HDMTypeII_tanb_vs_cba.root', '#bf{2HDM Type II, #it{m_{H}} = 200 GeV}',     1,   10, 26, -0.9, 0.9, 'cos(#beta-#alpha)',    utils.h_to_zz_to + utils.lepp + utils.lepm + utils.lepp + utils.lepm, None ),  
    ( 'ExclusionContours_2HDMTypeI_tanb_vs_mH.root',   '#bf{2HDM Type I, cos(#beta-#alpha) = -0.1}',  0.5, 18, 80,     200,  400, '#it{m_{H}} [GeV]', utils.h_to_zz_to + utils.lepp + utils.lepm + utils.lepp + utils.lepm + ' + ' + utils.lepp + utils.lepm + utils.nu + utils.nubar, ( 320, 324, 31 ) ),  
    ( 'ExclusionContours_2HDMTypeII_tanb_vs_mH.root',  '#bf{2HDM Type II, cos(#beta-#alpha) = -0.1}', 0.5, 10, 35,     200,  400, '#it{m_{H}} [GeV]', utils.h_to_zz_to + utils.lepp + utils.lepm + utils.lepp + utils.lepm + ' + ' + utils.lepp + utils.lepm + utils.nu + utils.nubar, ( 320, 324, 15.6 ) ),  
  ]

  for file_name, mod_type, minY, maxY, max_maxY, minX, maxX, x_title, channel, patch_vals in limits:
    file = ROOT.TFile( 'inputs/' + file_name )
    first_base_hist = file.Get( 'h_med' ) 
    base_hist = ROOT.TH2F( first_base_hist.GetName() + '_extended', ';%s;tan#beta' % x_title, first_base_hist.GetXaxis().GetNbins(), first_base_hist.GetXaxis().GetXmin(), first_base_hist.GetXaxis().GetXmax(), 100 * first_base_hist.GetYaxis().GetNbins(), first_base_hist.GetYaxis().GetXmin(), 1000 )
    obs_name = 'obs'
    if 'tanb_vs_mH' in file_name:
      obs_name = 'obsc'
    types = [ 
      utils.graph_info( 'n2sig', file, 5, 1, 1001 ),
      utils.graph_info( 'n1sig', file, 3, 1, 1001 ),
      utils.graph_info( 'p1sig', file, 5, 1, 1001 ),
      utils.graph_info( 'p2sig', file, ROOT.kWhite, 1, 1001 ),
      #utils.graph_info( 'med', file, ROOT.kWhite, 1001 ), 
      utils.graph_info( 'medc', file, ROOT.kAzure + 2, 2 ), 
      utils.graph_info( 'obsf', file, ROOT.kOrange + 10, 1, 3844 ),
      utils.graph_info( obs_name, file, ROOT.kBlack, 1 ),
    ]
    graphs = {}
    single_graphs = {}
    for item in types:
      for index in range( item.number ):
        full_name = 'h_%s_contour_%d' % ( item.name, index )
        graphs[ full_name ] = ( utils.add_points( file.Get( full_name ), [] ), item )
        single_graphs[ item.name ] = graphs[ full_name ]
    canvas = ROOT.TCanvas( 'plot_' + file_name.replace( '.root', '' ), '', 600, 600 )
    base_hist.Draw( 'axis' )
    order = [ 'n2sig', 'n1sig', 'p1sig', 'p2sig', 'med', 'medc', 'obsf', obs_name ]
    for key1 in order:
      for key2, ( g, g_info ) in graphs.iteritems():
        if key1 in key2:
          g.SetLineColor( g_info.color )
          g.SetLineStyle( g_info.line )
          g.SetLineWidth( 2 )
          option = 'c'
          if g_info.fill:
            g.SetFillColor( g_info.color )
            g.SetFillStyle( g_info.fill )
            g.SetLineStyle( 1 )
            g.SetLineColor( ROOT.kBlack )
            option = 'fc'
            #if 'sig' in g_info.name:
            #  option = '3'
          g.Draw( option )
    base_hist.GetXaxis().SetRangeUser( minX, maxX )
    base_hist.GetYaxis().SetRangeUser( minY, max_maxY ) #utils.get_bound( minY, maxY ) )
    canvas.Update()
    the_box = utils.get_box( ROOT.gPad.GetUxmin(), ROOT.gPad.GetUxmax(), maxY, ROOT.gPad.GetUymax() )
    base_hist.Draw( 'axis same' )
    the_box.Draw( 'l' )
    x_l1, y_l1, latex1 = utils.draw_latex( utils.lumi, False )
    latex1.DrawLatex( x_l1, y_l1 - 0.105, channel )
    latex1.SetTextSize( 20 )
    #latex1.DrawLatex( x_l1, y_l1 - 0.16, '2HDM Type I, #it{m_{H}}=200 GeV' )
    latex1.SetTextAlign( 22 )
    latex1.DrawLatex( 0.535, y_l1 - 0.16, mod_type )
    xLeg = 0.62
    yLeg = 0.89
    leg = utils.create_legend_2hdm( 3 ) 
    leg.AddEntry( single_graphs[ obs_name ][ 0 ], 'Observed', 'l' )
    leg.AddEntry( single_graphs[ 'n1sig' ][ 0 ], '#pm1#sigma band', 'f' )
    leg.AddEntry( single_graphs[ 'medc' ][ 0 ], 'Expected', 'l' )
    leg.AddEntry( single_graphs[ 'n2sig' ][ 0 ], '#pm2#sigma band', 'f' )
    leg.AddEntry( None, '', '' )
    leg.AddEntry( single_graphs[ 'obsf' ][ 0 ], 'Excluded', 'f' )
    leg.Draw()
    #if patch_vals:
    #  p_x1, p_x2, p_y = patch_vals 
    #  utils.patch_bar( p_x1, p_x2, p_y, p_y ) 
    canvas.SetLogy()
    utils.save( canvas )
 def move_south(self, amount: int):
     self.waypoint_position = add_points(self.waypoint_position, (0, -amount))
Esempio n. 16
0
def compute_thick_spline(p0, p1, thickness, num_samples=100, ax=None):
    """Compute the thick cubic spline between two points

    * translate to the origin and rotate the points to have both on the x axis
    * compute the spline
    * make it thicker
    * rotate and translate to original position
    """
    logg = logging.getLogger(f"c.{__name__}.compute_spline")
    logg.setLevel("INFO")
    logg.debug(f"Starting compute_spline")

    # translate and rotate the point to the origin
    rot_p0, rot_p1, dir_01 = translate_points_to_origin(p0, p1)
    logg.debug(f"rot_p0: {rot_p0} rot_p1: {rot_p1}")

    # compute the normal direction to the vectors
    np0_ori_rad = rot_p0.ori_rad + pi / 2
    np1_ori_rad = rot_p1.ori_rad + pi / 2

    # compute the corner points of the thick spline
    offset_x_0 = cos(np0_ori_rad) * thickness
    offset_y_0 = sin(np0_ori_rad) * thickness
    logg.debug(f"offset_x_0: {offset_x_0} offset_y_0: {offset_y_0}")
    p0t = SPoint(rot_p0.x + offset_x_0, rot_p0.y + offset_y_0, rot_p0.ori_deg)
    p0b = SPoint(rot_p0.x - offset_x_0, rot_p0.y - offset_y_0, rot_p0.ori_deg)
    logg.debug(f"p0t: {p0t} p0b: {p0b}")
    offset_x_1 = cos(np1_ori_rad) * thickness
    offset_y_1 = sin(np1_ori_rad) * thickness
    logg.debug(f"offset_x_1: {offset_x_1} offset_y_1: {offset_y_1}")
    p1t = SPoint(rot_p1.x + offset_x_1, rot_p1.y + offset_y_1, rot_p1.ori_deg)
    p1b = SPoint(rot_p1.x - offset_x_1, rot_p1.y - offset_y_1, rot_p1.ori_deg)
    logg.debug(f"p1t: {p1t} p1b: {p1b}")

    # compute the coeff of the line passing through the points
    coeff_l = line_curve(p0t, p0b)
    coeff_r = line_curve(p1t, p1b)
    logg.debug(f"coeff_l: {coeff_l} coeff_r: {coeff_r}")

    # compute the spline points
    coeff_t = cubic_curve(p0t, p1t)
    coeff_b = cubic_curve(p0b, p1b)
    x_sample_t, y_segment_t = sample_segment_points(p0t.x, p1t.x, coeff_t)
    x_sample_b, y_segment_b = sample_segment_points(p0b.x, p1b.x, coeff_b)
    logg.debug(f"x_sample_t.shape: {x_sample_t.shape}")
    logg.debug(f"x_sample_b.shape: {x_sample_b.shape}")

    contour_t, contour_b, x_sample = build_contour(
        p0t,
        p0b,
        p1t,
        p1b,
        coeff_l,
        coeff_r,
        x_sample_t,
        y_segment_t,
        x_sample_b,
        y_segment_b,
        ax,
    )

    # compute the top and bottom contours
    logg.debug(f"x_sample.shape: {x_sample.shape}")
    logg.debug(f"contour_t.shape: {contour_t.shape}")
    logg.debug(f"contour_b.shape: {contour_b.shape}")

    # get the max and min y, aligned on the grid
    max_y = np.amax(contour_t)
    min_y = np.amin(contour_b)
    logg.debug(f"max_y: {max_y} min_y: {min_y}")
    max_y_aligned = floor(max_y)
    min_y_aligned = ceil(min_y)
    logg.debug(f"max_y_aligned: {max_y_aligned} min_y_aligned: {min_y_aligned}")

    #  sample all the points inside the spline, aligned on the grid
    on_points_x = []
    on_points_y = []
    for i, x_curr in enumerate(x_sample):
        for y_curr in range(min_y_aligned, max_y_aligned + 1):
            if contour_b[i] <= y_curr <= contour_t[i]:
                on_points_x.append(x_curr)
                on_points_y.append(y_curr)

    # rototranslate points to the original position
    rototran_x, rototran_y = rototranslate_points(
        on_points_x, on_points_y, -dir_01, p0.x, p0.y,
    )

    # plot everything to debug things
    if not ax is None:
        vec_len = 3
        ## plot the points
        utils.add_vector(p0, ax, color="r", vec_len=vec_len)
        utils.add_vector(p1, ax, color="r", vec_len=vec_len)
        ## plot the rotated vectors
        utils.add_vector(rot_p0, ax, color="k", vec_len=vec_len)
        utils.add_vector(rot_p1, ax, color="k", vec_len=vec_len)
        ## plot the corner of the spline
        utils.add_vector(p0t, ax, color="k", vec_len=vec_len)
        utils.add_vector(p1t, ax, color="k", vec_len=vec_len)
        utils.add_vector(p0b, ax, color="k", vec_len=vec_len)
        utils.add_vector(p1b, ax, color="k", vec_len=vec_len)
        ## plot top and bottom splines
        #  utils.add_points(x_sample_t, y_segment_t, ax, color="b", marker=".", ls="")
        #  utils.add_points(x_sample_b, y_segment_b, ax, color="b", marker=".", ls="")
        utils.add_points(x_sample_t, y_segment_t, ax, color="r", marker="", ls="-")
        utils.add_points(x_sample_b, y_segment_b, ax, color="r", marker="", ls="-")
        ## plot top and bottom contours
        utils.add_points(x_sample, contour_t, ax, color="r", marker=".", ls="")
        utils.add_points(x_sample, contour_b, ax, color="r", marker=".", ls="")
        ## plot on point
        utils.add_points(on_points_x, on_points_y, ax, color="b", marker=".", ls="")
        ## plot on point translated back to original position
        utils.add_points(rototran_x, rototran_y, ax, color="b", marker=".", ls="")

    return rototran_x, rototran_y
Esempio n. 17
0
def build_contour(
    p0t,
    p0b,
    p1t,
    p1b,
    coeff_l,
    coeff_r,
    x_sample_t,
    y_segment_t,
    x_sample_b,
    y_segment_b,
    ax,
):
    """TODO: Docstring for build_contour.

    :p0t: TODO
    :p0b: TODO
    :p1t: TODO
    :p1b: TODO
    :coeff_l: TODO
    :coeff_r: TODO
    :x_sample_t: TODO
    :y_segment_t: TODO
    :x_sample_b: TODO
    :y_segment_b: TODO
    :returns: TODO

    """
    logg = logging.getLogger(f"c.{__name__}.build_contour")
    logg.setLevel("INFO")
    logg.debug(f"Starting build_contour")

    # regular case, no overlaps
    if p0t.x <= p1t.x and p0b.x <= p1b.x:
        # sample the whole line
        x_sample_l, y_segment_l = sample_segment_points(p0t.x, p0b.x, coeff_l)
        x_sample_r, y_segment_r = sample_segment_points(p1t.x, p1b.x, coeff_r)
        logg.debug(f"x_sample_l.shape: {x_sample_l.shape}")
        logg.debug(f"x_sample_r.shape: {x_sample_r.shape}")

        # plot everything to debug things
        if not ax is None:
            # plot left and right segments
            utils.add_points(x_sample_l, y_segment_l, ax, color="g", marker=".", ls="")
            utils.add_points(x_sample_r, y_segment_r, ax, color="g", marker=".", ls="")

        # /\
        if coeff_l[0] >= 0 and coeff_r[0] <= 0:
            logg.debug(f"/\ coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l, x_sample_t, x_sample_r))
            contour_t = np.hstack((y_segment_l, y_segment_t, y_segment_r))
            contour_b = y_segment_b

        # //
        elif coeff_l[0] >= 0 and coeff_r[0] >= 0:
            logg.debug(f"// coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l, x_sample_t))
            contour_t = np.hstack((y_segment_l, y_segment_t))
            contour_b = np.hstack((y_segment_b, y_segment_r))

        # \\
        elif coeff_l[0] <= 0 and coeff_r[0] <= 0:
            logg.debug(f"\\\\ coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l, x_sample_b))
            contour_t = np.hstack((y_segment_t, y_segment_r))
            contour_b = np.hstack((y_segment_l, y_segment_b))

        # \/
        elif coeff_l[0] <= 0 and coeff_r[0] >= 0:
            logg.debug(f"\\/ coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l, x_sample_b, x_sample_r))
            contour_t = y_segment_t
            contour_b = np.hstack((y_segment_l, y_segment_b, y_segment_r))

        return contour_t, contour_b, x_sample

    # both ends of p1tb are left of p0bt, this should not happen
    elif p0t.x <= p1t.x and p0b.x <= p1b.x:
        # MAYBE call this again with them swapped
        raise ValueError(f"Swap the points and try again {p0t} {p0b} {p1t} {p1b}")

    # compute the intersection between the two lines
    # x = (b2-b1)/(a1-a2)
    i_x = (coeff_l[1] - coeff_r[1]) / (coeff_r[0] - coeff_l[0])
    i_y = coeff_l[0] * i_x + coeff_l[1]
    logg.debug(f"i_x: {i_x} i_y: {i_y}")

    # /\ // \\ type, keep the lower part
    if p0t.x > p1t.x and p0b.x <= p1b.x:
        x_sample = 0
        contour_t = 0
        contour_b = 0
        x_sample_l, y_segment_l = sample_segment_points(p0b.x, i_x, coeff_l)
        x_sample_r, y_segment_r = sample_segment_points(p1b.x, i_x, coeff_r)

        # /\
        if coeff_l[0] >= 0 and coeff_r[0] <= 0:
            logg.debug(f"/\ coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l, x_sample_r))
            contour_t = np.hstack((y_segment_l, y_segment_r))
            contour_b = y_segment_b

        # //
        elif coeff_l[0] >= 0 and coeff_r[0] >= 0:
            logg.debug(f"// coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l))
            contour_t = np.hstack((y_segment_l))
            contour_b = np.hstack((y_segment_b, y_segment_r))

        # \\
        elif coeff_l[0] <= 0 and coeff_r[0] <= 0:
            logg.debug(f"\\\\ coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_r))
            contour_t = np.hstack((y_segment_r))
            contour_b = np.hstack((y_segment_l, y_segment_b))

    # \/ // \\ type, keep the upper part
    elif p0t.x <= p1t.x and p0b.x > p1b.x:
        x_sample = 0
        contour_t = 0
        contour_b = 0
        x_sample_l, y_segment_l = sample_segment_points(p0t.x, i_x, coeff_l)
        x_sample_r, y_segment_r = sample_segment_points(p1t.x, i_x, coeff_r)

        # //
        if coeff_l[0] >= 0 and coeff_r[0] >= 0:
            logg.debug(f"// coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l, x_sample_t))
            contour_t = np.hstack((y_segment_l, y_segment_t))
            contour_b = np.hstack((y_segment_r))

        # \\
        elif coeff_l[0] <= 0 and coeff_r[0] <= 0:
            logg.debug(f"\\\\ coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l))
            contour_t = np.hstack((y_segment_t, y_segment_r))
            contour_b = np.hstack((y_segment_l))

        # \/
        elif coeff_l[0] <= 0 and coeff_r[0] >= 0:
            logg.debug(f"\\/ coeff_l[0]: {coeff_l[0]} coeff_r[0]: {coeff_r[0]}")
            x_sample = np.hstack((x_sample_l, x_sample_r))
            contour_t = y_segment_t
            contour_b = np.hstack((y_segment_l, y_segment_r))

    # plot everything to debug things
    if not ax is None:
        ## plot left and right segments
        utils.add_points(x_sample_l, y_segment_l, ax, color="g", marker=".", ls="")
        utils.add_points(x_sample_r, y_segment_r, ax, color="g", marker=".", ls="")
        ## intersection point
        utils.add_points([i_x], [i_y], ax, color="g", marker="x", ls="")
        ## plot the segments
        utils.add_points(
            [p0t.x, p0b.x], [p0t.y, p0b.y], ax, color="b", marker="", ls="-"
        )
        utils.add_points(
            [p1t.x, p1b.x], [p1t.y, p1b.y], ax, color="b", marker="", ls="-"
        )

    return contour_t, contour_b, x_sample
 def move_north(self, amount: int):
     self.current_position = add_points(self.current_position, (0, amount))
 def move_east(self, amount: int):
     self.current_position = add_points(self.current_position, (amount, 0))
 def move_forward(self, amount: int):
     vector: Point = (amount * self.waypoint_position[0], amount * self.waypoint_position[1])
     self.current_position = add_points(self.current_position, vector)
Esempio n. 21
0
 def has_sea_monster(self, point: Point) -> bool:
     transformed_points = [add_points(point, monster_point) for monster_point in sea_monster_points]
     matches = [self.grid.get(transformed_point, None) == '#' for transformed_point in transformed_points]
     return all(matches)
 def move_west(self, amount: int):
     self.waypoint_position = add_points(self.waypoint_position, (-amount, 0))