diff --git a/Cargo.lock b/Cargo.lock index 5f11ea3..b1213d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aes" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "aho-corasick" version = "1.0.1" @@ -67,6 +78,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bindgen" version = "0.59.2" @@ -96,6 +113,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.12.2" @@ -114,6 +140,27 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "cairo-rs" version = "0.17.0" @@ -145,6 +192,9 @@ name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +dependencies = [ + "jobserver", +] [[package]] name = "cexpr" @@ -195,6 +245,8 @@ dependencies = [ "glib", "glib-build-tools", "gtk4", + "npyz", + "num-traits", "plotters", "plotters-backend", "proj", @@ -202,6 +254,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "clang-sys" version = "1.6.1" @@ -249,6 +311,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed3d0b5ff30645a68f35ece8cea4556ca14ef8a1651455f789a099a0513532a6" +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + [[package]] name = "core-foundation" version = "0.9.3" @@ -302,6 +370,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.3.2" @@ -311,6 +388,25 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "dbase" version = "0.3.0" @@ -321,6 +417,17 @@ dependencies = [ "time 0.3.21", ] +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + [[package]] name = "dirs-next" version = "2.0.0" @@ -613,6 +720,16 @@ dependencies = [ "system-deps", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "geo-macros" version = "0.1.0" @@ -890,6 +1007,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + [[package]] name = "humantime" version = "2.1.0" @@ -944,6 +1070,24 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "jobserver" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +dependencies = [ + "libc", +] + [[package]] name = "jpeg-decoder" version = "0.3.0" @@ -1052,6 +1196,38 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "npyz" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80581878bc671c9c832a199569fdb6696a1948b32346a8095c939d12a1946178" +dependencies = [ + "byteorder", + "num-bigint", + "py_literal", + "zip", +] + +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" +dependencies = [ + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1115,6 +1291,17 @@ dependencies = [ "system-deps", ] +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + [[package]] name = "pathfinder_geometry" version = "0.5.1" @@ -1134,6 +1321,18 @@ dependencies = [ "rustc_version 0.3.3", ] +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", + "hmac", + "password-hash", + "sha2", +] + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -1150,6 +1349,40 @@ dependencies = [ "ucd-trie", ] +[[package]] +name = "pest_derive" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b79d4c71c865a25a4322296122e3924d30bc8ee0834c8bfc8b95f7f054afbfb" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c435bf1076437b851ebc8edc3a18442796b30f1728ffea6262d59bbe28b077e" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn 2.0.16", +] + +[[package]] +name = "pest_meta" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "745a452f8eb71e39ffd8ee32b3c5f51d03845f99786fa9b68db6ff509c505411" +dependencies = [ + "once_cell", + "pest", + "sha2", +] + [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1291,6 +1524,19 @@ dependencies = [ "tar", ] +[[package]] +name = "py_literal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "102df7a3d46db9d3891f178dcc826dc270a6746277a9ae6436f8d29fd490a8e1" +dependencies = [ + "num-bigint", + "num-complex", + "num-traits", + "pest", + "pest_derive", +] + [[package]] name = "quote" version = "1.0.27" @@ -1300,6 +1546,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + [[package]] name = "redox_syscall" version = "0.2.16" @@ -1423,6 +1675,28 @@ dependencies = [ "serde", ] +[[package]] +name = "sha1" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + [[package]] name = "shapefile" version = "0.4.0" @@ -1467,6 +1741,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + [[package]] name = "syn" version = "1.0.109" @@ -1624,6 +1904,12 @@ version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + [[package]] name = "ucd-trie" version = "0.1.5" @@ -1917,3 +2203,53 @@ dependencies = [ "once_cell", "pkg-config", ] + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "aes", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2", + "sha1", + "time 0.3.21", + "zstd", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.8+zstd.1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +dependencies = [ + "cc", + "libc", + "pkg-config", +] diff --git a/Cargo.toml b/Cargo.toml index 3e314eb..7ad7d6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,8 @@ plotters-backend = { path = "../plotters/plotters-backend" } geo-types = "0.7.9" shapefile = { version = "0.4", features = ["geo-types"] } thiserror = "1.0.40" +num-traits = "0.2.15" +npyz = { version = "0.8.0", features = ["npz"] } [build-dependencies] glib-build-tools = "0.17.0" diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..6c7cb2e --- /dev/null +++ b/readme.md @@ -0,0 +1,6 @@ +| 插入方式 | 描述 | 旋转方式 | +| -------- | ----------------------------------------------- | ------------ | +| LL | 在 A 的左子树根节点的左子树上插入节点而破坏平衡 | 右旋转 | +| RR | 在 A 的右子树根节点的右子树上插入节点而破坏平衡 | 左旋转 | +| LR | 在A的左子树根节点的右子树上插入节点而破坏平衡 | 先左旋后右旋 | +| RL | 在 A 的右子树根节点的左子树上插入节点而破坏平衡 | 先右旋后左旋 | \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6c605f4..85b525f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,11 +14,13 @@ use shapefile; use gtk::{prelude::*, DrawingArea}; use proj::Proj; // use plotters::prelude::{ChartBuilder, IntoDrawingArea, Rectangle}; +use npyz::npz::{self, NpzArchive}; use plotters::style::{HSLColor, BLACK, WHITE}; // use plotters::prelude::DrawingArea; use window::Window; mod backend; mod painter; +mod trees; mod window; const APP_ID: &str = "org.gtk_rs.HelloWorld2"; @@ -51,6 +53,14 @@ fn build_ui(app: &Application) { root.fill(&WHITE); + use trees::get; + + let mut npz_file = NpzArchive::open("/Users/ruomu/test.npz").unwrap(); + + // let value = npz_file.by_name("value").unwrap().unwrap(); + let lon = npz_file.by_name("lon").unwrap().unwrap(); + // let lat = npz_file.by_name("lat").unwrap().unwrap(); + let mut polygons: Vec<(shapefile::Polygon, _)> = shapefile::read_as::<_, shapefile::Polygon, shapefile::dbase::Record>( "/Users/ruomu/china/省界_region.shp", @@ -59,45 +69,52 @@ fn build_ui(app: &Application) { let (polygon, polygon_record) = polygons.first_mut().unwrap(); - let from = "EPSG:4326"; - let to = "EPSG:3857"; - let ft = Proj::new_known_crs(from, to, None).unwrap(); - let proj = Mercator::new().change_min_latitude(-80f64); let mut chart = ChartBuilder::on(&root) .build_geo_coord( Some(std::ops::Range { - start: 73.0, - end: 135.0, + start: 119.0, + end: 121.0, }), Some(std::ops::Range { - start: 4.0, - end: 53.5, + start: 29.0, + end: 30.0, }), proj, ) .unwrap(); - chart.draw_mesh_lines( - (10, 5), - (true, true), - &ShapeStyle { - color: RGBAColor(0, 0, 0, 1f64), - filled: false, - stroke_width: 1, - }, - ); - - // chart - // // .configure_mesh() - // // .disable_x_mesh() - // // .disable_y_mesh() - // .draw() - // .unwrap(); + // chart.draw_mesh_lines( + // (10, 5), + // (true, true), + // &ShapeStyle { + // color: RGBAColor(0, 0, 0, 1f64), + // filled: false, + // stroke_width: 1, + // }, + // ); let ring = polygon.ring(0).unwrap(); + chart.draw_series( + lon.into_vec::().unwrap().into_iter().map(|lon| { + Rectangle::new([(lon, 29.1), (lon + 0.001, 29.1 + 0.001)], BLACK.filled()) + }), + ); + + // chart.draw_series(lon.into_vec::().unwrap().into_iter().map(|lon| { + // lat.into_vec::().unwrap().into_iter().map(|lat| { + // Rectangle::new( + // [ + // (lon as f64, lat as f64), + // (lon as f64 + 0.001, lat as f64 + 0.001), + // ], + // BLACK.filled(), + // ) + // }) + // })); + for (polygon, _) in polygons.into_iter() { chart .draw_series( diff --git a/src/trees.rs b/src/trees.rs new file mode 100644 index 0000000..2344a3c --- /dev/null +++ b/src/trees.rs @@ -0,0 +1,22 @@ +use num_traits::Num; +use plotters::style::RGBAColor; +pub fn get(levels: &Vec, colors: &Vec, v: T) -> RGBAColor +where + T: Num + PartialOrd, +{ + let len = levels.len(); + + let mut left = 0; + let mut right = len - 1; + + while left < right - 1 { + let middle = (right + left) / 2; + if v > levels[middle] { + left = middle; + } else { + right = middle; + } + } + + colors[left] +}