rust_3d/
is_polygon.rs

1/*
2Copyright 2018 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//! IsPolygon is a trait used for closed polygons
24
25use crate::*;
26
27//------------------------------------------------------------------------------
28
29/// IsPolygon is a trait used for closed polygons
30pub trait IsPolygon<V> {
31    /// Should return the number of segments within the polygon
32    fn num_segments(&self) -> usize;
33    /// Should return the ids of vertices of the given segment
34    fn segment_vertex_ids(&self, segmentid: SId) -> Result<(VId, VId)>;
35    /// Should return the vertices of the given segment
36    fn segment_vertices(&self, segmentid: SId) -> Result<(V, V)>;
37    /// Should return the vertex with the given id
38    fn vertex(&self, vertexid: VId) -> Result<V>;
39
40    /// Returns the number of vertices within the polygon
41    fn num_vertices(&self) -> usize {
42        self.num_segments()
43    }
44}