|
|
@ -13,22 +13,18 @@ It should be split up into a few more separate files eventually... |
|
|
|
Probably even into it's own module folder. |
|
|
|
Probably even into it's own module folder. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
import math |
|
|
|
|
|
|
|
from typing import List |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from OpenGL.GL import (glBegin, glClearColor, glColor3f, glColor4f, |
|
|
|
from OpenGL.GL import (glBegin, glClearColor, glColor3f, glColor4f, |
|
|
|
glEnable, glEnd, GL_LINES, GL_LINE_LOOP, GL_LINE_SMOOTH, |
|
|
|
glEnable, glEnd, GL_LINES, GL_LINE_LOOP, GL_LINE_SMOOTH, |
|
|
|
GL_POINTS, glPointSize, glVertex3f, |
|
|
|
GL_POINTS, glPointSize, glVertex3f, |
|
|
|
glViewport) |
|
|
|
glViewport) |
|
|
|
|
|
|
|
|
|
|
|
from voronoiview.colors import Color, COLOR_TO_RGBA |
|
|
|
from voronoiview.colors import (Color, COLOR_TO_RGBA) |
|
|
|
from voronoiview.exceptions import (handle_exceptions, |
|
|
|
|
|
|
|
InvalidStateError) |
|
|
|
from voronoiview.exceptions import InvalidStateError |
|
|
|
from voronoiview.mode import Mode |
|
|
|
from voronoiview.mode import Mode |
|
|
|
from voronoiview.point_manager import PointManager |
|
|
|
from voronoiview.point_manager import PointManager |
|
|
|
|
|
|
|
|
|
|
|
# Constants set based on the size of the window. |
|
|
|
# Constants set based on the size of the window. |
|
|
|
__BOTTOM_LEFT = (0, 0) |
|
|
|
|
|
|
|
__WIDTH = None |
|
|
|
__WIDTH = None |
|
|
|
__HEIGHT = None |
|
|
|
__HEIGHT = None |
|
|
|
|
|
|
|
|
|
|
@ -147,9 +143,10 @@ def resize_gl(w, h): |
|
|
|
""" |
|
|
|
""" |
|
|
|
global __WIDTH |
|
|
|
global __WIDTH |
|
|
|
global __HEIGHT |
|
|
|
global __HEIGHT |
|
|
|
|
|
|
|
global __current_context |
|
|
|
|
|
|
|
|
|
|
|
__WIDTH = __current_context.opengl_widget.width() |
|
|
|
__WIDTH = __current_context.opengl_widget.width() * __current_context.devicePixelRatio() |
|
|
|
__HEIGHT = __current_context.opengl_widget.height() |
|
|
|
__HEIGHT = __current_context.opengl_widget.height() * __current_context.devicePixelRatio() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def viewport_width(): |
|
|
|
def viewport_width(): |
|
|
@ -160,7 +157,6 @@ def viewport_height(): |
|
|
|
return __HEIGHT |
|
|
|
return __HEIGHT |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@handle_exceptions |
|
|
|
|
|
|
|
def paint_gl(): |
|
|
|
def paint_gl(): |
|
|
|
""" |
|
|
|
""" |
|
|
|
Stock PaintGL function from OpenGL that switches |
|
|
|
Stock PaintGL function from OpenGL that switches |
|
|
@ -410,15 +406,16 @@ def draw_voronoi_diagram(): |
|
|
|
|
|
|
|
|
|
|
|
color = COLOR_TO_RGBA[Color.BLACK] |
|
|
|
color = COLOR_TO_RGBA[Color.BLACK] |
|
|
|
|
|
|
|
|
|
|
|
for region_indices in results.regions: |
|
|
|
print(results.regions) |
|
|
|
# The region index is out of bounds |
|
|
|
|
|
|
|
if -1 in region_indices: |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for region_indices in results.regions: |
|
|
|
glBegin(GL_LINE_LOOP) |
|
|
|
glBegin(GL_LINE_LOOP) |
|
|
|
for idx in region_indices: |
|
|
|
for idx in region_indices: |
|
|
|
vertex = vertices[idx] |
|
|
|
vertex = vertices[idx] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if -1 in region_indices: |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
|
|
|
|
glColor3f(color[0], color[1], color[2]) |
|
|
|
glColor3f(color[0], color[1], color[2]) |
|
|
|
glVertex3f(__clamp_x(vertex[0]), |
|
|
|
glVertex3f(__clamp_x(vertex[0]), |
|
|
|
__clamp_y(vertex[1]), |
|
|
|
__clamp_y(vertex[1]), |
|
|
|