1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use crateMergeOperation;
/// A trait that provides arithmetic operations for working with geometries,
/// enabling merging and combining of curve data based on different operations.
///
/// This trait allows performing mathematical operations between geometric objects,
/// particularly curves, to create new derived geometries. It supports various
/// operations like addition, subtraction, multiplication, and more through the
/// `MergeOperation` enum.
///
/// # Type Parameters
/// - `Input`: The type of geometric object that can be merged and operated upon.
///
/// # Associated Types
/// - `Error`: Represents the type of error that may occur during curve operations.
///
/// # Required Methods
///
/// ## `merge`
/// Combines multiple geometries into a single curve based on a specified `MergeOperation`.
///
/// ### Parameters
/// - `geometries`: A slice of references to the input geometries that need to be merged.
/// - `operation`: The operation used to combine the geometries (e.g., addition, subtraction, etc.).
///
/// ### Returns
/// - `Result<Input, Self::Error>`: Returns the resulting merged curve if successful,
/// or an error of type `Self::Error` if the merge process fails.
///
/// ## `merge_with`
/// Merges the current curve with another curve based on a specified `MergeOperation`.
///
/// ### Parameters
/// - `other`: A reference to another curve to be merged.
/// - `operation`: The operation used to combine the geometries (e.g., addition, subtraction, etc.).
///
/// ### Returns
/// - `Result<Input, Self::Error>`: Returns the resulting merged curve if successful,
/// or an error of type `Self::Error` if the merge process fails.
///
/// # Examples
///
/// ```rust
/// use rust_decimal::Decimal;
/// use optionstratlib::geometrics::{Arithmetic, GeometricObject, MergeOperation};
/// use optionstratlib::curves::{Curve, Point2D};
///
/// let curve1 = Curve::from_vector(vec![
/// Point2D::new(Decimal::ZERO, Decimal::ZERO),
/// Point2D::new(Decimal::ONE, Decimal::ONE),
/// ]);
/// let curve2 = Curve::from_vector(vec![
/// Point2D::new(Decimal::ZERO, Decimal::ONE),
/// Point2D::new(Decimal::ONE, Decimal::TWO),
/// ]);
///
/// // Merge two curves by adding their values
/// let result_curve = Curve::merge(&[&curve1, &curve2], MergeOperation::Add);
/// ```
///
/// # Notes
/// - This trait is designed to be implemented for specific curve types which define how
/// the merging will occur. The associated error type should capture and communicate
/// any issues encountered during operations.
/// - The implementation may need to handle cases where curves have different domains
/// or sampling points.