Factor out Model to mercator_db

This commit is contained in:
2019-09-09 14:28:15 +02:00
parent 2a718d6c88
commit ba40556aee
5 changed files with 349 additions and 69 deletions

View File

@@ -1,32 +1,14 @@
#[macro_use]
extern crate serde_derive;
mod storage;
use rand::distributions::Distribution;
use rand::distributions::Uniform;
use rand::prelude::ThreadRng;
use std::fs::File;
use std::io::BufWriter;
use mercator_db::json::model::*;
use rand::distributions::Distribution;
use rand::distributions::Uniform;
use rand::prelude::ThreadRng;
use serde::Serialize;
use storage::*;
const POSITIONS_PER_SHAPE: usize = 1000;
impl SpatialObject {
pub fn new(shapes: Vec<Shape>, id: String) -> Self {
SpatialObject {
shapes,
properties: Properties {
type_name: "Feature".to_string(),
id,
},
}
}
}
fn get_reference_space() -> Vec<Space> {
vec![Space {
name: "std".to_string(),
@@ -96,7 +78,13 @@ fn get_point(space_name: &str, rng: &mut ThreadRng, die: &Uniform<f64>) -> Spati
});
}
SpatialObject::new(shapes, format!("oid{}", die.sample(rng)))
SpatialObject {
properties: Properties {
type_name: "Feature".to_string(),
id: format!("oid{}", die.sample(rng)),
},
shapes,
}
}
fn get_space(nb_points: usize, rng: &mut ThreadRng, die: &Uniform<f64>) {

View File

@@ -1,45 +0,0 @@
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Space {
pub name: String,
pub origin: Vec<f64>,
pub axes: Vec<Axis>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Axis {
pub measurement_unit: String,
pub graduation: Graduation,
pub unit_vector: Vec<f64>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Graduation {
pub set: String,
pub minimum: f64,
pub maximum: f64,
pub steps: u64,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SpatialObject {
pub properties: Properties,
pub shapes: Vec<Shape>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Shape {
#[serde(rename = "type")]
pub type_name: String,
#[serde(rename = "space")]
pub reference_space: String,
pub vertices: Vec<Point>,
}
type Point = Vec<f64>;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Properties {
#[serde(rename = "type")]
pub type_name: String,
pub id: String,
}