d@16
|
1 (cl:in-package #:amuse)
|
d@16
|
2
|
d@16
|
3 (defmethod duration ((period-designator period))
|
d@16
|
4 (%period-interval period-designator))
|
d@16
|
5
|
d@16
|
6 (defmethod timepoint ((moment-designator moment))
|
d@16
|
7 (%moment-time moment-designator))
|
d@16
|
8
|
d@16
|
9 ;; Time protocol
|
d@16
|
10
|
d@16
|
11 (defmethod time+ ((object1 moment) (object2 period))
|
d@16
|
12 (make-moment (+ (timepoint object1) (duration object2))))
|
d@16
|
13
|
d@16
|
14 (defmethod time+ ((object1 period) (object2 moment)) ;?
|
d@16
|
15 (time+ object2 object1))
|
d@16
|
16
|
d@16
|
17 (defmethod time+ ((object1 period) (object2 period))
|
d@16
|
18 (make-floating-period (+ (duration object1)
|
d@16
|
19 (duration object2))))
|
d@16
|
20
|
d@16
|
21 (defmethod time+ ((object1 moment) (object2 moment))
|
d@16
|
22 (error 'undefined-action :operation 'time+ :datatype (list 'moment 'moment)))
|
d@16
|
23
|
d@16
|
24 (defmethod time- ((object1 moment) (object2 moment))
|
d@16
|
25 (make-anchored-period object1
|
d@16
|
26 (- (duration object2)
|
d@16
|
27 (duration object1))))
|
d@16
|
28
|
d@16
|
29 (defmethod time- ((object1 moment) (object2 period))
|
d@16
|
30 (make-moment (- (timepoint object1) (duration object2))))
|
d@16
|
31
|
d@16
|
32 (defmethod time- ((object1 period) (object2 moment)) ;?
|
d@16
|
33 (error 'undefined-action
|
d@16
|
34 :operation 'time-
|
d@16
|
35 :datatype (list 'period 'moment)))
|
d@16
|
36
|
d@16
|
37 (defmethod time- ((object1 period) (object2 period))
|
d@16
|
38 (make-floating-period (- (duration object2)
|
d@16
|
39 (duration object1))))
|
d@16
|
40
|
d@16
|
41
|
d@16
|
42 (defmethod time> ((object1 moment) (object2 moment))
|
d@16
|
43 (> (timepoint object1) (timepoint object2)))
|
d@16
|
44
|
d@16
|
45 (defmethod time= ((object1 moment) (object2 moment))
|
d@16
|
46 (= (timepoint object1) (timepoint object2)))
|
d@16
|
47
|
d@16
|
48 (defmethod duration> ((object1 period) (object2 period))
|
d@16
|
49 (> (duration object1) (duration object2)))
|
d@16
|
50
|
d@16
|
51 (defmethod duration= ((object1 period) (object2 period))
|
d@16
|
52 (= (duration object1) (duration object2)))
|
d@16
|
53
|
d@16
|
54 (defmethod duration* ((object1 period) (object2 number))
|
d@16
|
55 (* (duration object1) object2))
|
d@16
|
56
|
d@16
|
57 (defmethod duration* ((object1 number) (object2 period))
|
d@16
|
58 (duration* object2 object1))
|
d@16
|
59
|
d@16
|
60 (defmethod duration/ ((object1 period) (object2 number))
|
d@16
|
61 (/ (duration object1) object2))
|
d@16
|
62
|
d@16
|
63 ;; Pitch protocol
|
d@16
|
64
|
d@16
|
65 ; How do we do this?
|
d@16
|
66
|
d@16
|
67 ;; Allen
|
d@16
|
68
|
d@16
|
69 (defmethod meets ((object1 anchored-period)
|
d@16
|
70 (object2 anchored-period))
|
d@16
|
71 (or (time= (cut-off object1) (onset object2))
|
d@16
|
72 (time= (cut-off object2) (onset object1))))
|
d@16
|
73
|
d@16
|
74 (defmethod before ((object1 anchored-period)
|
d@16
|
75 (object2 anchored-period))
|
d@16
|
76 (time< (cut-off object1) (onset object2)))
|
d@16
|
77
|
d@16
|
78 (defmethod overlaps ((object1 anchored-period)
|
d@16
|
79 (object2 anchored-period))
|
d@16
|
80 (or (and (time> (cut-off object1) (onset object2))
|
d@16
|
81 (time< (onset object1) (onset object2)))
|
d@16
|
82 (and (time> (cut-off object1) (cut-off object2))
|
d@16
|
83 (time< (onset object1) (cut-off object2)))))
|
d@16
|
84
|
d@16
|
85 (defmethod during ((object1 anchored-period)
|
d@16
|
86 (object2 anchored-period))
|
d@16
|
87 (and (time> (onset object1) (onset object2))
|
d@16
|
88 (time< (cut-off object2) (cut-off object2))))
|
d@16
|
89
|
d@16
|
90 (defmethod starts ((object1 anchored-period)
|
d@16
|
91 (object2 anchored-period))
|
d@16
|
92 (time= (onset object1) (onset object2)))
|
d@16
|
93
|
d@16
|
94 (defmethod ends ((object1 anchored-period)
|
d@16
|
95 (object2 anchored-period))
|
d@16
|
96 (time= (cut-off object1) (cut-off object2)))
|
d@16
|
97
|
d@16
|
98 ;; ...and
|
d@16
|
99
|
d@16
|
100 (defmethod period-intersection ((object1 anchored-period)
|
d@16
|
101 (object2 anchored-period))
|
d@16
|
102 (cond
|
d@16
|
103 ((disjoint object1 object2)
|
d@16
|
104 ;; if they don't overlap, return nil, not a negative-valued
|
d@16
|
105 ;; period
|
d@16
|
106 nil)
|
d@16
|
107 (t
|
d@16
|
108 (let ((new-onset (max (onset object1)
|
d@16
|
109 (onset object2))))
|
d@16
|
110 (make-anchored-period new-onset
|
d@16
|
111 (time- (min (cut-off object1)
|
d@16
|
112 (cut-off object2))
|
d@16
|
113 new-onset))))))
|
d@16
|
114
|
d@16
|
115
|
d@16
|
116 |