Skip to content

Commit 762a57f

Browse files
committed
Add new test case based on issue 18
1 parent 1b98ecf commit 762a57f

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

src/lib.rs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,159 @@ mod tests {
482482
);
483483
}
484484

485+
#[test]
486+
fn test_issue18() {
487+
let data_str = include_str!("../tests/fixtures/issue18.json");
488+
let raw_data: serde_json::Value = serde_json::from_str(data_str).unwrap();
489+
let matrix: Vec<Float> = raw_data["data"]
490+
.as_array()
491+
.unwrap()
492+
.iter()
493+
.map(|x| x.as_f64().unwrap() as Float)
494+
.collect();
495+
let h = raw_data["height"].as_u64().unwrap() as usize;
496+
let w = raw_data["width"].as_u64().unwrap() as usize;
497+
498+
let c = ContourBuilder::new(w, h, true);
499+
let res = c.contours(&matrix, &[10.]).unwrap();
500+
assert_eq!(
501+
res[0].geometry(),
502+
&MultiPolygon::<Float>(vec![
503+
polygon![
504+
(x: 5.093049464469837, y: 2.5),
505+
(x: 4.5, y: 1.675604779947537),
506+
(x: 4.041491617923191, y: 2.5),
507+
(x: 4.5, y: 3.0939939099086486),
508+
(x: 5.093049464469837, y: 2.5),
509+
],
510+
polygon![
511+
(x: 3.2866555248441216, y: 3.5),
512+
(x: 2.5380369570434365, y: 2.5),
513+
(x: 2.810018648476255, y: 1.5),
514+
(x: 2.5, y: 0.7099240221367358),
515+
(x: 2.102376081825299, y: 1.5),
516+
(x: 1.5, y: 2.2930927322449044),
517+
(x: 0.9128140626438015, y: 1.5),
518+
(x: 1.5, y: 0.7886423607239752),
519+
(x: 2.1982064997527755, y: 0.5),
520+
(x: 1.5, y: 0.0),
521+
(x: 0.5, y: 0.0),
522+
(x: 0.0, y: 0.5),
523+
(x: 0.0, y: 1.5),
524+
(x: 0.0, y: 2.5),
525+
(x: 0.5, y: 3.3582089552233354),
526+
(x: 1.5, y: 2.708014829934868),
527+
(x: 2.108384, y: 3.5),
528+
(x: 2.5, y: 4.408234071765186),
529+
(x: 3.2866555248441216, y: 3.5),
530+
],
531+
polygon![
532+
(x: 6.441781292984862, y: 3.5),
533+
(x: 5.5, y: 2.959587986897662),
534+
(x: 4.958615849921951, y: 3.5),
535+
(x: 5.5, y: 3.8767591586303354),
536+
(x: 6.441781292984862, y: 3.5),
537+
],
538+
polygon![
539+
(x: 4.0457991530192805, y: 4.5),
540+
(x: 3.5, y: 3.7647997446944315),
541+
(x: 2.618308376788021, y: 4.5),
542+
(x: 3.5, y: 5.140019447145437),
543+
(x: 4.0457991530192805, y: 4.5),
544+
],
545+
polygon![
546+
(x: 7.016556897182495, y: 4.5),
547+
(x: 6.5, y: 3.6303611303611305),
548+
(x: 6.300452312802572, y: 4.5),
549+
(x: 6.5, y: 4.727784276551992),
550+
(x: 7.016556897182495, y: 4.5),
551+
],
552+
polygon![
553+
(x: 3.1676925049689437, y: 5.5),
554+
(x: 2.5, y: 4.606132784000669),
555+
(x: 2.0164254986312082, y: 4.5),
556+
(x: 1.5, y: 4.435054715357187),
557+
(x: 0.5, y: 3.5148494368248206),
558+
(x: 0.0, y: 4.5),
559+
(x: 0.0, y: 5.5),
560+
(x: 0.5, y: 6.231487086359968),
561+
(x: 1.5, y: 6.137720033528919),
562+
(x: 2.5, y: 5.946904838536682),
563+
(x: 3.1676925049689437, y: 5.5),
564+
],
565+
polygon![
566+
(x: 5.084253149370173, y: 8.5),
567+
(x: 5.5, y: 8.109086806926463),
568+
(x: 6.223857085400153, y: 7.5),
569+
(x: 6.5, y: 7.140249759846301),
570+
(x: 7.011048375853896, y: 6.5),
571+
(x: 6.5, y: 6.223083605597608),
572+
(x: 5.5, y: 5.6994222282881175),
573+
(x: 4.5, y: 6.254883716200413),
574+
(x: 4.150007260055157, y: 6.5),
575+
(x: 3.5, y: 7.222661673070077),
576+
(x: 3.1732349360925136, y: 7.5),
577+
(x: 3.5, y: 8.060357480674517),
578+
(x: 3.908975059166165, y: 8.5),
579+
(x: 4.5, y: 9.177341957020609),
580+
(x: 5.084253149370173, y: 8.5),
581+
],
582+
polygon![
583+
(x: 2.4412640476419276, y: 9.5),
584+
(x: 1.5, y: 9.30005100999793),
585+
(x: 1.320828800497289, y: 9.5),
586+
(x: 1.5, y: 10.0),
587+
(x: 2.4412640476419276, y: 9.5),
588+
],
589+
polygon![
590+
(x: 10.0, y: 9.5),
591+
(x: 10.0, y: 8.5),
592+
(x: 10.0, y: 7.5),
593+
(x: 10.0, y: 6.5),
594+
(x: 10.0, y: 5.5),
595+
(x: 10.0, y: 4.5),
596+
(x: 10.0, y: 3.5),
597+
(x: 10.0, y: 2.5),
598+
(x: 10.0, y: 1.5),
599+
(x: 10.0, y: 0.5),
600+
(x: 9.5, y: 0.0),
601+
(x: 8.5, y: 0.0),
602+
(x: 7.5, y: 0.0),
603+
(x: 6.5, y: 0.0),
604+
(x: 5.5, y: 0.0),
605+
(x: 4.5, y: 0.0),
606+
(x: 3.5, y: 0.0),
607+
(x: 2.663832019716454, y: 0.5),
608+
(x: 3.5, y: 0.8786157823790688),
609+
(x: 4.5, y: 1.3957432081675032),
610+
(x: 4.74461210542345, y: 1.5),
611+
(x: 5.5, y: 1.98943399535271),
612+
(x: 6.017704327724515, y: 2.5),
613+
(x: 6.5, y: 3.427621734855286),
614+
(x: 6.616189691853682, y: 3.5),
615+
(x: 7.5, y: 4.0492152848856175),
616+
(x: 7.6640591047371185, y: 4.5),
617+
(x: 7.765869728675749, y: 5.5),
618+
(x: 8.019380992928879, y: 6.5),
619+
(x: 8.5, y: 6.935535276948297),
620+
(x: 8.930593233352143, y: 7.5),
621+
(x: 8.5, y: 7.910325821871075),
622+
(x: 7.717229434426615, y: 8.5),
623+
(x: 7.5, y: 8.658415374082265),
624+
(x: 6.5, y: 8.666753585397572),
625+
(x: 5.5, y: 8.792345981060047),
626+
(x: 4.7166421517126125, y: 9.5),
627+
(x: 5.5, y: 10.0),
628+
(x: 6.5, y: 10.0),
629+
(x: 7.5, y: 10.0),
630+
(x: 8.5, y: 10.0),
631+
(x: 9.5, y: 10.0),
632+
(x: 10.0, y: 9.5),
633+
],
634+
])
635+
);
636+
}
637+
485638
#[test]
486639
fn test_multipolygon_with_x_y_steps() {
487640
let c = ContourBuilder::new(10, 10, true)

tests/fixtures/issue18.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"data": [10.005131244659424,10.00740671157837,9.996798515319824,10.016339778900146,10.029620170593262,10.015851020812988,10.020735740661621,10.03123426437378,10.127958297729492,10.510040283203125,10.01283311843872,9.981746196746826,10.012049198150635,9.973183155059814,9.996552467346191,10.010646343231201,10.011570453643799,10.045228481292725,10.047812461853027,10.211743831634521,10.002796649932861,10.004762172698975,10.000755786895752,9.980885982513428,10.01618480682373,9.988893985748291,10.010346412658691,10.040336608886719,10.032609939575195,10.129814624786377,9.999537944793701,9.981868743896484,10.01167106628418,9.996834754943848,9.988937377929688,10.013059139251709,9.999192714691162,10.00614070892334,10.040743827819824,10.069762706756592,10.030653953552246,10.001259326934814,9.998820781707764,10.008788108825684,9.992686748504639,9.978397369384766,10.005385398864746,9.994959831237793,10.025681495666504,10.067190170288086,10.006914615631104,10.005441665649414,10.009931564331055,9.995057106018066,9.964602947235107,9.995819568634033,9.981742858886719,9.980104446411133,10.054936408996582,10.050554752349854,9.997461795806885,9.99690866470337,9.987708568572998,9.978653907775879,10.011493682861328,10.016782283782959,10.006991863250732,9.993310451507568,10.006190299987793,10.031456470489502,9.960848331451416,9.960952281951904,9.983121871948242,10.00819206237793,10.01116943359375,10.010298252105713,9.996071338653564,9.999953269958496,9.991977214813232,10.010609149932861,9.982444763183594,9.962605953216553,9.990678787231445,9.99357271194458,10.009288311004639,9.993390560150146,9.996950626373291,9.996800422668457,10.011529445648193,10.012756824493408,9.957185745239258,10.009345531463623,9.999416828155518,9.990969181060791,9.995575428009033,10.015998840332031,10.01523733139038,10.016997814178467,10.014256000518799,10.001533031463623],
3+
"height": 10,
4+
"width": 10
5+
}

0 commit comments

Comments
 (0)