@@ -9,21 +9,35 @@ package ShapeItems {
99 private import Objects::*;
1010 private import Items::Item;
1111 private import SequenceFunctions::isEmpty;
12-
12+ private import SequenceFunctions::notEmpty;
13+ private import SequenceFunctions::size;
14+ private import ControlFunctions::'?';
15+
1316 /**
14- * A Line is a Curve that is a straight line of a given length .
17+ * A PlanarCurve is a flat Surface with a given area .
1518 */
16- item def Line :> Curve {
17- attribute :>> length;
18- attribute :>> outerSpaceDimension = 1;
19+ item def PlanarCurve :> Curve {
20+ attribute :>> area [1] ;
21+
22+ constraint { notEmpty(outerSpaceDimension) & outerSpaceDimension <= 2 }
1923 }
2024
2125 /**
2226 * A PlanarSurface is a flat Surface with a given area.
2327 */
2428 item def PlanarSurface :> Surface {
25- attribute :>> area;
29+ attribute :>> area [1] ;
2630 attribute :>> outerSpaceDimension = 2;
31+
32+ item :>> shape : PlanarCurve;
33+ }
34+
35+ /**
36+ * A Line is a Curve that is a straight line of a given length.
37+ */
38+ item def Line :> PlanarCurve {
39+ attribute :>> length [1];
40+ attribute :>> outerSpaceDimension = 1;
2741 }
2842
2943 /**
@@ -39,12 +53,12 @@ package ShapeItems {
3953 /**
4054 * A Circle is a Path in the shape of a circle of a given radius.
4155 */
42- item def Circle :> Path {
43- attribute radius :>> radius;
56+ item def Circle :> Path, PlanarCurve {
57+ attribute :>> radius;
4458
4559 item :>> faces [0];
4660 item :>> edges [1] {
47- attribute circumference :>> length = Circle::radius * TrigFunctions::pi;
61+ attribute circumference :>> length = Circle::radius * TrigFunctions::pi * 2 ;
4862 item :>> shape : Item [0];
4963 item :>> vertices [0];
5064 }
@@ -54,15 +68,15 @@ package ShapeItems {
5468 /**
5569 * A Disc is a Shell bounded by a Circle.
5670 */
57- item def Disc :> Shell {
58- attribute radius :>> radius;
71+ item def Disc :> Shell, PlanarSurface {
72+ attribute :>> radius;
5973
6074 item :>> shape : Circle [1] {
6175 attribute :>> radius = Disc::radius;
6276 }
6377
6478 item :>> faces : PlanarSurface [1] {
65- item :>> edges [1];
79+ item :>> edges [1];
6680 }
6781 item :>> edges : Circle [1] = shape;
6882 item :>> vertices [0];
@@ -76,38 +90,42 @@ package ShapeItems {
7690 item def Sphere :> Shell {
7791 attribute :>> radius;
7892
79- item faces : Surface [1] :>> faces ;
93+ item :>> faces [1];
8094 item :>> edges [0];
8195 item :>> vertices [0];
96+
97+ attribute :>> genus = 0;
8298 }
8399
84100 /**
85101 * A Cone is a Shell in the shape of a right circular code, possibly truncated, with given
86102 * baseRadius, apexRadius and height.
87103 */
88104 item def Cone :> Shell {
89- attribute baseRadius :> radius;
90- attribute apexRadius :> radius default 0 [m];
91- attribute :>> height;
105+ attribute baseRadius [1] = radius;
106+ attribute apexRadius [1] default 0 [m];
107+ attribute :>> height [1];
108+
109+ attribute :>> radius [1];
92110 attribute isTruncated : Boolean [1] = (apexRadius > 0);
93111
94- item faces : Surface [2..3] :>> faces ;
112+ item :>> faces [2..3];
95113 item bf : Disc [1] :> faces;
96114 item af : Disc [0..1] :> faces;
97115 item cf : Surface [1] :> faces;
98116 constraint { (apexRadius == 0) == isEmpty(af) }
99117
100- item edges : Circle [1..2] :>> edges ;
101- item be [1 ] :> edges {
118+ item :>> edges : Circle [2..4] ;
119+ item be [2 ] :> edges {
102120 attribute :>> radius = baseRadius;
103121 }
104- item ae [0..1 ] :> edges {
122+ item ae [0..2 ] :> edges {
105123 attribute :>> radius = apexRadius;
106124 }
107- constraint { isEmpty(af) == isEmpty(ae) }
125+ constraint { isEmpty(af) ? isEmpty(ae) : size(ae) == 2 }
108126
109- item vertices : Point [0..1] :>> vertices ;
110- constraint { isEmpty(ae) == isEmpty (vertices) }
127+ item :>> vertices [0..1];
128+ constraint { isEmpty(ae) == notEmpty (vertices) }
111129
112130 /* Faces to edges */
113131 connection :WithinBoth connect bf.edges [1] to be [0..*];
@@ -122,38 +140,37 @@ package ShapeItems {
122140 connection :WithinBoth connect be [2] to be [2];
123141 connection :WithinBoth connect ae [2] to ae [2];
124142
143+ attribute :>> genus = 0;
125144 }
126145
127146 /**
128147 * A Cylinder is a Cone whose baseRadius and apexRadius are the same, representing
129148 * a right circular cylinder.
130149 */
131150 item def Cylinder :> Cone {
132- attribute :>> radius = baseRadius;
133-
134- attribute :>> baseRadius = apexRadius;
151+ attribute :>> apexRadius = baseRadius;
135152 }
136153
137154 /**
138155 * A Cuboid is a Shell in the shape of a six-sided polyhedron with rectangular sides, with
139156 * given length, width and height.
140157 */
141158 item def Cuboid :> Shell {
142- attribute :>> length;
143- attribute :>> width;
144- attribute :>> height;
159+ attribute :>> length [1] ;
160+ attribute :>> width [1] ;
161+ attribute :>> height [1] ;
145162
146163 item faces : PlanarSurface [6] :>> faces {
147164 item :>> edges [4];
148165 }
149- item tf :> faces [1] ;
150- item bf :> faces [1] ;
151- item ff :> faces [1] ;
152- item rf :> faces [1] ;
153- item slf :> faces [1] ;
154- item srf :> faces [1] ;
155-
156- item edges : Line [12] :>> edges {
166+ item tf [1] :> faces;
167+ item bf [1] :> faces;
168+ item ff [1] :> faces;
169+ item rf [1] :> faces;
170+ item slf [1] :> faces;
171+ item srf [1] :> faces;
172+
173+ item :>> edges : Line [24] {
157174 item :>> vertices [2];
158175 }
159176 item tfe [2] :> edges { attribute :>> length = Cuboid::length; }
@@ -169,7 +186,7 @@ package ShapeItems {
169186 item urle [2] :> edges { attribute :>> length = Cuboid::height; }
170187 item urre [2] :> edges { attribute :>> length = Cuboid::height; }
171188
172- item vertices : Point [8] : >> vertices;
189+ item : >> vertices [24] ;
173190 item tflv [3] :> vertices;
174191 item tfrv [3] :> vertices;
175192 item trlv [3] :> vertices;
@@ -261,6 +278,8 @@ package ShapeItems {
261278 connection :WithinBoth connect bfrv [3] to bfrv [3];
262279 connection :WithinBoth connect brlv [3] to brlv [3];
263280 connection :WithinBoth connect brrv [3] to brrv [3];
281+
282+ attribute :>> genus = 0;
264283 }
265284 alias Box for Cuboid;
266285}
0 commit comments