commit e46ab576caa9ceadad7d1773cc2f5f7b0d81b9ea
parent fb2da9b32f197cd1576d41388cb58c3052bfaee3
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 9 Jan 2025 17:46:56 +0100
Replace hard coded parameters with parsed values
Windows geometry was based on #defined constants that are now part of
mode_2 datasets and are user provided and parsed.
Diffstat:
4 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/src/cg_catalog.c b/src/cg_catalog.c
@@ -212,6 +212,10 @@ create_catalog
item.crawl_height = parsed_item->crawl_height;
item.attic_height = parsed_item->attic_height;
item.glass_ratio = parsed_item->glass_ratio;
+ item.windows_min_width = parsed_item->windows_min_width;
+ item.windows_max_width = parsed_item->windows_max_width;
+ item.windows_min_spacing = parsed_item->windows_min_spacing;
+ item.windows_height_ratio = parsed_item->windows_height_ratio;
ERR(htable_dataset_cmode_2_set(&catalog->catalog_2, &name, &item));
}
break;
diff --git a/src/cg_construction_mode_2.c b/src/cg_construction_mode_2.c
@@ -873,13 +873,6 @@ build_windows
wall_width = wall_surface / wall_height;
total_wall_surface += wall_surface;
- /* TODO: put it in parameters */
-#define CG2_MODE2_WINDOWS_MIN_WIDTH 1.2
-#define CG2_MODE2_WINDOWS_MAX_WIDTH 3.0
-#define CG2_MODE2_WINDOWS_MIN_SPACING 0.4
-#define CG2_MODE2_WINDOWS_HEIGHT_RATIO 0.6
-#define CG2_MODE2_WINDOWS_WALL_FRACTION_ABOVE 0.1
-
if(!removed_wall) {
double window_height, expected_total_width_from_ratio;
double wc, best_wc, best_wc_score, best_wc_spacing, best_wc_width;
@@ -889,16 +882,17 @@ build_windows
best_wc_spacing = wall_width;
best_wc_width = 0;
/* search for the count, width, spacing that best meet expectations */
- window_height = CG2_MODE2_WINDOWS_HEIGHT_RATIO * wall_height;
+ window_height = data->windows_height_ratio * wall_height;
expected_total_width_from_ratio = wall_width * data->glass_ratio;
wc = 1;
while(wall_width >=
- wc * CG2_MODE2_WINDOWS_MIN_WIDTH + (wc + 1) * CG2_MODE2_WINDOWS_MIN_SPACING) {
+ wc * data->windows_min_width + (wc + 1) * data->windows_min_spacing)
+ {
double score;
- double max_achievable_width = MMIN(CG2_MODE2_WINDOWS_MAX_WIDTH,
- (wall_width - (wc + 1) * CG2_MODE2_WINDOWS_MIN_SPACING) / wc);
+ double max_achievable_width = MMIN(data->windows_max_width,
+ (wall_width - (wc + 1) * data->windows_min_spacing) / wc);
if(max_achievable_width * wc >= expected_total_width_from_ratio
- && CG2_MODE2_WINDOWS_MIN_WIDTH * wc <= expected_total_width_from_ratio)
+ && data->windows_min_width * wc <= expected_total_width_from_ratio)
{
/* Expected ratio is achievable! */
score = 1;
@@ -912,7 +906,7 @@ build_windows
/* Compute the width that is closest to expectations */
double best_width_for_wc =
(max_achievable_width * wc < expected_total_width_from_ratio)
- ? max_achievable_width : CG2_MODE2_WINDOWS_MIN_WIDTH;
+ ? max_achievable_width : data->windows_min_width;
score = 1 / (1 + fabs(wc * best_width_for_wc - expected_total_width_from_ratio));
ASSERT(score < 1);
if(score > best_wc_score) {
@@ -954,9 +948,8 @@ build_windows
+ best_wc_spacing + (double)n * (best_wc_spacing + best_wc_width);
dxdydz[0] = -N[1] * offset;
dxdydz[1] = N[0] * offset;
- /* Apply requested Z positioning */
- dxdydz[2] = (wall_height - window_height) * 0.5
- - CG2_MODE2_WINDOWS_WALL_FRACTION_ABOVE * wall_height;
+ /* Z positioning (centered) */
+ dxdydz[2] = (wall_height - window_height) * 0.5;
ERR(str_printf(&name, "surface+_%lu_w%lu",
(long unsigned)i, (long unsigned)n));
/* surface_ is used to check for neighbor compatibility with a slitghly
@@ -1116,7 +1109,7 @@ build_windows
}
effective_ratio = total_windows_surface / total_wall_surface;
meet_effective_ratio = data->glass_ratio == 0
- || fabs(effective_ratio - data->glass_ratio)/ data->glass_ratio < 0.01;
+ || fabs(effective_ratio - data->glass_ratio) / data->glass_ratio < 0.01;
logger_print(city->logger, (meet_effective_ratio ? LOG_OUTPUT : LOG_WARNING),
"Building '%s' overall glass ratio is %.1f %% (expected is %.1f %%).\n",
prefix, 100 * effective_ratio, 100 * data->glass_ratio);
diff --git a/src/cg_construction_mode_2.h b/src/cg_construction_mode_2.h
@@ -48,6 +48,10 @@ struct dataset_cmode_2 {
double crawl_height; /* can be 0 */
double attic_height; /* can be 0 */
double glass_ratio; /* in [0, 1] */
+ double windows_min_width; /* must be > 0 */
+ double windows_max_width; /* must be >= windows_min_width */
+ double windows_min_spacing; /* must be > 0 */
+ double windows_height_ratio; /* in [0, 1] */
};
#define HTABLE_NAME dataset_cmode_2
diff --git a/src/cg_construction_mode_2_parsing_schemas.h b/src/cg_construction_mode_2_parsing_schemas.h
@@ -39,6 +39,10 @@ struct parsed_dataset_cmode_2 {
double crawl_height; /* can be 0 */
double attic_height; /* can be 0 */
double glass_ratio; /* in [0, 1] */
+ double windows_min_width; /* must be > 0 */
+ double windows_max_width; /* must be >= windows_min_width */
+ double windows_min_spacing; /* must be > 0 */
+ double windows_height_ratio; /* in [0, 1] */
};
/********************************************************/
@@ -79,6 +83,14 @@ static const cyaml_schema_field_t dataset_cmode_2_fields_schema[] = {
struct parsed_dataset_cmode_2, attic_height),
CYAML_FIELD_FLOAT("glass_ratio", CYAML_FLAG_DEFAULT,
struct parsed_dataset_cmode_2, glass_ratio),
+ CYAML_FIELD_FLOAT("windows_min_width", CYAML_FLAG_DEFAULT,
+ struct parsed_dataset_cmode_2, windows_min_width),
+ CYAML_FIELD_FLOAT("windows_max_width", CYAML_FLAG_DEFAULT,
+ struct parsed_dataset_cmode_2, windows_max_width),
+ CYAML_FIELD_FLOAT("windows_min_spacing", CYAML_FLAG_DEFAULT,
+ struct parsed_dataset_cmode_2, windows_min_spacing),
+ CYAML_FIELD_FLOAT("windows_height_ratio", CYAML_FLAG_DEFAULT,
+ struct parsed_dataset_cmode_2, windows_height_ratio),
CYAML_FIELD_END
};