Update to use gdpc Transform (simplifies a lot)
This commit is contained in:
@@ -6,8 +6,7 @@ from buildings.geometry.Rectangle import Rectangle
|
||||
from buildings.geometry.Vertice import Vertice
|
||||
|
||||
class Polygon:
|
||||
def __init__(self, position : Point, size: tuple[int,int]):
|
||||
self.position = position
|
||||
def __init__(self, size: tuple[int,int]):
|
||||
self.size = size
|
||||
self.shape = []
|
||||
self.vertices = []
|
||||
@@ -70,7 +69,7 @@ class Polygon:
|
||||
def set_vertices_and_neighbors(self, tiles : list[Tile], vertices : list[Vertice]):
|
||||
for tile in tiles:
|
||||
targets = tile.get_neighbors_coords()
|
||||
for vertice_num,target in utils.Enumerate(targets):
|
||||
for vertice_num,target in enumerate(targets):
|
||||
has_neighbor = self._has_neighbor(target, tiles)
|
||||
if not has_neighbor:
|
||||
vertice = tile.get_vertice(vertice_num)
|
||||
|
||||
@@ -9,9 +9,8 @@ class Rectangle:
|
||||
def get_position(self):
|
||||
return (self.point1.position, self.point2.position)
|
||||
|
||||
def fill(self,editor : Editor, material : str, y : int, y2 : int = None, xpadding : int = 0, zpadding : int = 0):
|
||||
def fill(self,editor : Editor, material : str, y : int = None, xpadding : int = 0, zpadding : int = 0):
|
||||
if self.point2.x - self.point1.x < 2*xpadding: xpadding = 0
|
||||
if self.point2.z - self.point1.z < 2*zpadding: zpadding = 0
|
||||
if y2 == None: y2 = y
|
||||
|
||||
geometry.placeCuboid(editor, (self.point1.x+xpadding, y, self.point1.z+zpadding), (self.point2.x-xpadding, y2, self.point2.z-zpadding), Block(material))
|
||||
geometry.placeCuboid(editor, (self.point1.x+xpadding, 0, self.point1.z+zpadding), (self.point2.x-xpadding, y, self.point2.z-zpadding), Block(material))
|
||||
|
||||
@@ -27,15 +27,14 @@ class Tile:
|
||||
self.north_vertice = None
|
||||
self.south_vertice = None
|
||||
|
||||
def fill(self, editor : Editor, material : str, y : int, y2 : int = None) -> list[Point]:
|
||||
if y2 == None: y2 = y
|
||||
geometry.placeCuboid(editor, (self.pos.x, y, self.pos.z), (self.pos.x+self.size-1, y2, self.pos.z+self.size-1), Block(material))
|
||||
def fill(self, editor : Editor, material : str, y : int = 0) -> list[Point]:
|
||||
geometry.placeCuboid(editor, (self.pos.x, 0, self.pos.z), (self.pos.x+self.size-1, y, self.pos.z+self.size-1), Block(material))
|
||||
|
||||
def get_neighbors_coords(self):
|
||||
return [Point(x = self.pos.x - self.size, z = self.pos.z), # west
|
||||
Point(x = self.pos.x + self.size, z = self.pos.z), # east
|
||||
Point(x = self.pos.x, z = self.pos.z - self.size), # north
|
||||
Point(x = self.pos.x, z = self.pos.z + self.size)] # south
|
||||
return [Point(x = self.pos.x, z = self.pos.z - self.size), # north
|
||||
Point(x = self.pos.x - self.size, z = self.pos.z), # west
|
||||
Point(x = self.pos.x, z = self.pos.z + self.size), # south
|
||||
Point(x = self.pos.x + self.size, z = self.pos.z)] # east
|
||||
|
||||
|
||||
def get_neighbor(self, direction) -> Point:
|
||||
@@ -62,16 +61,16 @@ class Tile:
|
||||
|
||||
def get_vertice(self,vertice : int|DIRECTION) -> Vertice:
|
||||
# gives the corresponding vertice :
|
||||
# 0 = west, 1 = east, 2 = north, 3 = south
|
||||
# 0 = north, 1 = west, 2 = south, 3 = east
|
||||
match(vertice):
|
||||
case 0 :
|
||||
return Vertice(self.north_west, self.south_west, DIRECTION.WEST)
|
||||
case 1 :
|
||||
return Vertice(self.north_east, self.south_east, DIRECTION.EAST)
|
||||
case 2 :
|
||||
return Vertice(self.north_west, self.north_east, DIRECTION.NORTH)
|
||||
case 3 :
|
||||
case 1 :
|
||||
return Vertice(self.north_west, self.south_west, DIRECTION.WEST)
|
||||
case 2 :
|
||||
return Vertice(self.south_west, self.south_east, DIRECTION.SOUTH)
|
||||
case 3 :
|
||||
return Vertice(self.north_east, self.south_east, DIRECTION.EAST)
|
||||
case DIRECTION.WEST :
|
||||
return self.west_vertice
|
||||
case DIRECTION.EAST :
|
||||
|
||||
@@ -16,6 +16,6 @@ class Vertice(Rectangle):
|
||||
return [Point(x = self.point1.x, z = self.point1.z - 1),
|
||||
Point(x = self.point2.x, z = self.point2.z + 1)]
|
||||
|
||||
def get_size(self):
|
||||
def get_len(self):
|
||||
return self.point2.x - self.point1.x + self.point2.z - self.point1.z + 1
|
||||
|
||||
Reference in New Issue
Block a user