Segment error detection
This commit is contained in:
66
main.py
66
main.py
@@ -18,20 +18,23 @@ from gdpc import Editor, Block
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
editor = Editor(buffering=True)
|
editor = Editor(buffering=True)
|
||||||
c = Circle(Point2D(400, -75)).circle_thick_by_line(5, 32)
|
# c = Circle(Point2D(400, -75)).circle_thick_by_line(5, 32)
|
||||||
for i in range(len(c[0])):
|
# for i in range(len(c[0])):
|
||||||
for j in range(len(c[0][i])):
|
# for j in range(len(c[0][i])):
|
||||||
if i % 2 == 0:
|
# if i % 2 == 0:
|
||||||
editor.placeBlock(
|
# editor.placeBlock(
|
||||||
(c[0][i][j].x, 110, c[0][i][j].y), Block("white_concrete"))
|
# (c[0][i][j].x, 110, c[0][i][j].y), Block("white_concrete"))
|
||||||
else:
|
# else:
|
||||||
editor.placeBlock(
|
# editor.placeBlock(
|
||||||
(c[0][i][j].x, 110, c[0][i][j].y), Block("black_concrete"))
|
# (c[0][i][j].x, 110, c[0][i][j].y), Block("black_concrete"))
|
||||||
print(c[1])
|
# print(c[1])
|
||||||
for i in range(len(c[1])):
|
# for i in range(len(c[1])):
|
||||||
for j in range(len(c[1][i])):
|
# for j in range(len(c[1][i])):
|
||||||
editor.placeBlock(
|
# editor.placeBlock(
|
||||||
(c[1][i][j].x, 110, c[1][i][j].y), Block("red_concrete"))
|
# (c[1][i][j].x, 110, c[1][i][j].y), Block("red_concrete"))
|
||||||
|
|
||||||
|
Road([Point3D(464, 85, -225), Point3D(408, 105, -224),
|
||||||
|
Point3D(368, 104, -249), Point3D(368, 85, -296), Point3D(457, 79, -292)], 15)
|
||||||
# rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker()
|
# rectangle_house_mountain, rectangle_building, skeleton_highway, skeleton_mountain, road_grid = world_maker()
|
||||||
|
|
||||||
# editor = Editor(buffering=True)
|
# editor = Editor(buffering=True)
|
||||||
@@ -128,38 +131,3 @@ def set_roads(skeleton: Skeleton, origin):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
"""
|
|
||||||
from gdpc import Editor, Block, geometry, Transform
|
|
||||||
import networks.curve as curve
|
|
||||||
import numpy as np
|
|
||||||
from utils.JsonReader import JsonReader
|
|
||||||
from utils.YamlReader import YamlReader
|
|
||||||
from buildings.Building import Building
|
|
||||||
|
|
||||||
from utils.functions import *
|
|
||||||
from utils.Enums import DIRECTION
|
|
||||||
|
|
||||||
editor = Editor(buffering=True)
|
|
||||||
|
|
||||||
# get every differents buildings shapes
|
|
||||||
f = JsonReader('buildings\shapes.json')
|
|
||||||
shapes = f.data
|
|
||||||
baseShape = shapes[0]['matrice']
|
|
||||||
|
|
||||||
# get the random data for the buildings
|
|
||||||
y = YamlReader('params.yml')
|
|
||||||
random_data = y.data
|
|
||||||
|
|
||||||
#move your editor to the position you wanna build on
|
|
||||||
transform = Transform((75,-60,110),rotation = 0)
|
|
||||||
editor.transform.push(transform)
|
|
||||||
|
|
||||||
# clear the area you build on
|
|
||||||
geometry.placeCuboid(editor, (-5,0,-8), (25,100,25), Block("air"))
|
|
||||||
|
|
||||||
# create a building at the relative position 0,0 with 20 blocks length and 20 blocks width, with a normal shape and 10 floors
|
|
||||||
building = Building(random_data["buildings"], [(0,0,0), (20,30,20)], baseShape, DIRECTION.EAST)
|
|
||||||
# build it with your custom materials
|
|
||||||
building.build(editor, ["stone_bricks","glass_pane","glass","cobblestone_wall","stone_brick_stairs","oak_planks","white_concrete","cobblestone","stone_brick_slab","iron_bars"])
|
|
||||||
"""
|
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ class Segment2D:
|
|||||||
self.end = end
|
self.end = end
|
||||||
self.points: List[Point2D] = []
|
self.points: List[Point2D] = []
|
||||||
self.points_thick: List[Point2D] = []
|
self.points_thick: List[Point2D] = []
|
||||||
self.points_thick_by_line: List[Union[Point2D, int]] = []
|
|
||||||
|
self.points_thick_by_line: List[List[Point2D]] = []
|
||||||
|
self.gaps: List[List[Point2D]] = []
|
||||||
|
|
||||||
self.thickness = None
|
self.thickness = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -58,7 +61,7 @@ class Segment2D:
|
|||||||
delta_2x = 2*delta_x
|
delta_2x = 2*delta_x
|
||||||
delta_2y = 2*delta_y
|
delta_2y = 2*delta_y
|
||||||
|
|
||||||
self._add_points(start, _is_computing_thickness)
|
self._add_points(start, _is_computing_thickness, LINE_OVERLAP.NONE)
|
||||||
|
|
||||||
if (delta_x > delta_y):
|
if (delta_x > delta_y):
|
||||||
error = delta_2y - delta_x
|
error = delta_2y - delta_x
|
||||||
@@ -66,30 +69,34 @@ class Segment2D:
|
|||||||
start.x += step_x
|
start.x += step_x
|
||||||
if (error >= 0):
|
if (error >= 0):
|
||||||
if (overlap == LINE_OVERLAP.MAJOR):
|
if (overlap == LINE_OVERLAP.MAJOR):
|
||||||
self._add_points(start, _is_computing_thickness)
|
self._add_points(
|
||||||
|
start, _is_computing_thickness, overlap)
|
||||||
|
|
||||||
start.y += step_y
|
start.y += step_y
|
||||||
if (overlap == LINE_OVERLAP.MINOR):
|
if (overlap == LINE_OVERLAP.MINOR):
|
||||||
self._add_points(
|
self._add_points(
|
||||||
Point2D(start.copy().x - step_x, start.copy().y), _is_computing_thickness)
|
Point2D(start.copy().x - step_x, start.copy().y), _is_computing_thickness, overlap)
|
||||||
error -= delta_2x
|
error -= delta_2x
|
||||||
error += delta_2y
|
error += delta_2y
|
||||||
self._add_points(start, _is_computing_thickness)
|
self._add_points(
|
||||||
|
start, _is_computing_thickness, LINE_OVERLAP.NONE)
|
||||||
else:
|
else:
|
||||||
error = delta_2x - delta_y
|
error = delta_2x - delta_y
|
||||||
while (start.y != end.y):
|
while (start.y != end.y):
|
||||||
start.y += step_y
|
start.y += step_y
|
||||||
if (error >= 0):
|
if (error >= 0):
|
||||||
if (overlap == LINE_OVERLAP.MAJOR):
|
if (overlap == LINE_OVERLAP.MAJOR):
|
||||||
self._add_points(start, _is_computing_thickness)
|
self._add_points(
|
||||||
|
start, _is_computing_thickness, overlap)
|
||||||
|
|
||||||
start.x += step_x
|
start.x += step_x
|
||||||
if (overlap == LINE_OVERLAP.MINOR):
|
if (overlap == LINE_OVERLAP.MINOR):
|
||||||
self._add_points(
|
self._add_points(
|
||||||
Point2D(start.copy().x, start.copy().y - step_y), _is_computing_thickness)
|
Point2D(start.copy().x, start.copy().y - step_y), _is_computing_thickness, overlap)
|
||||||
error -= delta_2y
|
error -= delta_2y
|
||||||
error += delta_2x
|
error += delta_2x
|
||||||
self._add_points(start, _is_computing_thickness)
|
self._add_points(
|
||||||
|
start, _is_computing_thickness, LINE_OVERLAP.NONE)
|
||||||
|
|
||||||
if not _is_computing_thickness:
|
if not _is_computing_thickness:
|
||||||
return self.points
|
return self.points
|
||||||
@@ -110,6 +117,7 @@ class Segment2D:
|
|||||||
>>> self.compute_thick_segment(self.start, self.end, self.thickness, self.thickness_mode)
|
>>> self.compute_thick_segment(self.start, self.end, self.thickness, self.thickness_mode)
|
||||||
"""
|
"""
|
||||||
self.points_thick_by_line = [[] for _ in range(thickness+1)]
|
self.points_thick_by_line = [[] for _ in range(thickness+1)]
|
||||||
|
self.gaps = [[] for _ in range(thickness+1)]
|
||||||
|
|
||||||
start = self.start.copy()
|
start = self.start.copy()
|
||||||
end = self.end.copy()
|
end = self.end.copy()
|
||||||
@@ -243,10 +251,14 @@ class Segment2D:
|
|||||||
np.round((self.start.y + self.end.y) / 2.0).astype(int),
|
np.round((self.start.y + self.end.y) / 2.0).astype(int),
|
||||||
)
|
)
|
||||||
|
|
||||||
def _add_points(self, points, is_computing_thickness):
|
def _add_points(self, points, is_computing_thickness, overlap):
|
||||||
if is_computing_thickness > 0:
|
if is_computing_thickness > 0:
|
||||||
self.points_thick.append(points.copy())
|
self.points_thick.append(points.copy())
|
||||||
self.points_thick_by_line[is_computing_thickness].append(
|
if overlap == LINE_OVERLAP.NONE:
|
||||||
(points.copy()))
|
self.points_thick_by_line[is_computing_thickness].append(
|
||||||
|
(points.copy()))
|
||||||
|
else:
|
||||||
|
self.gaps[is_computing_thickness].append(
|
||||||
|
(points.copy()))
|
||||||
else:
|
else:
|
||||||
self.points.append(points.copy())
|
self.points.append(points.copy())
|
||||||
|
|||||||
@@ -65,9 +65,10 @@ class Road:
|
|||||||
# self.output_block.append(
|
# self.output_block.append(
|
||||||
# (Point3D.insert_3d([self.polyline.segments[i].points_thick[j]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("stone")))
|
# (Point3D.insert_3d([self.polyline.segments[i].points_thick[j]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("stone")))
|
||||||
for k in range(len(self.polyline.segments[i].points_thick_by_line)):
|
for k in range(len(self.polyline.segments[i].points_thick_by_line)):
|
||||||
match k:
|
kk = k % 7
|
||||||
|
match kk:
|
||||||
case 0:
|
case 0:
|
||||||
blob = 'black_concrete'
|
blob = 'pink_concrete'
|
||||||
case 1:
|
case 1:
|
||||||
blob = 'red_concrete'
|
blob = 'red_concrete'
|
||||||
case 2:
|
case 2:
|
||||||
@@ -87,12 +88,17 @@ class Road:
|
|||||||
self.output_block.append(
|
self.output_block.append(
|
||||||
(Point3D.insert_3d([self.polyline.segments[i].points_thick_by_line[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block(blob)))
|
(Point3D.insert_3d([self.polyline.segments[i].points_thick_by_line[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block(blob)))
|
||||||
|
|
||||||
|
for m in range(len(self.polyline.segments[i].gaps[k])):
|
||||||
|
nearest = self.polyline.segments[i].gaps[k][m].nearest(
|
||||||
|
Point3D.to_2d(self.polyline_total_line_output, removed_axis='y'), True)
|
||||||
|
self.output_block.append(
|
||||||
|
(Point3D.insert_3d([self.polyline.segments[i].gaps[k][m]], 'y', [self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("white_concrete")))
|
||||||
|
|
||||||
for i in range(1, len(self.polyline.centers)-1):
|
for i in range(1, len(self.polyline.centers)-1):
|
||||||
# Circle
|
# Circle
|
||||||
|
|
||||||
circle = Circle(self.polyline.centers[i])
|
circle, gaps = Circle(self.polyline.centers[i]).circle_thick_by_line(int(
|
||||||
circle.circle_thick(int(
|
(self.polyline.radii[i]-self.width/2)), int((self.polyline.radii[i]+self.width/2)+1))
|
||||||
(self.polyline.radii[i]-self.width/2)), int((self.polyline.radii[i]+self.width/2)-1))
|
|
||||||
|
|
||||||
# Better to do here than drawing circle arc inside big triangle!
|
# Better to do here than drawing circle arc inside big triangle!
|
||||||
double_point_a = Point2D.from_arrays(Point2D.to_arrays(self.polyline.acrs_intersections[i][0]) + 5 * (Point2D.to_arrays(
|
double_point_a = Point2D.from_arrays(Point2D.to_arrays(self.polyline.acrs_intersections[i][0]) + 5 * (Point2D.to_arrays(
|
||||||
@@ -100,13 +106,39 @@ class Road:
|
|||||||
double_point_b = Point2D.from_arrays(Point2D.to_arrays(self.polyline.acrs_intersections[i][2]) + 5 * (Point2D.to_arrays(
|
double_point_b = Point2D.from_arrays(Point2D.to_arrays(self.polyline.acrs_intersections[i][2]) + 5 * (Point2D.to_arrays(
|
||||||
self.polyline.acrs_intersections[i][2]) - Point2D.to_arrays(self.polyline.centers[i])))
|
self.polyline.acrs_intersections[i][2]) - Point2D.to_arrays(self.polyline.centers[i])))
|
||||||
|
|
||||||
for j in range(len(circle.points_thick)):
|
for j in range(len(circle)):
|
||||||
if circle.points_thick[j].is_in_triangle(double_point_a, self.polyline.centers[i], double_point_b):
|
for k in range(len(circle[j])):
|
||||||
nearest = circle.points_thick[j].nearest(
|
jj = j % 7
|
||||||
Point3D.to_2d(self.polyline_total_line_output, removed_axis='y'), True)
|
match jj:
|
||||||
self.output_block.append(
|
case 0:
|
||||||
(Point3D.insert_3d([circle.points_thick[j]], 'y', [
|
blob = 'pink_concrete'
|
||||||
self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("white_concrete")))
|
case 1:
|
||||||
|
blob = 'red_concrete'
|
||||||
|
case 2:
|
||||||
|
blob = 'orange_concrete'
|
||||||
|
case 3:
|
||||||
|
blob = 'yellow_concrete'
|
||||||
|
case 4:
|
||||||
|
blob = 'green_concrete'
|
||||||
|
case 5:
|
||||||
|
blob = 'blue_concrete'
|
||||||
|
case 6:
|
||||||
|
blob = 'purple_concrete'
|
||||||
|
if circle[j][k].is_in_triangle(double_point_a, self.polyline.centers[i], double_point_b):
|
||||||
|
nearest = circle[j][k].nearest(
|
||||||
|
Point3D.to_2d(self.polyline_total_line_output, removed_axis='y'), True)
|
||||||
|
self.output_block.append(
|
||||||
|
(Point3D.insert_3d([circle[j][k]], 'y', [
|
||||||
|
self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block(blob)))
|
||||||
|
|
||||||
|
for j in range(len(gaps)):
|
||||||
|
for k in range(len(gaps[j])):
|
||||||
|
if gaps[j][k].is_in_triangle(double_point_a, self.polyline.centers[i], double_point_b):
|
||||||
|
nearest = gaps[j][k].nearest(
|
||||||
|
Point3D.to_2d(self.polyline_total_line_output, removed_axis='y'), True)
|
||||||
|
self.output_block.append(
|
||||||
|
(Point3D.insert_3d([gaps[j][k]], 'y', [
|
||||||
|
self.polyline_total_line_output[nearest[0]].y])[0].coordinates, Block("white_concrete")))
|
||||||
|
|
||||||
def _projection_polyline(self):
|
def _projection_polyline(self):
|
||||||
nearest_points_to_reference = []
|
nearest_points_to_reference = []
|
||||||
|
|||||||
Reference in New Issue
Block a user