1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
use super::images::{avif_decode, to_gif, ImageError, ImageInfo};
use async_trait::async_trait;
use base64::{engine::general_purpose, Engine as _};
use dssim::Dssim;
use image::imageops::{crop, grayscale, overlay, resize, FilterType};
use image::{load, DynamicImage, ImageFormat, RgbaImage};
use rgb::FromSlice;
use snafu::{ensure, ResultExt, Snafu};
use std::ffi::OsStr;
use std::fs::File;
use std::io::Cursor;
use std::io::Read;
use std::time::Duration;
use substring::Substring;
use urlencoding::decode;

pub const PROCESS_LOAD: &str = "load";
pub const PROCESS_RESIZE: &str = "resize";
pub const PROCESS_OPTIM: &str = "optim";
pub const PROCESS_CROP: &str = "crop";
pub const PROCESS_GRAY: &str = "gray";
pub const PROCESS_WATERMARK: &str = "watermark";
pub const PROCESS_DIFF: &str = "diff";

const IMAGE_TYPE_GIF: &str = "gif";
const IMAGE_TYPE_PNG: &str = "png";
const IMAGE_TYPE_AVIF: &str = "avif";
const IMAGE_TYPE_WEBP: &str = "webp";
const IMAGE_TYPE_JPEG: &str = "jpeg";

#[derive(Debug, Snafu)]
pub enum ImageProcessingError {
    #[snafu(display("Process image fail, message:{message}"))]
    ParamsInvalid { message: String },
    #[snafu(display("{source}"))]
    Reqwest { source: reqwest::Error },
    #[snafu(display("{source}"))]
    HTTPHeaderToStr { source: reqwest::header::ToStrError },
    #[snafu(display("{source}"))]
    Base64Decode { source: base64::DecodeError },
    #[snafu(display("{source}"))]
    Image { source: image::ImageError },
    #[snafu(display("{source}"))]
    Images { source: ImageError },
    #[snafu(display("{source}"))]
    ParseInt { source: std::num::ParseIntError },
    #[snafu(display("{source}"))]
    FromUtf { source: std::string::FromUtf8Error },
    #[snafu(display("{source}"))]
    Io { source: std::io::Error },
}
type Result<T, E = ImageProcessingError> = std::result::Result<T, E>;

/// Run process image task.
/// Load task: ["load", "url"]
/// Resize task: ["resize", "width", "height"]
/// Gray task: ["gray"]
/// Optim task: ["optim", "webp", "quality", "speed"]
/// Crop task: ["crop", "x", "y", "width", "height"]
/// Watermark task: ["watermark", "url", "position", "margin left", "margin top"]
/// Diff task: ["diff"]
pub async fn run(tasks: Vec<Vec<String>>) -> Result<ProcessImage> {
    let mut img = ProcessImage {
        ..Default::default()
    };
    let he = ParamsInvalidSnafu {
        message: "params is invalid",
    };
    for params in tasks {
        if params.is_empty() {
            continue;
        }
        let sub_params = params[1..].to_vec();
        let task = &params[0];
        match task.as_str() {
            PROCESS_LOAD => {
                let data = &sub_params[0];
                let mut ext = "";
                if sub_params.len() >= 2 {
                    ext = &sub_params[1];
                }
                img = LoaderProcess::new(data, ext).process(img).await?;
            }
            PROCESS_RESIZE => {
                // 参数不符合
                ensure!(sub_params.len() >= 2, he);
                let width = sub_params[0].parse::<u32>().context(ParseIntSnafu {})?;
                let height = sub_params[1].parse::<u32>().context(ParseIntSnafu {})?;
                img = ResizeProcess::new(width, height).process(img).await?;
            }
            PROCESS_GRAY => {
                img = GrayProcess::new().process(img).await?;
            }
            PROCESS_OPTIM => {
                // 参数不符合
                ensure!(sub_params.len() == 3, he);
                let output_type = &sub_params[0];
                let mut quality = 80;
                if sub_params.len() > 1 {
                    quality = sub_params[1].parse::<u8>().context(ParseIntSnafu {})?;
                }

                let mut speed = 3;
                if sub_params.len() > 2 {
                    speed = sub_params[2].parse::<u8>().context(ParseIntSnafu {})?;
                }

                img = OptimProcess::new(output_type, quality, speed)
                    .process(img)
                    .await?;
            }
            PROCESS_CROP => {
                // 参数不符合
                ensure!(sub_params.len() >= 4, he);
                let x = sub_params[0].parse::<u32>().context(ParseIntSnafu {})?;
                let y = sub_params[1].parse::<u32>().context(ParseIntSnafu {})?;
                let width = sub_params[2].parse::<u32>().context(ParseIntSnafu {})?;
                let height = sub_params[3].parse::<u32>().context(ParseIntSnafu {})?;
                img = CropProcess::new(x, y, width, height).process(img).await?;
            }
            PROCESS_WATERMARK => {
                // 参数不符合
                ensure!(!sub_params.is_empty(), he);
                let url = decode(sub_params[0].as_str())
                    .context(FromUtfSnafu {})?
                    .to_string();
                let mut position = WatermarkPosition::RightBottom;
                if sub_params.len() > 1 {
                    position = (sub_params[1].as_str()).into();
                }
                let mut margin_left = 0;
                if sub_params.len() > 2 {
                    margin_left = sub_params[2].parse::<i64>().context(ParseIntSnafu {})?;
                }
                let mut margin_top = 0;
                if sub_params.len() > 3 {
                    margin_top = sub_params[3].parse::<i64>().context(ParseIntSnafu {})?;
                }
                let watermark = LoaderProcess::new(&url, "")
                    .process(ProcessImage {
                        ..Default::default()
                    })
                    .await?;

                let pro = WatermarkProcess::new(watermark.di, position, margin_left, margin_top);
                img = pro.process(img).await?;
            }
            PROCESS_DIFF => {
                img.diff = img.get_diff();
            }
            _ => {}
        }
    }
    Ok(img)
}

#[derive(Default, Clone)]
pub struct ProcessImage {
    original: Option<RgbaImage>,
    di: DynamicImage,
    pub diff: f64,
    pub original_size: usize,
    buffer: Vec<u8>,
    pub ext: String,
}

impl ProcessImage {
    pub fn new(data: Vec<u8>, ext: &str) -> Result<Self> {
        let format = ImageFormat::from_extension(OsStr::new(ext));
        ensure!(
            format.is_some(),
            ParamsInvalidSnafu {
                message: "Image format is not support".to_string(),
            }
        );
        // 已保证format不为空
        let di = load(Cursor::new(&data), format.unwrap()).context(ImageSnafu {})?;
        Ok(ProcessImage {
            original_size: data.len(),
            original: Some(di.to_rgba8()),
            di,
            buffer: data,
            diff: -1.0,
            ext: ext.to_string(),
        })
    }
    pub fn get_buffer(&self) -> Result<Vec<u8>> {
        if self.buffer.is_empty() {
            let mut bytes: Vec<u8> = Vec::new();
            let format =
                ImageFormat::from_extension(self.ext.as_str()).unwrap_or(ImageFormat::Jpeg);
            self.di
                .write_to(&mut Cursor::new(&mut bytes), format)
                .context(ImageSnafu {})?;
            Ok(bytes)
        } else {
            Ok(self.buffer.clone())
        }
    }
    fn support_dssim(&self) -> bool {
        self.ext != IMAGE_TYPE_GIF
    }
    fn get_diff(&self) -> f64 {
        // 如果无数据
        if self.original.is_none() {
            return -1.0;
        }
        // 如果是gif或者禁用了dssim
        if !self.support_dssim() {
            return -1.0;
        }
        // 已确保一定有数据
        let original = self.original.as_ref().unwrap();
        // 如果宽高不一致,则不比对
        if original.width() != self.di.width() || original.height() != self.di.height() {
            return -1.0;
        }
        let width = original.width() as usize;
        let height = original.height() as usize;
        let attr = Dssim::new();
        let gp1 = attr
            .create_image_rgba(original.as_raw().as_rgba(), width, height)
            .unwrap();
        let gp2 = attr
            .create_image_rgba(self.di.to_rgba8().as_raw().as_rgba(), width, height)
            .unwrap();
        let (diff, _) = attr.compare(&gp1, gp2);
        let value: f64 = diff.into();
        // 放大1千倍
        value * 1000.0
    }
}

#[async_trait]

pub trait Process {
    async fn process(&self, pi: ProcessImage) -> Result<ProcessImage>;
}

/// Loader process loads the image data from http, file or base64.
pub struct LoaderProcess {
    data: String,
    ext: String,
}

impl LoaderProcess {
    pub fn new(data: &str, ext: &str) -> Self {
        LoaderProcess {
            data: data.to_string(),
            ext: ext.to_string(),
        }
    }
    async fn fetch_data(&self) -> Result<ProcessImage> {
        let data = &self.data;
        let mut ext = self.ext.clone();
        let from_http = data.starts_with("http");
        let file_prefix = "file://";
        let from_file = data.starts_with(file_prefix);
        let original_data = if from_http {
            let resp = reqwest::Client::builder()
                .build()
                .context(ReqwestSnafu {})?
                .get(data)
                .timeout(Duration::from_secs(5 * 60))
                .send()
                .await
                .context(ReqwestSnafu {})?;

            if let Some(content_type) = resp.headers().get("Content-Type") {
                let str = content_type.to_str().context(HTTPHeaderToStrSnafu {})?;
                let arr: Vec<_> = str.split('/').collect();
                if arr.len() == 2 {
                    ext = arr[1].to_string();
                }
            }
            resp.bytes().await.context(ReqwestSnafu {})?.into()
        } else if from_file {
            let mut file =
                File::open(data.substring(file_prefix.len(), data.len())).context(IoSnafu)?;
            ext = data.split('.').last().unwrap_or_default().to_string();

            let mut contents = vec![];
            file.read_to_end(&mut contents).context(IoSnafu)?;
            contents
        } else {
            general_purpose::STANDARD
                .decode(data.as_bytes())
                .context(Base64DecodeSnafu {})?
        };
        ProcessImage::new(original_data, &ext)
    }
}

// 图片加载
#[async_trait]
impl Process for LoaderProcess {
    async fn process(&self, _: ProcessImage) -> Result<ProcessImage> {
        let result = self.fetch_data().await?;
        Ok(result)
    }
}

/// Resize process resizes the image size.
pub struct ResizeProcess {
    width: u32,
    height: u32,
}

impl ResizeProcess {
    pub fn new(width: u32, height: u32) -> Self {
        ResizeProcess { width, height }
    }
}

#[async_trait]
impl Process for ResizeProcess {
    async fn process(&self, pi: ProcessImage) -> Result<ProcessImage> {
        let mut img = pi;
        let mut w = self.width;
        let mut h = self.height;
        if w == 0 && h == 0 {
            return Ok(img);
        }
        let width = img.di.width();
        let height = img.di.height();
        // 如果宽或者高为0,则计算对应的宽高
        if w == 0 {
            w = width * h / height;
        }
        if h == 0 {
            h = height * w / width;
        }
        let result = resize(&img.di, w, h, FilterType::Lanczos3);
        img.buffer = vec![];
        img.di = DynamicImage::ImageRgba8(result);
        Ok(img)
    }
}

/// Gray process changes the image to gray mode.
#[derive(Default)]
pub struct GrayProcess {}

impl GrayProcess {
    pub fn new() -> Self {
        GrayProcess {}
    }
}

#[async_trait]
impl Process for GrayProcess {
    async fn process(&self, pi: ProcessImage) -> Result<ProcessImage> {
        let mut img = pi;
        img.di = DynamicImage::ImageLuma8(grayscale(&img.di));
        img.buffer = vec![];
        Ok(img)
    }
}

pub enum WatermarkPosition {
    LeftTop,
    Top,
    RightTop,
    Left,
    Center,
    Right,
    LeftBottom,
    Bottom,
    RightBottom,
}

impl From<&str> for WatermarkPosition {
    fn from(value: &str) -> Self {
        match value {
            "leftTop" => WatermarkPosition::LeftTop,
            "top" => WatermarkPosition::Top,
            "rightTop" => WatermarkPosition::RightTop,
            "left" => WatermarkPosition::Left,
            "center" => WatermarkPosition::Center,
            "right" => WatermarkPosition::Right,
            "leftBottom" => WatermarkPosition::LeftBottom,
            "bottom" => WatermarkPosition::Bottom,
            _ => WatermarkPosition::RightBottom,
        }
    }
}

/// Watermark process adds a watermark over the image.
pub struct WatermarkProcess {
    watermark: DynamicImage,
    position: WatermarkPosition,
    margin_left: i64,
    margin_top: i64,
}

impl WatermarkProcess {
    pub fn new(
        watermark: DynamicImage,
        position: WatermarkPosition,
        margin_left: i64,
        margin_top: i64,
    ) -> Self {
        WatermarkProcess {
            watermark,
            position,
            margin_left,
            margin_top,
        }
    }
}

#[async_trait]
impl Process for WatermarkProcess {
    async fn process(&self, pi: ProcessImage) -> Result<ProcessImage> {
        let mut img = pi;
        let di = img.di;
        let w = di.width() as i64;
        let h = di.height() as i64;
        let ww = self.watermark.width() as i64;
        let wh = self.watermark.height() as i64;
        let mut x: i64 = 0;
        let mut y: i64 = 0;
        match self.position {
            WatermarkPosition::Top => {
                x = (w - ww) >> 1;
            }
            WatermarkPosition::RightTop => {
                x = w - ww;
            }
            WatermarkPosition::Left => {
                y = (h - wh) >> 1;
            }
            WatermarkPosition::Center => {
                x = (w - ww) >> 1;
                y = (h - wh) >> 1;
            }
            WatermarkPosition::Right => {
                x = w - ww;
                y = (h - wh) >> 1;
            }
            WatermarkPosition::LeftBottom => {
                y = h - wh;
            }
            WatermarkPosition::Bottom => {
                x = (w - ww) >> 1;
                y = h - wh;
            }
            WatermarkPosition::RightBottom => {
                x = w - ww;
                y = h - wh;
            }
            _ => (),
        }
        x += self.margin_left;
        y += self.margin_top;
        let mut bottom: DynamicImage = di;
        overlay(&mut bottom, &self.watermark, x, y);
        img.buffer = vec![];
        img.di = bottom;
        Ok(img)
    }
}

/// Crop process crops the image.
pub struct CropProcess {
    x: u32,
    y: u32,
    width: u32,
    height: u32,
}

impl CropProcess {
    pub fn new(x: u32, y: u32, width: u32, height: u32) -> Self {
        Self {
            x,
            y,
            width,
            height,
        }
    }
}

#[async_trait]
impl Process for CropProcess {
    async fn process(&self, pi: ProcessImage) -> Result<ProcessImage> {
        let mut img = pi;
        let mut r = img.di;
        let result = crop(&mut r, self.x, self.y, self.width, self.height);
        img.di = DynamicImage::ImageRgba8(result.to_image());
        img.buffer = vec![];
        Ok(img)
    }
}

/// Optim process optimizes the image of multi format.
pub struct OptimProcess {
    output_type: String,
    quality: u8,
    speed: u8,
}

impl OptimProcess {
    pub fn new(output_type: &str, quality: u8, speed: u8) -> Self {
        Self {
            output_type: output_type.to_string(),
            quality,
            speed,
        }
    }
}

#[async_trait]
impl Process for OptimProcess {
    async fn process(&self, pi: ProcessImage) -> Result<ProcessImage> {
        let mut img = pi;

        let info: ImageInfo = img.di.to_rgba8().into();
        let quality = self.quality;
        let speed = self.speed;
        let original_type = img.ext.clone();

        let original_size = img.buffer.len();
        let mut output_type = self.output_type.clone();
        // 如果未指定输出,则保持原有
        if output_type.is_empty() {
            output_type.clone_from(&original_type);
        }

        img.ext.clone_from(&output_type);

        let data = match output_type.as_str() {
            IMAGE_TYPE_GIF => {
                let c = Cursor::new(&img.buffer);
                to_gif(c, 10).context(ImagesSnafu {})?
            }
            _ => {
                match output_type.as_str() {
                    IMAGE_TYPE_PNG => info.to_png(quality).context(ImagesSnafu {})?,
                    IMAGE_TYPE_AVIF => info.to_avif(quality, speed).context(ImagesSnafu {})?,
                    IMAGE_TYPE_WEBP => info.to_webp().context(ImagesSnafu {})?,
                    // 其它的全部使用jpeg
                    _ => {
                        img.ext = IMAGE_TYPE_JPEG.to_string();
                        info.to_mozjpeg(quality).context(ImagesSnafu {})?
                    }
                }
            }
        };
        // 类型不一样
        // 或者类型一样但是数据最小
        // 或者无原始数据
        if img.ext != original_type || data.len() < original_size || original_size == 0 {
            img.buffer = data;
            // 支持dssim再根据数据生成image
            // 否则无此必要
            if img.support_dssim() {
                // image 的avif decoder有其它依赖
                // 暂使用其它模块
                // decode如果失败则忽略
                // 因为只用于计算dssim
                let result = if img.ext == IMAGE_TYPE_AVIF {
                    avif_decode(&img.buffer).context(ImagesSnafu {})
                } else {
                    let c = Cursor::new(&img.buffer);
                    let format = ImageFormat::from_extension(OsStr::new(img.ext.as_str()));
                    load(c, format.unwrap()).context(ImageSnafu {})
                };
                if let Ok(value) = result {
                    img.di = value;
                }
            }
        }

        Ok(img)
    }
}

#[cfg(test)]
mod tests {
    use super::{
        CropProcess, GrayProcess, LoaderProcess, OptimProcess, ResizeProcess, WatermarkProcess,
    };
    use crate::image_processing::{Process, ProcessImage};
    use base64::{engine::general_purpose, Engine as _};
    use pretty_assertions::assert_eq;
    fn new_process_image() -> ProcessImage {
        let data = include_bytes!("../assets/rust-logo.png");
        ProcessImage::new(data.to_vec(), "png").unwrap()
    }

    #[test]
    fn test_load_process() {
        let p = LoaderProcess::new(
            "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png",
            "",
        );
        let result = tokio_test::block_on(p.fetch_data()).unwrap();
        assert_ne!(result.buffer.len(), 0);
        assert_eq!(result.ext, "png");

        let file = format!(
            "file://{}/assets/rust-logo.png",
            std::env::current_dir().unwrap().to_string_lossy()
        );
        let p = LoaderProcess::new(&file, "");
        let result = tokio_test::block_on(p.fetch_data()).unwrap();
        assert_ne!(result.buffer.len(), 0);
        assert_eq!(result.ext, "png");

        let data = include_bytes!("../assets/rust-logo.png");
        let p = LoaderProcess::new(&general_purpose::STANDARD.encode(data), "png");
        let result = tokio_test::block_on(p.process(ProcessImage::default())).unwrap();
        assert_ne!(result.buffer.len(), 0);
        assert_eq!(result.ext, "png");
    }

    #[test]
    fn test_resize_process() {
        let p = new_process_image();
        let result = tokio_test::block_on(ResizeProcess::new(48, 0).process(p)).unwrap();
        assert_eq!(result.di.width(), 48);
        assert_eq!(result.di.height(), 48);
    }

    #[test]
    fn test_gray_process() {
        let p = new_process_image();
        let result = tokio_test::block_on(GrayProcess::new().process(p)).unwrap();
        assert_eq!(result.di.width(), 144);
        assert_eq!(result.di.height(), 144);
    }

    #[test]
    fn test_watermark_process() {
        let watermark =
            tokio_test::block_on(ResizeProcess::new(48, 0).process(new_process_image())).unwrap();
        let p = new_process_image();
        let result = tokio_test::block_on(
            WatermarkProcess::new(watermark.di, "rightBottom".into(), 0, 0).process(p),
        )
        .unwrap();
        assert_eq!(result.di.width(), 144);
        assert_eq!(result.di.height(), 144);
    }

    #[test]
    fn test_crop_process() {
        let p = new_process_image();
        let result = tokio_test::block_on(CropProcess::new(40, 40, 48, 48).process(p)).unwrap();
        assert_eq!(result.di.width(), 48);
        assert_eq!(result.di.height(), 48);
    }

    #[test]
    fn test_optim_process() {
        // to png
        let result =
            tokio_test::block_on(OptimProcess::new("png", 70, 0).process(new_process_image()))
                .unwrap();
        assert_eq!(result.ext, "png");
        assert_eq!(result.buffer.len(), 1483);
        assert_ne!(result.get_diff(), 0.0_f64);
        assert_ne!(result.get_diff(), -1.0_f64);

        let result =
            tokio_test::block_on(OptimProcess::new("avif", 70, 0).process(new_process_image()))
                .unwrap();
        assert_eq!(result.ext, "avif");
        assert_eq!(result.buffer.len(), 2367);
        assert_ne!(result.get_diff(), 0.0_f64);
        assert_ne!(result.get_diff(), -1.0_f64);


        let result =
            tokio_test::block_on(OptimProcess::new("webp", 0, 0).process(new_process_image()))
                .unwrap();
        assert_eq!(result.ext, "webp");
        assert_eq!(result.buffer.len(), 2764);
        assert_eq!(result.get_diff(), 0.0);

        let result =
            tokio_test::block_on(OptimProcess::new("jpeg", 70, 0).process(new_process_image()))
                .unwrap();
        assert_eq!(result.ext, "jpeg");
        assert_eq!(result.buffer.len(), 392);
        assert_ne!(result.get_diff(), 0.0_f64);
        assert_ne!(result.get_diff(), -1.0_f64);
    }
}