Fix naming convention
This commit is contained in:
37
networks/roads/lanes/Lane.py
Normal file
37
networks/roads/lanes/Lane.py
Normal file
@@ -0,0 +1,37 @@
|
||||
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, lane_materials, width):
|
||||
self.coordinates = coordinates
|
||||
self.width = width
|
||||
self.lane_materials = lane_materials
|
||||
self.surface = []
|
||||
|
||||
def get_surface(self):
|
||||
resolution, distance = curve.resolution_distance(self.coordinates, 6)
|
||||
|
||||
curve_points = curve.curve(self.coordinates, resolution)
|
||||
curve_surface = CurveSurface.CurveSurface(self.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(self.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(self.lane_materials.keys()),
|
||||
weights=self.lane_materials.values(),
|
||||
k=1,)))
|
||||
|
||||
return self.surface
|
||||
7
networks/roads/lanes/lanes.json
Normal file
7
networks/roads/lanes/lanes.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}
|
||||
}
|
||||
Reference in New Issue
Block a user