src/sets.rs

branch
dev
changeset 86
d5b0e496b72f
parent 75
e9f4550cfa18
equal deleted inserted replaced
76:99ad55974e62 86:d5b0e496b72f
5 use std::ops::{RangeFull,RangeFrom,Range,RangeInclusive,RangeTo,RangeToInclusive}; 5 use std::ops::{RangeFull,RangeFrom,Range,RangeInclusive,RangeTo,RangeToInclusive};
6 use crate::types::*; 6 use crate::types::*;
7 use crate::loc::Loc; 7 use crate::loc::Loc;
8 use crate::euclidean::Euclidean; 8 use crate::euclidean::Euclidean;
9 use crate::instance::{Space, Instance}; 9 use crate::instance::{Space, Instance};
10 use serde::Serialize; 10 use serde::{Serialize, Deserialize};
11 11
12 pub mod cube; 12 pub mod cube;
13 pub use cube::Cube; 13 pub use cube::Cube;
14 14
15 /// Trait for arbitrary sets. The parameter `U` is the element type. 15 /// Trait for arbitrary sets. The parameter `U` is the element type.
60 60
61 /// Halfspaces described by an orthogonal vector and an offset. 61 /// Halfspaces described by an orthogonal vector and an offset.
62 /// 62 ///
63 /// The halfspace is $H = \\{ t v + a \mid a^⊤ v = 0 \\}$, where $v$ is the orthogonal 63 /// The halfspace is $H = \\{ t v + a \mid a^⊤ v = 0 \\}$, where $v$ is the orthogonal
64 /// vector and $t$ the offset. 64 /// vector and $t$ the offset.
65 #[derive(Clone,Copy,Debug,Serialize,Eq,PartialEq)] 65 #[derive(Clone,Copy,Debug,Serialize,Deserialize,Eq,PartialEq)]
66 pub struct Halfspace<A, F> where A : Euclidean<F>, F : Float { 66 pub struct Halfspace<A, F> where A : Euclidean<F>, F : Float {
67 pub orthogonal : A, 67 pub orthogonal : A,
68 pub offset : F, 68 pub offset : F,
69 } 69 }
70 70
114 self.orthogonal.dot(item) >= self.offset 114 self.orthogonal.dot(item) >= self.offset
115 } 115 }
116 } 116 }
117 117
118 /// Polygons defined by `N` `Halfspace`s. 118 /// Polygons defined by `N` `Halfspace`s.
119 #[derive(Clone,Copy,Debug,Eq,PartialEq)] 119 #[derive(Clone,Copy,Debug,Eq,PartialEq,Serialize,Deserialize)]
120 #[serde(bound(
121 serialize = "[Halfspace<A,F>; N] : Serialize",
122 deserialize = "[Halfspace<A,F>; N] : for<'a> Deserialize<'a>"
123 ))]
120 pub struct NPolygon<A, F, const N : usize>(pub [Halfspace<A,F>; N]) 124 pub struct NPolygon<A, F, const N : usize>(pub [Halfspace<A,F>; N])
121 where A : Euclidean<F>, F : Float; 125 where A : Euclidean<F>, F : Float;
122 126
123 impl<A,F,const N : usize> Set<A> for NPolygon<A,F,N> 127 impl<A,F,const N : usize> Set<A> for NPolygon<A,F,N>
124 where 128 where

mercurial