cellular_raza_core/backend/cpu_os_threads/
trait_bounds.rs

1use cellular_raza_concepts::*;
2
3use core::fmt::Debug;
4use core::ops::{Add, AddAssign, Mul, Sub, SubAssign};
5use num::Zero;
6
7// TODO use trait alias when available
8/* pub trait Position = Sized
9+ Add<Self, Output = Self>
10+ AddAssign
11+ Sub<Output = Self>
12+ SubAssign
13+ Clone
14+ Debug
15+ Send
16+ Sync
17+ Mul<f64, Output = Self>;*/
18/// Represents the current position of a cell-agent.
19pub trait PositionBound:
20    Sized
21    + Add<Self, Output = Self>
22    + AddAssign
23    + Sub<Output = Self>
24    + SubAssign
25    + Clone
26    + Debug
27    + Send
28    + Sync
29    + Mul<f64, Output = Self>
30{
31}
32impl<T> PositionBound for T where
33    T: Sized
34        + Add<Self, Output = Self>
35        + AddAssign
36        + Sub<Output = Self>
37        + SubAssign
38        + Clone
39        + Debug
40        + Send
41        + Sync
42        + Mul<f64, Output = Self>
43{
44}
45
46// TODO use trait alias when available
47/* pub trait Force = Sized
48+ Add<Self, Output = Self>
49+ AddAssign
50+ Sub<Output = Self>
51+ SubAssign
52+ Clone
53+ Debug
54+ Zero
55+ Send
56+ Sync
57+ Mul<f64, Output = Self>;*/
58/// Represents a force which can act between two cells.
59pub trait ForceBound:
60    Sized
61    + Add<Self, Output = Self>
62    + AddAssign
63    + Sub<Output = Self>
64    + SubAssign
65    + Clone
66    + Debug
67    + Zero
68    + Send
69    + Sync
70    + Mul<f64, Output = Self>
71{
72}
73impl<T> ForceBound for T where
74    T: Sized
75        + Add<Self, Output = Self>
76        + AddAssign
77        + Sub<Output = Self>
78        + SubAssign
79        + Clone
80        + Debug
81        + Zero
82        + Send
83        + Sync
84        + Mul<f64, Output = Self>
85{
86}
87
88// TODO use trait alias when available
89/* pub trait Velocity = Sized
90+ Add<Self, Output = Self>
91+ AddAssign
92+ Sub<Output = Self>
93+ SubAssign
94+ Clone
95+ Debug
96+ Zero
97+ Send
98+ Sync
99+ Mul<f64, Output = Self>;*/
100/// Represents the velocity of a cell.
101pub trait VelocityBound:
102    Sized
103    + Add<Self, Output = Self>
104    + AddAssign
105    + Sub<Output = Self>
106    + SubAssign
107    + Clone
108    + Debug
109    + Zero
110    + Send
111    + Sync
112    + Mul<f64, Output = Self>
113{
114}
115impl<T> VelocityBound for T where
116    T: Sized
117        + Add<Self, Output = Self>
118        + AddAssign
119        + Sub<Output = Self>
120        + SubAssign
121        + Clone
122        + Debug
123        + Zero
124        + Send
125        + Sync
126        + Mul<f64, Output = Self>
127{
128}
129
130/// Encapsulates all concepts that can be specified for a [Agent]
131///
132/// We hope to be deprecating this trait in the future and only rely on individual traits instead.
133/// While this trait could be manually implemented, it is often not necessary (see [cellular_raza-building-blocks](https://docs.rs/cellular_raza-building-blocks))
134pub trait Agent<Pos: PositionBound, Vel: VelocityBound, For: ForceBound, Inf, Float = f64>:
135    Cycle<Self, Float>
136    + Interaction<Pos, Vel, For, Inf>
137    + Mechanics<Pos, Vel, For, Float>
138    + Position<Pos>
139    + Velocity<Vel>
140    + Sized
141    + Send
142    + Sync
143    + Clone
144    + serde::Serialize
145    + for<'a> serde::Deserialize<'a>
146{
147}
148impl<Pos, Vel, For, Inf, Float, A> Agent<Pos, Vel, For, Inf, Float> for A
149where
150    Pos: PositionBound,
151    For: ForceBound,
152    Vel: VelocityBound,
153    A: Cycle<Self, Float>
154        + Interaction<Pos, Vel, For, Inf>
155        + Mechanics<Pos, Vel, For, Float>
156        + Position<Pos>
157        + Velocity<Vel>
158        + Sized
159        + Send
160        + Sync
161        + Clone
162        + serde::Serialize
163        + for<'a> serde::Deserialize<'a>,
164{
165}
166
167// TODO Define trait aliases for Position and Force
168
169// TODO use trait alias when available
170// pub trait InteractionInformation = Send + Sync + Clone + core::fmt::Debug;
171/// Trait implementations needed for the information generic parameter of [Interaction].
172pub trait InteractionInf: Send + Sync + Clone + core::fmt::Debug {}
173impl<T> InteractionInf for T where T: Send + Sync + Clone + core::fmt::Debug {}