Skip to content

Commit b42db34

Browse files
committed
Apply JMA Style naming
1 parent 6ddd79c commit b42db34

11 files changed

Lines changed: 162 additions & 127 deletions

File tree

asset-preprocessor/src/parse_shapefile.rs

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Please follow:
7979
}
8080

8181
struct AreaRings {
82-
area_code: codes::Area,
82+
地震情報細分区域: codes::地震情報細分区域,
8383
bounding_box: BoundingBox<GeoDegree>,
8484
rings: Vec<Ring>,
8585
}
@@ -89,14 +89,17 @@ impl AreaRings {
8989
let Shape::Polygon(polygon) = shape else {
9090
return None;
9191
};
92-
let area_code: codes::Area = match record.get("code").unwrap() {
92+
93+
let 地震情報細分区域: codes::地震情報細分区域 = match record.get("code").unwrap() {
9394
FieldValue::Character(Some(c)) => match c.parse() {
94-
Ok(c) => c,
95+
Ok(c) => codes::地震情報細分区域(c),
9596
Err(_) => panic!("コワッ…コワれたshapefileきた!"),
9697
},
97-
FieldValue::Character(None) => codes::UNNUMBERED_AREA, // 北方領土・諸外国等がNoneになる
98+
99+
FieldValue::Character(None) => codes::地震情報細分区域::UNNUMBERED, // 北方領土・諸外国等がNoneになる
98100
_ => panic!("知らないshapefileきた?🤔"),
99101
};
102+
100103
let bounding_box = (*polygon.bbox()).into();
101104
let rings = polygon
102105
.rings()
@@ -105,7 +108,7 @@ impl AreaRings {
105108
.collect();
106109

107110
Some(Self {
108-
area_code,
111+
地震情報細分区域,
109112
bounding_box,
110113
rings,
111114
})
@@ -119,20 +122,20 @@ pub(crate) struct PointReferences<'a> {
119122
impl<'a> PointReferences<'a> {
120123
fn tally_of(
121124
shapefile: &'a Shapefile,
122-
area_to_pref: &'a HashMap<codes::Area, codes::Pref>,
125+
area_to_pref: &'a HashMap<codes::地震情報細分区域, codes::地震情報都道府県等>,
123126
) -> Self {
124127
let mut map: HashMap<Point, PointReference> = HashMap::new();
125128

126129
shapefile.entries.iter().for_each(|area_rings| {
127-
let area_code = area_rings.area_code;
130+
let 地震情報細分区域 = area_rings.地震情報細分区域;
128131

129132
area_rings.rings.iter().for_each(|ring| {
130133
ring.iter_adjacent_points().for_each(|point_set| {
131134
let reference = map
132135
.entry(point_set.current)
133136
.or_insert(PointReference::new(area_to_pref));
134137

135-
reference.mark_area(area_code);
138+
reference.mark_area(地震情報細分区域);
136139
reference.mark_point(point_set.previous);
137140
reference.mark_point(point_set.next);
138141
});
@@ -162,38 +165,41 @@ impl<'a> PointReferences<'a> {
162165
}
163166

164167
pub(crate) struct PointReference<'a> {
165-
area_to_pref: &'a HashMap<codes::Area, codes::Pref>,
166-
areas: HashSet<codes::Area>,
168+
area_to_pref: &'a HashMap<codes::地震情報細分区域, codes::地震情報都道府県等>,
169+
areas: HashSet<codes::地震情報細分区域>,
167170
adjacent_points: HashSet<Point>,
168171
}
169172

170173
impl<'a> PointReference<'a> {
171-
fn new(area_to_pref: &'a HashMap<codes::Area, codes::Pref>) -> Self {
174+
fn new(
175+
area_to_pref: &'a HashMap<codes::地震情報細分区域, codes::地震情報都道府県等>
176+
) -> Self {
172177
Self {
173178
area_to_pref,
174179
areas: HashSet::new(),
175180
adjacent_points: HashSet::new(),
176181
}
177182
}
178183

179-
fn mark_area(&mut self, area: codes::Area) {
184+
fn mark_area(&mut self, area: codes::地震情報細分区域) {
180185
self.areas.insert(area);
181186
}
182187

183188
fn mark_point(&mut self, point: Point) {
184189
self.adjacent_points.insert(point);
185190
}
186191

187-
fn area_references(&self) -> &HashSet<codes::Area> {
192+
fn area_references(&self) -> &HashSet<codes::地震情報細分区域> {
188193
&self.areas
189194
}
190195

191-
pub(crate) fn pref_references(&self) -> HashSet<codes::Pref> {
196+
pub(crate) fn pref_references(&self) -> HashSet<codes::地震情報都道府県等> {
192197
let areas = self
193198
.area_references()
194199
.iter()
195-
.filter(|a| **a != codes::UNNUMBERED_AREA)
200+
.filter(|a| **a != codes::地震情報細分区域::UNNUMBERED)
196201
.map(|a| *self.area_to_pref.get(a).unwrap());
202+
197203
HashSet::from_iter(areas)
198204
}
199205

@@ -202,15 +208,18 @@ impl<'a> PointReference<'a> {
202208
}
203209
}
204210
pub fn read(
205-
#[allow(non_snake_case)] area_code__pref_code: &HashMap<codes::Area, codes::Pref>,
211+
#[allow(non_snake_case)] area_code__pref_code: &HashMap<
212+
codes::地震情報細分区域,
213+
codes::地震情報都道府県等,
214+
>,
206215
) -> (
207-
HashMap<codes::Area, BoundingBox<GeoDegree>>, // area_bounding_box
208-
HashMap<codes::Area, Vertex<GeoDegree>>, // area_centers
209-
Vec<(f32, f32)>, // vertex_buffer
210-
Vec<u32>, // map_indices
211-
Vec<Vec<u32>>, // area_lines
212-
Vec<Vec<u32>>, // pref_lines
213-
Vec<(f32, usize)>, // scale_level_map
216+
HashMap<codes::地震情報細分区域, BoundingBox<GeoDegree>>, // area_bounding_box
217+
HashMap<codes::地震情報細分区域, Vertex<GeoDegree>>, // area_centers
218+
Vec<(f32, f32)>, // vertex_buffer
219+
Vec<u32>, // map_indices
220+
Vec<Vec<u32>>, // area_lines
221+
Vec<Vec<u32>>, // pref_lines
222+
Vec<(f32, usize)>, // scale_level_map
214223
) {
215224
let shapefile = Shapefile::new(
216225
"../assets/shapefile/earthquake_detailed/earthquake_detailed_simplified.shp",
@@ -220,21 +229,24 @@ pub fn read(
220229

221230
// @Siro_256 にゃ~っ…! (ΦωΦ)
222231

223-
let area_centers = calculate_area_centers(&shapefile);
232+
let 地震情報細分区域_centers = calculate_地震情報細分区域_centers(&shapefile);
224233

225-
let area_bounding_box: HashMap<codes::Area, BoundingBox<GeoDegree>> = shapefile
226-
.entries
227-
.iter()
228-
.filter(|area_rings| area_rings.area_code != codes::UNNUMBERED_AREA)
229-
.map(|area_rings| (area_rings.area_code, area_rings.bounding_box))
230-
.collect();
234+
let 地震情報細分区域_bounding_box: HashMap<codes::地震情報細分区域, BoundingBox<GeoDegree>> =
235+
shapefile
236+
.entries
237+
.iter()
238+
.filter(|rings| {
239+
rings.地震情報細分区域 != codes::地震情報細分区域::UNNUMBERED
240+
})
241+
.map(|rings| (rings.地震情報細分区域, rings.bounding_box))
242+
.collect();
231243

232244
let map_indices = shapefile
233245
.entries
234246
.iter()
235-
.flat_map(|area_rings| &area_rings.rings)
236-
.flat_map(|r| r.triangulate())
237-
.map(|p| vertex_buffer.insert(p.into()) as u32)
247+
.flat_map(|rings| &rings.rings)
248+
.flat_map(|ring| ring.triangulate())
249+
.map(|point| vertex_buffer.insert(point.into()) as u32)
238250
.collect();
239251

240252
let references = PointReferences::tally_of(&shapefile, area_code__pref_code);
@@ -322,8 +334,8 @@ pub fn read(
322334
// (ΦωΦ) < Meow !
323335
{
324336
(
325-
area_bounding_box,
326-
area_centers,
337+
地震情報細分区域_bounding_box,
338+
地震情報細分区域_centers,
327339
vertex_buffer.into_buffer(),
328340
map_indices,
329341
area_lines,
@@ -400,58 +412,60 @@ fn gen_lod(
400412
.collect()
401413
}
402414

403-
fn calculate_area_centers(shapefile: &Shapefile) -> HashMap<codes::Area, Vertex<GeoDegree>> {
415+
fn calculate_地震情報細分区域_centers(
416+
shapefile: &Shapefile,
417+
) -> HashMap<codes::地震情報細分区域, Vertex<GeoDegree>> {
404418
use geo::{
405419
algorithm::{Area, Centroid},
406420
LineString, Polygon,
407421
};
408422

409-
let area_weighted_vectors: HashMap<codes::Area, Vec<(f64, geo::Point)>> = shapefile
423+
let weighted_vectors: HashMap<codes::地震情報細分区域, Vec<(f64, geo::Point)>> = shapefile
410424
.entries
411425
.iter()
412-
.filter(|area_rings| area_rings.area_code != codes::UNNUMBERED_AREA)
413-
.map(|area_rings| {
414-
let area_polygons: Vec<(f64, geo::Point)> = area_rings
426+
.filter(|rings| rings.地震情報細分区域 != codes::地震情報細分区域::UNNUMBERED)
427+
.map(|rings| {
428+
let polygons: Vec<(f64, geo::Point)> = rings
415429
.rings
416430
.iter()
417431
.map(|ring| LineString::new(ring.points().iter().map(|p| p.into()).collect_vec()))
418432
.map(|geo_line_string| Polygon::new(geo_line_string, vec![]))
419433
.map(|geo_polygon| (geo_polygon.unsigned_area(), geo_polygon.centroid().unwrap()))
420434
.collect();
421435

422-
(area_rings.area_code, area_polygons)
436+
(rings.地震情報細分区域, polygons)
423437
})
424438
.collect();
425439

426-
let area_centers: HashMap<codes::Area, Point> = area_weighted_vectors
440+
let centers: HashMap<codes::地震情報細分区域, Point> = weighted_vectors
427441
.into_iter()
428-
.map(|(area_code, weighted_vectors)| {
429-
let area_weight: f64 = weighted_vectors
442+
.map(|(地震情報細分区域, weighted_vectors)| {
443+
let weight: f64 = weighted_vectors
430444
.iter()
431445
.map(|(weight, _vector)| weight)
432446
.sum();
433447

434-
let area_vector: Point = weighted_vectors
448+
let vector: Point = weighted_vectors
435449
.iter()
436450
.map(|(weight, vector)| {
437451
let vector: Point = vector.into();
438452
vector.multiply_by(*weight as f32)
439453
})
440454
.fold(Point::new(0.0.into(), 0.0.into()), |a, b| a + b);
441455

442-
(area_code, area_vector.divide_by(area_weight as f32))
456+
(地震情報細分区域, vector.divide_by(weight as f32))
443457
})
444458
.collect();
445459

446-
let area_centers: HashMap<codes::Area, Vertex<GeoDegree>> = area_centers
460+
let centers: HashMap<codes::地震情報細分区域, Vertex<GeoDegree>> = centers
447461
.into_iter()
448-
.map(|(area_code, center)| {
462+
.map(|(code, center)| {
449463
(
450-
area_code,
464+
code,
451465
Vertex::new(center.latitude.into(), center.longitude.into()),
452466
)
453467
})
454468
.collect();
455469

456-
area_centers
470+
centers
457471
}

asset-preprocessor/src/parse_tsunami_shapefile.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl VertexBuffer {
7272

7373
struct AreaLines {
7474
lines: Vec<Line>,
75-
tsunami_area_code: codes::TsunamiArea,
75+
津波予報区: codes::津波予報区,
7676
}
7777

7878
impl AreaLines {
@@ -81,17 +81,16 @@ impl AreaLines {
8181
return None;
8282
};
8383

84-
let tsunami_area_code: codes::TsunamiArea = match record.get("code").unwrap() {
84+
let 津波予報区: codes::津波予報区 = match record.get("code").unwrap() {
8585
FieldValue::Character(Some(c)) => match c.parse() {
86-
Ok(c) => c,
86+
Ok(c) => codes::津波予報区(c),
8787
Err(_) => panic!("Failed to parse code"),
8888
},
8989
FieldValue::Character(None) => panic!("UNNUMBERED_AREA DETECTED!"),
9090
_ => panic!("Failed to get code"),
9191
};
9292

93-
// 帰属未定 (極小の島など)
94-
if tsunami_area_code == 0 {
93+
if 津波予報区 == codes::津波予報区::帰属未定 {
9594
return None;
9695
}
9796

@@ -103,7 +102,7 @@ impl AreaLines {
103102

104103
Some(Self {
105104
lines,
106-
tsunami_area_code,
105+
津波予報区,
107106
})
108107
}
109108
}
@@ -167,7 +166,7 @@ pub fn read() -> (
167166
vertex_buffer.insert((
168167
Of32::from(v.longitude),
169168
Of32::from(v.latitude),
170-
tsunami_area_code_buffer.insert(e.tsunami_area_code),
169+
tsunami_area_code_buffer.insert(e.津波予報区.0),
171170
)) as u32
172171
})
173172
.collect();

renderer-assets/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn main() {
6060
.expect("エリア内に一つも観測点がない");
6161

6262
(
63-
*code,
63+
code.0,
6464
(nearest_intensity_station_index, bbox_to_tuple(bbox)),
6565
)
6666
})

renderer-assets/src/lib.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,41 @@ impl QueryInterface {
4848
}
4949
}
5050

51-
pub fn is_valid_earthquake_area_code(area_code: codes::Area) -> bool {
52-
AREAS.contains_key(&area_code)
51+
pub fn is_valid_地震情報細分区域(code: codes::地震情報細分区域) -> bool {
52+
AREAS.contains_key(&code.0)
5353
}
5454

55-
pub fn is_valid_tsunami_area_code(area_code: codes::Area) -> bool {
56-
TSUNAMI_AREA_CODE_TO_INTERNAL_CODE.contains_key(&area_code)
55+
pub fn is_valid_津波予報区(code: codes::津波予報区) -> bool {
56+
TSUNAMI_AREA_CODE_TO_INTERNAL_CODE.contains_key(&code.0)
5757
}
5858

59-
pub fn tsunami_area_code_to_internal_code(area_code: codes::TsunamiArea) -> Option<u16> {
60-
TSUNAMI_AREA_CODE_TO_INTERNAL_CODE.get(&area_code).copied()
59+
pub fn 津波予報区_to_internal_tsunami_area_code(
60+
code: codes::津波予報区,
61+
) -> Option<codes::InternalTsunamiAreaCode> {
62+
TSUNAMI_AREA_CODE_TO_INTERNAL_CODE
63+
.get(&code.0)
64+
.map(|code| codes::InternalTsunamiAreaCode(*code))
6165
}
6266

63-
pub fn tsunami_area_code_count() -> usize {
67+
pub fn internal_tsunami_area_code_count() -> usize {
6468
TSUNAMI_AREA_CODE_TO_INTERNAL_CODE.len()
6569
}
6670

67-
pub fn query_bounding_box_by_area(area_code: codes::Area) -> Option<BoundingBox<GeoDegree>> {
68-
let tuple = AREAS.get(&area_code)?.1;
71+
pub fn query_bounding_box_by_地震情報細分区域(code: codes::地震情報細分区域) -> Option<BoundingBox<GeoDegree>> {
72+
let tuple = AREAS.get(&code.0)?.1;
6973
let min = Vertex::new(tuple.0, tuple.1);
7074
let max = Vertex::new(tuple.2, tuple.3);
7175
Some(BoundingBox::new(min, max))
7276
}
7377

74-
pub fn query_rendering_center_by_area(area_code: codes::Area) -> Option<Vertex<GeoDegree>> {
75-
Some(INTENSITY_STATION_POSITIONS[AREAS.get(&area_code)?.0].into())
78+
pub fn query_intensity_icon_center_by_地震情報細分区域(code: codes::地震情報細分区域) -> Option<Vertex<GeoDegree>> {
79+
Some(INTENSITY_STATION_POSITIONS[AREAS.get(&code.0)?.0].into())
7680
}
7781

7882
pub fn query_position_by_station_code(
79-
intensity_station_code: codes::IntensityStation,
83+
code: codes::震度観測点,
8084
) -> Option<Vertex<GeoDegree>> {
81-
Some(INTENSITY_STATION_POSITIONS[*STATION_CODES.get(&intensity_station_code)?].into())
85+
Some(INTENSITY_STATION_POSITIONS[*STATION_CODES.get(&code.0)?].into())
8286
}
8387

8488
pub fn query_lod_level_by_scale(scale: f32) -> Option<usize> {

0 commit comments

Comments
 (0)