Verified Commit ad520e1e authored by Pascal Engélibert's avatar Pascal Engélibert 🚴
Browse files

Place new idties at certifiers barycenter

parent cc28c3ba
......@@ -267,6 +267,7 @@ impl<C: 'static + Debug + blockchain::Config, R: 'static + BcReader<C>> Gexplore
layout_module: &mut ResMut<LayoutModule>,
polylines: &mut ResMut<Assets<Polyline>>,
asset_handles: &Res<AssetHandles>,
query_idty: &mut Query<(&state::IdtyId, &Transform)>,
) {
let mut rng = rand::thread_rng();
let node_spawn_distrib = rand::distributions::Uniform::<f32>::new(-1.0, 1.0);
......@@ -285,16 +286,37 @@ impl<C: 'static + Debug + blockchain::Config, R: 'static + BcReader<C>> Gexplore
.id(),
);
let nb_idties = layout_module.idty_map.len();
layout_module.layout.add_nodes(
&[],
forceatlas2::Nodes::Degree(1),
&[
node_spawn_distrib.sample(&mut rng),
node_spawn_distrib.sample(&mut rng),
node_spawn_distrib.sample(&mut rng),
],
None,
);
// Place new idty at its certifiers' barycenter
let mut pos = [
node_spawn_distrib.sample(&mut rng),
node_spawn_distrib.sample(&mut rng),
node_spawn_distrib.sample(&mut rng),
];
let mut nb_certifiers: usize = 0;
for cert in changeset.new_certs.iter() {
let cert = cert.value();
if cert.receiver == idty_id {
if let Some(issuer) = entities.idties.get(&cert.issuer) {
if let Ok(issuer) = query_idty.get(*issuer) {
nb_certifiers += 1;
pos[0] += issuer.1.translation[0];
pos[1] += issuer.1.translation[1];
pos[2] += issuer.1.translation[2];
}
}
}
}
if nb_certifiers > 0 {
let nb_certifiers = nb_certifiers as f32;
pos[0] /= nb_certifiers;
pos[1] /= nb_certifiers;
pos[2] /= nb_certifiers;
}
layout_module
.layout
.add_nodes(&[], forceatlas2::Nodes::Degree(1), &pos, None);
layout_module.idty_map.insert(idty_id, nb_idties);
}
for (cert_id, cert) in changeset.new_certs {
......@@ -381,6 +403,7 @@ impl<C: 'static + Debug + blockchain::Config, R: 'static + BcReader<C>> Gexplore
mut meshes: ResMut<Assets<Mesh>>,
mut query_idty_material: Query<(&state::IdtyId, &mut Handle<StandardMaterial>)>,
mut query_idty_mesh: Query<(&state::IdtyId, &mut Handle<Mesh>)>,
mut query_idty_transform: Query<(&state::IdtyId, &Transform)>,
mut query_cert: Query<(&state::CertId, &mut PolylineMaterial)>,
mut measure_idty_list: ResMut<measure::idty::MeasureIdtyList>,
mut measure_cert_list: ResMut<measure::cert::MeasureCertList>,
......@@ -530,6 +553,7 @@ impl<C: 'static + Debug + blockchain::Config, R: 'static + BcReader<C>> Gexplore
&mut layout_module,
&mut polylines,
&asset_handles,
&mut query_idty_transform,
);
}
}
......@@ -542,6 +566,7 @@ impl<C: 'static + Debug + blockchain::Config, R: 'static + BcReader<C>> Gexplore
&mut layout_module,
&mut polylines,
&asset_handles,
&mut query_idty_transform,
);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment