rust_3d/filter_outer_inner.rs
1/*
2Copyright 2017 Martin Buck
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"),
6to deal in the Software without restriction, including without limitation the
7rights to use, copy, modify, merge, publish, distribute, sublicense,
8and/or sell copies of the Software, and to permit persons to whom the Software
9is furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall
12be included all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21*/
22
23//! FilterOuterInner, a filter which combines an inner and an outer filter. Where the inner is negated while the outer is allowed. This is useful to create hollow filter shapes
24
25use crate::*;
26
27//------------------------------------------------------------------------------
28
29/// FilterOuterInner, a filter which combines an inner and an outer filter. Where the inner is negated while the outer is allowed. This is useful to create hollow filter shapes
30pub struct FilterOuterInner<FOuter, FInner, T>
31where
32 FOuter: IsFilter<T>,
33 FInner: IsFilter<T>,
34{
35 filter: FilterAND<FOuter, FilterNegate<FInner, T>, T>,
36}
37
38impl<FOuter, FInner, T> FilterOuterInner<FOuter, FInner, T>
39where
40 FOuter: IsFilter<T>,
41 FInner: IsFilter<T>,
42{
43 /// Creates a new FilterOuterInner from two other IsFilter
44 pub fn new(filter_outer: FOuter, filter_inner: FInner) -> Self {
45 FilterOuterInner {
46 filter: FilterAND::new(filter_outer, FilterNegate::new(filter_inner)),
47 }
48 }
49}
50
51impl<FOuter, FInner, T> IsFilter<T> for FilterOuterInner<FOuter, FInner, T>
52where
53 FOuter: IsFilter<T>,
54 FInner: IsFilter<T>,
55{
56 fn is_allowed(&self, x: &T) -> bool {
57 self.filter.is_allowed(x)
58 }
59}