Skip to content

Commit 6a1c54d

Browse files
committed
Use helper variable "a_total_sum"
1 parent 6a7858a commit 6a1c54d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

R/apply_measures_to_blocks.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ apply_measures_to_blocks <- function(blocks, measures, dbg = FALSE, check = FALS
5656
# the measures.
5757
a_total <- blocks$total_area
5858
a_roof <- blocks$total_area * blocks$roof
59+
a_total_sum <- sum(a_total)
5960

6061
# 1. Handle measure "green roof"
6162
if (!is.na(measures$green_roof)) {
6263

6364
a_green_roof <- a_roof * blocks$green_roof
6465

6566
# Total green roof area to add (if value >= 0) or to remove (if value < 0)
66-
a_green_roof_change <- sum(measures$green_roof * a_total) - sum(a_green_roof)
67+
a_green_roof_change <- measures$green_roof * a_total_sum - sum(a_green_roof)
6768

6869
# Roof area that can be converted to green roof area
6970
if (a_green_roof_change >= 0) {
@@ -106,7 +107,7 @@ apply_measures_to_blocks <- function(blocks, measures, dbg = FALSE, check = FALS
106107
a_unpaved <- a_total - a_roof - a_paved
107108

108109
# Required increase/decrease in unpaved area
109-
a_unpaved_change <- measures$unpaved * sum(a_total) - sum(a_unpaved)
110+
a_unpaved_change <- measures$unpaved * a_total_sum - sum(a_unpaved)
110111
unpave <- a_unpaved_change >= 0
111112

112113
debug(sprintf(
@@ -151,7 +152,7 @@ apply_measures_to_blocks <- function(blocks, measures, dbg = FALSE, check = FALS
151152
if (!is.na(measures$to_swale)) {
152153
a_sealed <- a_roof + a_total * blocks$pvd
153154
a_to_swale <- blocks$to_swale * a_sealed
154-
a_to_swale_change <- sum(measures$to_swale * a_total) - sum(a_to_swale)
155+
a_to_swale_change <- measures$to_swale * a_total_sum - sum(a_to_swale)
155156

156157
increase <- a_to_swale_change >= 0
157158

0 commit comments

Comments
 (0)