Add line object
This commit is contained in:
36
networks/lanes/Lane.py
Normal file
36
networks/lanes/Lane.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import networks.geometry.curve as curve
|
||||
import networks.geometry.CurveSurface as CurveSurface
|
||||
import networks.geometry.segment as segment
|
||||
import random
|
||||
|
||||
|
||||
class Lane:
|
||||
def __init__(self, coordinates, width, lane_type):
|
||||
self.coordinates = coordinates
|
||||
self.width = width
|
||||
self.lane_type = lane_type
|
||||
self.lane_materials = lane_materials
|
||||
self.surface = []
|
||||
|
||||
def create_surface(self, coordinates):
|
||||
resolution, distance = curve.resolution_distance(coordinates, 6)
|
||||
|
||||
curve_points = curve.curve(coordinates, resolution)
|
||||
curve_surface = CurveSurface.CurveSurface(coordinates)
|
||||
curve_surface.compute_curvature()
|
||||
|
||||
# Set the road to be flat
|
||||
normals = []
|
||||
for i in range(len(curve_surface.curvature)):
|
||||
normals.append((0, 1, 0))
|
||||
|
||||
# Compute each line
|
||||
for distance in range(width):
|
||||
offset = curve.offset(curve_surface.curve, distance, normals)
|
||||
for i in range(len(offset)-1):
|
||||
line = segment.discrete_segment(offset[i], offset[i+1])
|
||||
for coordinate in line:
|
||||
self.surface.append((coordinate, random.choices(
|
||||
list(lane_materials.keys()),
|
||||
weights=lane_materials.values(),
|
||||
k=1,)))
|
||||
7
networks/lanes/materials.json
Normal file
7
networks/lanes/materials.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"classic_lane": {"stone": 3, "andesite": 1},
|
||||
"modern_lane": {"black_concrete": 3, "black_concrete_powder": 1},
|
||||
|
||||
"bike_lane_green": {"green_concrete": 3, "green_concrete_powder": 1},
|
||||
"bike_lane_red": {"red_concrete": 3, "red_concrete_powder": 1}
|
||||
}
|
||||
41
networks/lines/Line.py
Normal file
41
networks/lines/Line.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import networks.geometry.curve as curve
|
||||
import networks.geometry.segment as segment
|
||||
import random
|
||||
|
||||
|
||||
class Line:
|
||||
def __init__(self, coordinates, line_type):
|
||||
self.coordinates = coordinates
|
||||
self.line_type = line_type
|
||||
self.surface = []
|
||||
|
||||
def get_surface(self):
|
||||
resolution, distance = curve.resolution_distance(self.coordinates, 6)
|
||||
|
||||
curve_points = curve.curve(self.coordinates, resolution)
|
||||
|
||||
# Compute the line
|
||||
|
||||
pattern_length = 0
|
||||
pattern_materials = []
|
||||
for key, value in self.line_type.items():
|
||||
pattern_length += int(key)
|
||||
for _ in range(int(key)):
|
||||
pattern_materials.append(value)
|
||||
|
||||
pattern_iteration = 0
|
||||
for i in range(len(curve_points)-1):
|
||||
line = segment.discrete_segment(curve_points[i], curve_points[i+1])
|
||||
for coordinate in line:
|
||||
block = random.choices(
|
||||
list(pattern_materials[pattern_iteration].keys()),
|
||||
weights=pattern_materials[pattern_iteration].values(),
|
||||
k=1)[0]
|
||||
if block != 'None':
|
||||
self.surface.append((coordinate, block))
|
||||
|
||||
pattern_iteration += 1
|
||||
if pattern_iteration >= pattern_length:
|
||||
pattern_iteration = 0
|
||||
|
||||
return self.surface
|
||||
9
networks/lines/line.json
Normal file
9
networks/lines/line.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"solid_white": {
|
||||
"1": {"white_concrete": 3, "white_concrete_powder": 1}
|
||||
},
|
||||
"broken_white": {
|
||||
"3": {"white_concrete": 3, "white_concrete_powder": 1},
|
||||
"1": {"None": 1}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
class Lane:
|
||||
def __init__(self, coordinates, lane_type):
|
||||
pass
|
||||
@@ -1,7 +1,7 @@
|
||||
class Road:
|
||||
def __init__(self, coordinates, road_type):
|
||||
self.coordinates = coordinates # List of tuples (x1, y1, z1) in order
|
||||
def __init__(self, coordinates):
|
||||
self.coordinates = coordinates # List of tuples (x1, y1, z1) in order
|
||||
self.road_type = road_type # 'road', 'highway'
|
||||
|
||||
def place_roads(self):
|
||||
pass
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user