载入中...
搜索中...
未找到
UrbanTypes.h
浏览该文件的文档.
1#pragma once
2
3#include <cmath>
4#include <cstddef>
5#include <cstdint>
6#include <string>
7#include <utility>
8#include <vector>
9
10namespace eve::procgen::urban {
11
15struct Vec2 {
16 double x = 0.0;
17 double y = 0.0;
18
20 Vec2 operator+(const Vec2& o) const { return {x + o.x, y + o.y}; }
22 Vec2 operator-(const Vec2& o) const { return {x - o.x, y - o.y}; }
24 Vec2 operator*(double s) const { return {x * s, y * s}; }
26 Vec2 operator/(double s) const { return {x / s, y / s}; }
28 Vec2 operator-() const { return {-x, -y}; }
30 bool operator==(const Vec2& o) const { return x == o.x && y == o.y; }
32 bool operator!=(const Vec2& o) const { return !(*this == o); }
33};
34
36inline double cross(const Vec2& a, const Vec2& b) { return a.x * b.y - a.y * b.x; }
38inline double dot(const Vec2& a, const Vec2& b) { return a.x * b.x + a.y * b.y; }
40inline double length(const Vec2& a) { return std::sqrt(dot(a, a)); }
42inline double lengthSq(const Vec2& a) { return dot(a, a); }
44inline Vec2 normalize(const Vec2& a) {
45 const double l = length(a);
46 if (l <= 1e-12) return {1.0, 0.0};
47 return a / l;
48}
50inline Vec2 perpendicular(const Vec2& a) { return {-a.y, a.x}; }
52inline double distance(const Vec2& a, const Vec2& b) { return length(a - b); }
53
55using Polygon = std::vector<Vec2>;
57using Polyline = std::vector<Vec2>;
58
63struct Street {
64 Polyline pts; // centerline along parcel boundary edges
65 double width = 1.0;
66};
67
69struct Parcel {
70 std::vector<int> ring; // corner indices, CCW, no repeated first corner
71};
72
74struct GraphEdge {
75 int a = -1;
76 int b = -1;
77 bool isStreet = false;
78};
79
85 std::vector<Vec2> corners; // welded unique parcel corners
86 std::vector<Parcel> parcels; // CCW rings over `corners`
87 std::vector<GraphEdge> edges; // parcel corner graph edges
88 std::vector<Street> streets; // decomposed street network
89 std::vector<std::pair<int, int>> streetSegments; // corner index pairs (for mesh/access)
90
92 int streetEnds = 0;
93 double totalStreetLength = 0.0;
94 double avgIrregularity = 0.0;
95 double minIrregularity = 0.0;
96 double maxIrregularity = 0.0;
97 int levelsUsed = 0;
98
100 void clear() {
101 corners.clear();
102 parcels.clear();
103 edges.clear();
104 streets.clear();
105 streetSegments.clear();
108 levelsUsed = 0;
109 }
110};
111
118 Polygon land; // input land polygon (CCW); filled by the generator
119 double minParcelArea = 4.0; // minimally allowed parcel area (world units^2)
120 int targetParcels = 120; // desired parcel count (0 = run until no parcel is splittable)
121 int maxLevels = 10;
122 uint32_t seed = 1;
123
124 double lambdaSize = 0.3; // λ1 size balance
125 double lambdaRegu = 0.5; // λ2 regularity of resulting parcels
126 double lambdaAcce = 0.2; // λ3 street access
127 double lambdaOrient = 0.0; // optional orientation preference weight
128 double gammaAngle = 0.75; // γ1 interior-angle variance
129 double gammaSide = 0.25; // γ2 side-length variance
130 double accessThreshold = 0.5; // τ for Q_acce
131 double shortEdgeFactor = 0.2; // short-edge removal threshold factor
132 double streetWidth = 1.0; // street width (world units) for output
133 double dijkstraJunctionWeight = 1.5; // extra cost of a turn when connecting streets
134 double boundaryStreetFraction = 0.5; // fraction of boundary that is street (mode 2)
135
136 int streetPattern = 0; // 0=default(avoid cul-de-sacs), 1=loop, 2=culdesac, 3=tree
137 int culDeSacAfterLevel = 4; // allow street ends only from this level on (pattern 2)
138 int orientation = 0; // 0=none, 1=east-west, 2=north-south
139 int boundaryStreetMode = 0; // 0=all boundary is street, 1=none, 2=random segments
140
141 bool optimize = true;
143 double optRegu = 0.20; // ω1
144 double optSide = 1.00; // ω2
145 double optStre = 1.00; // ω3
146 double optJunc = 0.50; // ω4
147 double optClose = 0.30; // ω5
148 double optStep = 0.35;
149};
150
153 int edgeIndex = -1;
154 double t = 0.0;
155};
156
160 double tangentAngle = 0.0; // radians, angle of the boundary tangent
161 double arcLength = 0.0;
162};
163
164} // namespace eve::procgen::urban
const std::string & s
float length
Definition CaveMesh.cpp:94
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
Vec2 perpendicular(const Vec2 &a)
Perpendicular.
Definition UrbanTypes.h:50
std::vector< Vec2 > Polyline
Open polyline (e.g. a streamline candidate or a street centerline).
Definition UrbanTypes.h:57
Vec2 normalize(const Vec2 &a)
Normalize.
Definition UrbanTypes.h:44
double dot(const Vec2 &a, const Vec2 &b)
Dot.
Definition UrbanTypes.h:38
std::vector< Vec2 > Polygon
Closed polygon ring, stored CCW, without repeating the first point.
Definition UrbanTypes.h:55
double cross(const Vec2 &a, const Vec2 &b)
Cross.
Definition UrbanTypes.h:36
double lengthSq(const Vec2 &a)
Length sq.
Definition UrbanTypes.h:42
Where a point sits on the polygon boundary: edge edgeIndex at parameter t in [0,1].
Definition UrbanTypes.h:152
A boundary sample used for field constraints / candidate seeds.
Definition UrbanTypes.h:158
Undirected edge of the parcel corner graph.
Definition UrbanTypes.h:74
One parcel: a CCW ring of indices into UrbanLayout::corners.
Definition UrbanTypes.h:69
std::vector< int > ring
Definition UrbanTypes.h:70
A street decomposed from the street network graph: consecutive street edges whose included angle is l...
Definition UrbanTypes.h:63
Structured urban layout produced by the hierarchical co-generation (paper Section 4) plus the geometr...
Definition UrbanTypes.h:84
std::vector< Street > streets
Definition UrbanTypes.h:88
std::vector< Vec2 > corners
Definition UrbanTypes.h:85
std::vector< Parcel > parcels
Definition UrbanTypes.h:86
std::vector< std::pair< int, int > > streetSegments
Definition UrbanTypes.h:89
std::vector< GraphEdge > edges
Definition UrbanTypes.h:87
All user-facing controls for the urban generator. Defaults follow the paper (λ=0.3/0....
Definition UrbanTypes.h:117
Minimal 2D vector used by the urban layout algorithms (paper coordinates).
Definition UrbanTypes.h:15
Vec2 operator+(const Vec2 &o) const
Operator +.
Definition UrbanTypes.h:20
Vec2 operator-(const Vec2 &o) const
Operator -.
Definition UrbanTypes.h:22
Vec2 operator/(double s) const
Operator /.
Definition UrbanTypes.h:26
bool operator==(const Vec2 &o) const
Operator ==.
Definition UrbanTypes.h:30
Vec2 operator*(double s) const
Operator *.
Definition UrbanTypes.h:24
bool operator!=(const Vec2 &o) const
Operator !=.
Definition UrbanTypes.h:32
Vec2 operator-() const
Operator -.
Definition UrbanTypes.h:28