Skip to content

Commit

Permalink
remove rust warning, fix rust compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatthieu3 committed Sep 11, 2024
1 parent 424c3ce commit 16f9788
Show file tree
Hide file tree
Showing 25 changed files with 118 additions and 139 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* [feat] Add support for name removing in `removeOverlay` method
* [test] Add support of playwright. Instructions in the readme for running the test matching snapshots [PR #176]
* [fixed] Order of overlays in the stack now matches the addMOC/addCatalog/addOverlay calls ordering

## 3.5.0-beta

Expand Down
2 changes: 1 addition & 1 deletion examples/al-cfht.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import A from '../src/js/A.js';
let aladin;
A.init.then(() => {
aladin = A.aladin('#aladin-lite-div', {survey: "data/hips/PanSTARRS_DR1_color-z-zg-g", fov:2.0, target: "NGC 7318B", showSettingsControl: true, log: false});
aladin = A.aladin('#aladin-lite-div', {survey: "data/hips/PanSTARRS_DR1_color-z-zg-g", fov:2.0, target: "22 35 58.39 +33 57 57.8", showSettingsControl: true, log: false});
aladin.setProjection('AIT');
let cfht = aladin.createImageSurvey("CFHT", "CFHT MegaCam u+g+r", "./data/hips/CFHT", "equatorial", 10, {imgFormat: 'png'});
let jwst1 = aladin.createImageSurvey("CDS/P/JWST/Stephans-Quintet/NIRCam+MIRI", "JWST NIRCam+MIRI", "data/hips/JWST_NIRCam_MIRI", null, null, {imgFormat: 'png'});
Expand Down
2 changes: 1 addition & 1 deletion src/core/al-api/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::Deserialize;
pub struct Resources(HashMap<String, String>);

impl Resources {
pub fn get_filename<'a>(&'a self, name: &str) -> Option<&String> {
pub fn get_filename(&self, name: &str) -> Option<&String> {
self.0.get(name)
}
}
2 changes: 0 additions & 2 deletions src/core/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use crate::{
tile_fetcher::TileFetcherQueue,
time::DeltaTime,
};
use al_core::log::console_log;
use std::sync::{Arc, Mutex};
use wcs::WCS;

use wasm_bindgen::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/camera/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ use wasm_bindgen::JsCast;

const MAX_DPI_LIMIT: f32 = 3.0;
use crate::math;
use crate::time::{DeltaTime, Time};
use crate::time::Time;
use crate::Abort;
use crate::ArcDeg;
impl CameraViewPort {
Expand Down
9 changes: 1 addition & 8 deletions src/core/src/downloader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod query;
pub mod request;


use std::collections::HashSet;

use query::QueryId;
Expand Down Expand Up @@ -98,13 +97,7 @@ impl Downloader {
self.queried_list.contains(id)
}

//pub fn get_cached_resources(&mut self) -> Vec<Resource> {}

/*pub fn cache_rsc(&mut self, rsc: Resource) {
self.cache.insert(rsc.url().clone(), rsc);
}*/

pub fn delay_rsc(&mut self, rsc: Resource) {
pub fn _delay_rsc(&mut self, rsc: Resource) {
self.queried_cached_ids.push(rsc.id().clone());
self.cache.insert(rsc.id().clone(), rsc);
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/downloader/request/allsky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ impl From<query::Allsky> for AllskyRequest {
Ok(allsky_tiles)
}
_ => {
let mut opts = RequestInit::new();
opts.method("GET");
opts.mode(RequestMode::Cors);
let opts = RequestInit::new();
opts.set_method("GET");
opts.set_mode(RequestMode::Cors);
let window = web_sys::window().unwrap_abort();

let request = web_sys::Request::new_with_str_and_init(&url_clone, &opts)?;
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/downloader/request/blank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ impl From<query::PixelMetadata> for PixelMetadataRequest {
let request = match channel {
ChannelType::R32F | ChannelType::R32I | ChannelType::R16I | ChannelType::R8UI => {
Request::new(async move {
let mut opts = RequestInit::new();
opts.method("GET");
opts.mode(RequestMode::Cors);
let opts = RequestInit::new();
opts.set_method("GET");
opts.set_mode(RequestMode::Cors);

let request =
web_sys::Request::new_with_str_and_init(&url_clone, &opts).unwrap_abort();
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/downloader/request/moc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ impl From<query::Moc> for MOCRequest {

let window = web_sys::window().unwrap_abort();
let request = Request::new(async move {
let mut opts = RequestInit::new();
opts.method("GET");
opts.mode(RequestMode::Cors);
let opts = RequestInit::new();
opts.set_method("GET");
opts.set_mode(RequestMode::Cors);

let request = web_sys::Request::new_with_str_and_init(&url_clone, &opts).unwrap_abort();
let resp_value = JsFuture::from(window.fetch_with_request(&request)).await?;
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/downloader/request/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ impl From<query::Tile> for TileRequest {
| ChannelType::R32I
| ChannelType::R16I
| ChannelType::R8UI => Request::new(async move {
let mut opts = RequestInit::new();
opts.method("GET");
opts.mode(RequestMode::Cors);
let opts = RequestInit::new();
opts.set_method("GET");
opts.set_mode(RequestMode::Cors);

let request =
web_sys::Request::new_with_str_and_init(&url_clone, &opts).unwrap_abort();
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/survey/bitvector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<const N: usize> BitVector<N> {
}

mod tests {
use super::BitVector;


#[test]
fn test_bitvector_basic_op() {
Expand Down
78 changes: 22 additions & 56 deletions src/core/src/tile_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ use std::cell::RefCell;
use std::collections::VecDeque;
use std::rc::Rc;

use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsCast;

use crate::utils;
const MAX_NUM_TILE_FETCHING: usize = 8;
const MAX_QUERY_QUEUE_LENGTH: usize = 100;

use wasm_bindgen::JsValue;

pub struct TileFetcherQueue {
// A stack of queries to fetch
queries: VecDeque<query::Tile>,
Expand All @@ -29,7 +23,7 @@ impl TileFetcherQueue {
let queries = VecDeque::new();
let base_tile_queries = Vec::new();
let tiles_fetched_time = Time::now();
let mut num_tiles_fetched = 0;
let num_tiles_fetched = 0;
Self {
queries,
base_tile_queries,
Expand Down Expand Up @@ -123,56 +117,28 @@ impl TileFetcherQueue {
// Request the allsky
downloader.borrow_mut().fetch(query::Allsky::new(cfg));
} else if cfg.get_min_depth_tile() == 0 {
let hips_cdid = cfg.get_creator_did().to_string();
let hips_url = cfg.get_root_url().to_string();
let hips_fmt = cfg.get_format();
let min_order = cfg.get_min_depth_texture();

let dl = downloader.clone();
#[cfg(target_arch = "wasm32")]
utils::set_timeout(
move || {
for tile_cell in crate::healpix::cell::ALLSKY_HPX_CELLS_D0 {
dl.borrow_mut().fetch(query::Tile::new(
tile_cell,
hips_cdid.clone(),
hips_url.clone(),
hips_fmt,
));
}
},
2_000,
);
}
/*else {
for texture_cell in crate::healpix::cell::ALLSKY_HPX_CELLS_D0 {
for cell in texture_cell.get_tile_cells(cfg.delta_depth()) {
let hips_url = cfg.get_root_url();
let format = cfg.get_format();
let query = query::Tile::new(&cell, hips_url.to_string(), format);
self.append_base_tile(query, downloader);
}
{
let hips_cdid = cfg.get_creator_did().to_string();
let hips_url = cfg.get_root_url().to_string();
let hips_fmt = cfg.get_format();
let min_order = cfg.get_min_depth_texture();

let dl = downloader.clone();
crate::utils::set_timeout(
move || {
for tile_cell in crate::healpix::cell::ALLSKY_HPX_CELLS_D0 {
dl.borrow_mut().fetch(query::Tile::new(
tile_cell,
hips_cdid.clone(),
hips_url.clone(),
hips_fmt,
));
}
},
2_000,
);
}
}*/

/*
let f = async move {
let mut cb = |resolve: js_sys::Function, reject: js_sys::Function| {
web_sys::window()
.unwrap()
.set_timeout_with_callback_and_timeout_and_arguments_0(&resolve, 3000);
};
let p = js_sys::Promise::new(&mut cb);
wasm_bindgen_futures::JsFuture::from(p).await.unwrap();
Ok(JsValue::from_bool(true))
};
let _ = wasm_bindgen_futures::future_to_promise(f);
*/
}
}
}
9 changes: 5 additions & 4 deletions src/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ pub(super) fn merge_overlapping_intervals(mut intervals: Vec<Range<usize>>) -> V
intervals
}

use std::cell::Cell;
use std::rc::Rc;
use wasm_bindgen::closure::{Closure, WasmClosureFnOnce};
use wasm_bindgen::JsCast;
/*
Execute a closure after some delay. This mimics the javascript built-in setTimeout procedure.
*/
Expand All @@ -108,6 +104,11 @@ pub(crate) fn set_timeout<F>(f: F, delay: i32)
where
F: 'static + FnOnce() -> (),
{
use std::cell::Cell;
use std::rc::Rc;
use wasm_bindgen::closure::Closure;
use wasm_bindgen::JsCast;

let timeout_id = Rc::new(Cell::new(0));
let t_id = timeout_id.clone();
let cb = Closure::once_into_js(move || {
Expand Down
10 changes: 3 additions & 7 deletions src/js/A.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { ProgressiveCat } from "./ProgressiveCat.js";
import { Source } from "./Source.js";
import { Coo } from "./libs/astro/coo.js";
import { URLBuilder } from "./URLBuilder.js";
import { ColorCfg } from './ColorCfg.js';
import { Footprint } from './Footprint.js';
import { Aladin } from "./Aladin.js";
import { ActionButton } from "./gui/Widgets/ActionButton.js";
Expand Down Expand Up @@ -280,10 +279,6 @@ A.circle = function (ra, dec, radiusDeg, options) {
return new Circle([ra, dec], radiusDeg, options);
};

A.footprint = function(shapes) {
return new Footprint(shapes)
};

/**
* Creates an ellipse shape
*
Expand Down Expand Up @@ -389,8 +384,9 @@ A.coo = function (longitude, latitude, prec) {
* @memberof A
* @name footprint
*
* @param {A.polygon[]} shapes - an array of A.polygon objects
* @param {A.source} source - a A.source object
* @param {Circle[]|Polyline[]|Ellipse[]|Vector[]} shapes - an array of A.polygon objects
* @param {Source} [source] - a A.source object associated with the footprint
*
* @returns {Footprint} Returns a new Footprint object
*/
A.footprint = function(shapes, source) {
Expand Down
2 changes: 2 additions & 0 deletions src/js/Aladin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,8 @@ export let Aladin = (function () {

Aladin.prototype.addMOC = function (moc) {
this.view.addMOC(moc);

// see MOC.setView for sending it to outside the UI
};

Aladin.prototype.addUI = function (ui) {
Expand Down
20 changes: 14 additions & 6 deletions src/js/Catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,19 @@ export let Catalog = (function () {
if (shapes) {
shapes = [].concat(shapes);

// 1. return of the shape func is an image
if (shapes.length == 1 && (shapes[0] instanceof Image || shapes[0] instanceof HTMLCanvasElement)) {
source.setImage(shapes[0]);
// 2. return of the shape is a set of shapes or a footprint
} else {
shapes = new Footprint(shapes, source);
let footprint;
if (shapes.length == 1 && shapes[0] instanceof Footprint) {
footprint = shapes[0];
} else {
footprint = new Footprint(shapes, source);
}

let footprint = shapes;
this._shapeIsFootprintFunction = true;

footprint.setCatalog(this);

// store the footprints
Expand All @@ -596,6 +601,7 @@ export let Catalog = (function () {
}
} catch (e) {
// do not create the footprint
console.warn("Return of shape function could not be interpreted as a footprint");
continue;
}
}
Expand Down Expand Up @@ -699,8 +705,12 @@ export let Catalog = (function () {
}
};

Catalog.prototype.setView = function (view) {
Catalog.prototype.setView = function (view, idx) {
this.view = view;

this.view.catalogs.push(this);
this.view.insertOverlay(this, idx);

this.reportChange();
};

Expand Down Expand Up @@ -895,8 +905,6 @@ export let Catalog = (function () {

f.draw(ctx, this.view);
f.source.tooSmallFootprint = f.isTooSmall();
// propagate the info that the footprint is too small
//f.source.tooSmallFootprint = f.isTooSmall
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/js/Footprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export let Footprint= (function() {
return this.shapes.some((shape) => shape.isInStroke(ctx, view, x, y));
};

Footprint.prototype.isTooSmall = function(view) {
Footprint.prototype.isTooSmall = function() {
return this.shapes.every((shape) => shape.isTooSmall);
};

Expand Down
4 changes: 2 additions & 2 deletions src/js/MOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export let MOC = (function() {
this.errorCallback = errorCallback;
};

MOC.prototype.setView = function(view) {
MOC.prototype.setView = function(view, idx) {
let self = this;

this.view = view;
Expand Down Expand Up @@ -160,7 +160,7 @@ export let MOC = (function() {

// Add it to the view
self.view.mocs.push(self);
self.view.allOverlayLayers.push(self);
self.view.insertOverlay(self, idx);

// Tell the MOC has been fully loaded and can be sent as an event
ALEvent.GRAPHIC_OVERLAY_LAYER_ADDED.dispatchedTo(self.view.aladinDiv, {layer: self});
Expand Down
6 changes: 5 additions & 1 deletion src/js/Overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ export let GraphicOverlay = (function() {
}
};

GraphicOverlay.prototype.setView = function(view) {
GraphicOverlay.prototype.setView = function(view, idx) {
console.trace()
this.view = view;

this.view.overlays.push(this);
this.view.insertOverlay(this, idx);
};

GraphicOverlay.prototype.removeAll = function() {
Expand Down
Loading

0 comments on commit 16f9788

Please sign in to comment.