<commit_before>#!/usr/bin/env python
import tkinter as tk
import tkinter.messagebox


CANVAS_WIDTH = 600
CANVAS_HEIGHT = 300
CANVAS_PADDING = 3
CANVAS_BORDER_SIZE = 1

ZOOM_CELL_SIZE = 10
ZOOM_CELL_WIDTH = (CANVAS_WIDTH - CANVAS_PADDING - CANVAS_BORDER_SIZE) // \
                  (ZOOM_CELL_SIZE + CANVAS_BORDER_SIZE)
ZOOM_CELL_HEIGHT = (CANVAS_HEIGHT - CANVAS_PADDING - CANVAS_BORDER_SIZE) // \
                   (ZOOM_CELL_SIZE + CANVAS_BORDER_SIZE)


class LineDemoWindow:
    def __init__(self):
        self.root = tk.Tk()

        self.main_canvas = tk.Canvas(self.root,
                                     width=CANVAS_WIDTH, height=CANVAS_HEIGHT)
        self.main_canvas.grid(row=0, column=0, rowspan=7)
        self.zoom_canvas = tk.Canvas(self.root,
                                     width=CANVAS_WIDTH, height=CANVAS_HEIGHT)
        self.zoom_canvas.grid(row=7, column=0)

        self.from_label = tk.Label(self.root, text='From')
        self.from_label.grid(row=0, column=1)
        self.from_x_entry = tk.Entry(self.root)
        self.from_x_entry.insert(0, '5')
        self.from_x_entry.grid(row=0, column=2)
        self.from_y_entry = tk.Entry(self.root)
        self.from_y_entry.insert(0, '5')
        self.from_y_entry.grid(row=0, column=3)

        self.to_label = tk.Label(self.root, text='To')
        self.to_label.grid(row=1, column=1)
        self.to_x_entry = tk.Entry(self.root)
        self.to_x_entry.insert(0, '30')
        self.to_x_entry.grid(row=1, column=2)
        self.to_y_entry = tk.Entry(self.root)
        self.to_y_entry.insert(0, '20')
        self.to_y_entry.grid(row=1, column=3)

        self.step_button = tk.Button(
            self.root, text='Пошаговый алгоритм',
            command=self.draw_step
        )
        self.step_button.grid(row=2, column=1, sticky='w', columnspan=3)
        self.dda_button = tk.Button(
            self.root, text='Алгоритм ЦДА',
            command=self.draw_dda
        )
        self.dda_button.grid(row=3, column=1, sticky='w', columnspan=3)
        self.bresenham_button = tk.Button(
            self.root, text='Алгоритм Брезенхема',
            command=self.draw_bresenham
        )
        self.bresenham_button.grid(row=4, column=1, sticky='w', columnspan=3)
        self.bresenham_circle_button = tk.Button(
            self.root, text='Алгоритм Брезенхема (окружность)',
            command=self.draw_bresenham_circle
        )
        self.bresenham_circle_button.grid(row=5, column=1, sticky='w',
                                          columnspan=3)
        self.root.grid_rowconfigure(6, weight=1)

        self.clear()
        self.draw_pixel(0, 0)

    def get_points(self):
        from_x = int(self.from_x_entry.get())
        from_y = int(self.from_y_entry.get())
        to_x = int(self.to_x_entry.get())
        to_y = int(self.to_y_entry.get())
        return (from_x, from_y), (to_x, to_y)

    def draw_step(self):
        try:
            (from_x, from_y), (to_x, to_y) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

        self.clear()

        if from_x > to_x:
            from_x, to_x = to_x, from_x
            from_y, to_y = to_y, from_y

        dx = to_x - from_x
        dy = to_y - from_y

        for x in range(from_x, to_x + 1):
            passed_y = dy * (x - from_x) // dx if dx else 0
            y = from_y + passed_y
            self.draw_pixel(x, y)

    def draw_dda(self):
        try:
            (from_x, from_y), (to_x, to_y) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

    def draw_bresenham(self):
        try:
            (from_x, from_y), (to_x, to_y) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

    def draw_bresenham_circle(self):
        try:
            (from_x, from_y), (to_x, to_y) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

    def clear(self):
        self.main_canvas.delete('all')
        self.zoom_canvas.delete('all')
        self.draw_borders()

    def draw_pixel(self, x, y):
        if x < 0 or x >= CANVAS_WIDTH - CANVAS_PADDING - CANVAS_BORDER_SIZE or \
                    y < 0 or y >= CANVAS_HEIGHT - CANVAS_PADDING - CANVAS_BORDER_SIZE:<commit_msg>Add DDA<commit_after>#!/usr/bin/env python
import tkinter as tk
import tkinter.messagebox


CANVAS_WIDTH = 600
CANVAS_HEIGHT = 300
CANVAS_PADDING = 3
CANVAS_BORDER_SIZE = 1

ZOOM_CELL_SIZE = 10
ZOOM_CELL_WIDTH = (CANVAS_WIDTH - CANVAS_PADDING - CANVAS_BORDER_SIZE) // \
                  (ZOOM_CELL_SIZE + CANVAS_BORDER_SIZE)
ZOOM_CELL_HEIGHT = (CANVAS_HEIGHT - CANVAS_PADDING - CANVAS_BORDER_SIZE) // \
                   (ZOOM_CELL_SIZE + CANVAS_BORDER_SIZE)


class LineDemoWindow:
    def __init__(self):
        self.root = tk.Tk()

        self.main_canvas = tk.Canvas(self.root,
                                     width=CANVAS_WIDTH, height=CANVAS_HEIGHT)
        self.main_canvas.grid(row=0, column=0, rowspan=7)
        self.zoom_canvas = tk.Canvas(self.root,
                                     width=CANVAS_WIDTH, height=CANVAS_HEIGHT)
        self.zoom_canvas.grid(row=7, column=0)

        self.from_label = tk.Label(self.root, text='From')
        self.from_label.grid(row=0, column=1)
        self.from_x_entry = tk.Entry(self.root)
        self.from_x_entry.insert(0, '5')
        self.from_x_entry.grid(row=0, column=2)
        self.from_y_entry = tk.Entry(self.root)
        self.from_y_entry.insert(0, '5')
        self.from_y_entry.grid(row=0, column=3)

        self.to_label = tk.Label(self.root, text='To')
        self.to_label.grid(row=1, column=1)
        self.to_x_entry = tk.Entry(self.root)
        self.to_x_entry.insert(0, '30')
        self.to_x_entry.grid(row=1, column=2)
        self.to_y_entry = tk.Entry(self.root)
        self.to_y_entry.insert(0, '20')
        self.to_y_entry.grid(row=1, column=3)

        self.step_button = tk.Button(
            self.root, text='Пошаговый алгоритм',
            command=self.draw_step
        )
        self.step_button.grid(row=2, column=1, sticky='w', columnspan=3)
        self.dda_button = tk.Button(
            self.root, text='Алгоритм ЦДА',
            command=self.draw_dda
        )
        self.dda_button.grid(row=3, column=1, sticky='w', columnspan=3)
        self.bresenham_button = tk.Button(
            self.root, text='Алгоритм Брезенхема',
            command=self.draw_bresenham
        )
        self.bresenham_button.grid(row=4, column=1, sticky='w', columnspan=3)
        self.bresenham_circle_button = tk.Button(
            self.root, text='Алгоритм Брезенхема (окружность)',
            command=self.draw_bresenham_circle
        )
        self.bresenham_circle_button.grid(row=5, column=1, sticky='w',
                                          columnspan=3)
        self.root.grid_rowconfigure(6, weight=1)

        self.clear()

    def get_points(self):
        from_x = int(self.from_x_entry.get())
        from_y = int(self.from_y_entry.get())
        to_x = int(self.to_x_entry.get())
        to_y = int(self.to_y_entry.get())
        return (from_x, from_y), (to_x, to_y)

    def draw_step(self):
        try:
            (x1, y1), (x2, y2) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

        self.clear()

        if x1 > x2:
            x1, x2 = x2, x1
            y1, y2 = y2, y1

        dx = x2 - x1
        dy = y2 - y1

        for x in range(x1, x2 + 1):
            passed_y = dy * (x - x1) // dx if dx else 0
            y = y1 + passed_y
            self.draw_pixel(x, y)

    def draw_dda(self):
        try:
            (x1, y1), (x2, y2) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

        self.clear()

        if x1 > x2:
            x1, x2 = x2, x1
            y1, y2 = y2, y1

        dx = x2 - x1
        dy = y2 - y1
        l = max(dx, dy)

        self.draw_pixel(x1, y1)
        for i in range(l):
            y1 += dy / l
            x1 += dx / l
            self.draw_pixel(int(x1), int(y1))

    def draw_bresenham(self):
        try:
            (x1, y1), (x2, y2) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

        self.clear()

    def draw_bresenham_circle(self):
        try:
            (x1, y1), (x2, y2) = self.get_points()
        except ValueError:
            tkinter.messagebox.showerror('Error', 'Invalid coordinates')
            return

        self.clear()

    def clear(self):
        self.main_canvas.delete('all')
        self.zoom_canvas.delete('all')
        self.draw_borders()

    def draw_pixel(self, x, y):
        if x < 0 or x >= CANVAS_WIDTH - CANVAS_PADDING - CANVAS_BORDER_SIZE or \
                    y < 0 or y >= CANVAS_HEIGHT - CANVAS_PADDING - CANVAS_BORDER_SIZE:
{'fraction_non_alphanumeric': 0.1171756551873511, 'fraction_numerical': 0.017977041368854235, 'mean_word_length': 1.9993504384540435, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2527596', 'n_tokens_mistral': 3422, 'n_tokens_neox': 3346, 'n_words': 561}