Skip to content

Commit 6dc3a2a

Browse files
committed
Update to OCADml and OSCADml Gg adoption
commit ebc2fc0 Author: Geoff deRosenroll <geoffderosenroll@gmail.com> Date: Tue Jan 24 17:10:57 2023 -0800 Add changes entry and update dependencies commit dec9e9a Author: Geoff deRosenroll <geoffderosenroll@gmail.com> Date: Tue Jan 24 12:23:19 2023 -0800 Adjust to OCADml adopting abstract Gg vec types
1 parent 5ce65c2 commit 6dc3a2a

File tree

6 files changed

+47
-30
lines changed

6 files changed

+47
-30
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v0.2.0
2+
3+
- adjust to additional type parameter of `Scad.t` in OSCADml `v0.2.0`
4+
- add cases to catch `gg` vector type identifiers (OCADml `v0.3.0`)
5+
16
## v0.1.0
27

38
- Initial opam release of `ppx_deriving_cad`

dune-project

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
:with-test))
3030
(OCADml
3131
(and
32-
(>= 0.1.0)
32+
(>= 0.3.0)
3333
:with-test))
3434
(OSCADml
3535
(and
36-
(>= 0.1.0)
36+
(>= 0.2.0)
37+
:with-test))
38+
(gg
39+
(and
40+
(>= 1.0.0)
3741
:with-test))
3842
(ppxlib
3943
(>= 0.22.2))

ppx_deriving_cad.opam

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ depends: [
1515
"dune" {>= "3.2"}
1616
"ocaml" {>= "4.14.0"}
1717
"base" {>= "0.14.1" & with-test}
18-
"OCADml" {>= "0.1.0" & with-test}
19-
"OSCADml" {>= "0.1.0" & with-test}
18+
"OCADml" {>= "0.3.0" & with-test}
19+
"OSCADml" {>= "0.2.0" & with-test}
20+
"gg" {>= "1.0.0" & with-test}
2021
"ppxlib" {>= "0.22.2"}
2122
"ppx_inline_test" {with-test}
2223
"odoc" {with-doc}

src/dim.ml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open! Ast_builder.Default
44
type t =
55
| D2
66
| D3
7-
| Poly of string * string * string
7+
| Poly of string * string * string * string
88

99
type error =
1010
| MixedDimensions
@@ -48,10 +48,10 @@ let rec check ~loc dim = function
4848
| [%type: OCADml.Poly2.t]
4949
| [%type: Bezier2.t]
5050
| [%type: OCADml.Bezier2.t]
51-
| [%type: (V2.t, float, Affine2.t) Scad.t]
52-
| [%type: (v2, float, Affine2.t) Scad.t]
53-
| [%type: (OCADml.V2.t, float, OCADml.Affine2.t) OCADml.Scad.t]
54-
| [%type: (OCADml.v2, float, OCADml.Affine2.t) OCADml.Scad.t]
51+
| [%type: ([ `D2 ], V2.t, float, Affine2.t) Scad.t]
52+
| [%type: ([ `D2 ], v2, float, Affine2.t) Scad.t]
53+
| [%type: ([ `D2 ], OCADml.V2.t, float, OCADml.Affine2.t) OCADml.Scad.t]
54+
| [%type: ([ `D2 ], OCADml.v2, float, OCADml.Affine2.t) OCADml.Scad.t]
5555
| [%type: Scad.d2]
5656
| [%type: OSCADml.Scad.d2] ->
5757
( match dim with
@@ -70,31 +70,36 @@ let rec check ~loc dim = function
7070
| [%type: OCADml.Bezier3.t]
7171
| [%type: Mesh.t]
7272
| [%type: OCADml.Mesh.t]
73-
| [%type: (V3.t, V3.t, Affine3.t) Scad.t]
74-
| [%type: (v3, v3, Affine3.t) Scad.t]
75-
| [%type: (OCADml.V3.t, OCADml.V3.t, OCADml.Affine3.t) OSCADml.Scad.t]
76-
| [%type: (OCADml.v3, OCADml.v3, OCADml.Affine3.t) OSCADml.Scad.t]
73+
| [%type: ([ `D3 ], V3.t, V3.t, Affine3.t) Scad.t]
74+
| [%type: ([ `D3 ], v3, v3, Affine3.t) Scad.t]
75+
| [%type: ([ `D3 ], OCADml.V3.t, OCADml.V3.t, OCADml.Affine3.t) OSCADml.Scad.t]
76+
| [%type: ([ `D3 ], OCADml.v3, OCADml.v3, OCADml.Affine3.t) OSCADml.Scad.t]
7777
| [%type: Scad.d3]
7878
| [%type: OSCADml.Scad.d3] ->
7979
( match dim with
8080
| Some D2 -> Error MixedDimensions
8181
| Some (Poly _) -> Error PolyCollapse
8282
| _ -> Ok (Some D3) )
8383
| [%type:
84-
( [%t? { ptyp_desc = Ptyp_var s; _ }]
84+
( [%t? { ptyp_desc = Ptyp_var d; _ }]
85+
, [%t? { ptyp_desc = Ptyp_var s; _ }]
8586
, [%t? { ptyp_desc = Ptyp_var r; _ }]
8687
, [%t? { ptyp_desc = Ptyp_var a; _ }] )
8788
Scad.t]
8889
| [%type:
89-
( [%t? { ptyp_desc = Ptyp_var s; _ }]
90+
( [%t? { ptyp_desc = Ptyp_var d; _ }]
91+
, [%t? { ptyp_desc = Ptyp_var s; _ }]
9092
, [%t? { ptyp_desc = Ptyp_var r; _ }]
9193
, [%t? { ptyp_desc = Ptyp_var a; _ }] )
9294
OSCADml.Scad.t] ->
9395
( match dim with
9496
| Some (D2 | D3) -> Error PolyCollapse
95-
| Some (Poly (s', r', a')) as d
96-
when String.equal s s' && String.equal r r' && String.equal a a' -> Ok d
97-
| None -> Ok (Some (Poly (s, r, a)))
97+
| Some (Poly (d', s', r', a')) as dim
98+
when String.equal d d'
99+
&& String.equal s s'
100+
&& String.equal r r'
101+
&& String.equal a a' -> Ok dim
102+
| None -> Ok (Some (Poly (d, s, r, a)))
98103
| _ -> Error PolyMismatch )
99104
| { ptyp_desc = Ptyp_tuple (hd :: cts); _ } ->
100105
let f dim' ct =

src/ppx_deriving_cad.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,16 @@ let transform_expr ~loc ~jane ~transform ~kind (ct : core_type) =
105105
aux attrs (Util.list_map_expr :: funcs) typ
106106
| [%type: ([%t? typ], [%t? _]) result] | [%type: ([%t? typ], [%t? _]) Result.t] ->
107107
aux attrs (Util.result_map_expr :: funcs) typ
108-
| [%type: ([%t? _], [%t? _], [%t? _]) Scad.t]
108+
| [%type: ([%t? _], [%t? _], [%t? _], [%t? _]) Scad.t]
109109
| [%type: Scad.d2]
110110
| [%type: Scad.d3]
111-
| [%type: ([%t? _], [%t? _], [%t? _]) OSCADml.Scad.t]
111+
| [%type: ([%t? _], [%t? _], [%t? _], [%t? _]) OSCADml.Scad.t]
112112
| [%type: OSCADml.Scad.d2]
113113
| [%type: OSCADml.Scad.d3] -> inner_expr attrs (fix_id "OSCADml" "Scad"), funcs
114-
| [%type: v2] | [%type: OCADml.v2] -> inner_expr attrs (fix_id "OCADml" "V2"), funcs
115-
| [%type: v3] | [%type: OCADml.v3] -> inner_expr attrs (fix_id "OCADml" "V3"), funcs
114+
| [%type: v2] | [%type: OCADml.v2] | [%type: GG.v2] | [%type: GG.V2.t] ->
115+
inner_expr attrs (fix_id "OCADml" "V2"), funcs
116+
| [%type: v3] | [%type: OCADml.v3] | [%type: GG.v3] | [%type: GG.V3.t] ->
117+
inner_expr attrs (fix_id "OCADml" "V3"), funcs
116118
| { ptyp_desc = Ptyp_tuple cts; _ } ->
117119
let tup_expr =
118120
let argn n = Printf.sprintf "arg%i" n in
@@ -244,7 +246,7 @@ let transformer_intf ~ctxt (_rec_flag, type_declarations) =
244246
, cad_type_arrow ~lbl:(Optional "about") ~loc "V3"
245247
, cad_type_arrow ~loc "Affine3"
246248
, transforms_3d )
247-
| Poly (space, rot, affine) ->
249+
| Poly (_, space, rot, affine) ->
248250
( var_type_arrow ~loc space
249251
, var_type_arrow ~loc rot
250252
, var_type_arrow ~lbl:(Optional "about") ~loc space

test/ppx_deriving_scad_test.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ module type FunType = sig
3333
end
3434

3535
module PolyScads : sig
36-
type ('s, 'r, 'a) t =
37-
{ a : ('s, 'r, 'a) Scad.t
38-
; b : ('s, 'r, 'a) Scad.t
36+
type ('d, 's, 'r, 'a) t =
37+
{ a : ('d, 's, 'r, 'a) Scad.t
38+
; b : ('d, 's, 'r, 'a) Scad.t
3939
}
4040
[@@deriving cad]
4141
end = struct
42-
type ('s, 'r, 'a) t =
43-
{ a : ('s, 'r, 'a) Scad.t
44-
; b : ('s, 'r, 'a) Scad.t
42+
type ('d, 's, 'r, 'a) t =
43+
{ a : ('d, 's, 'r, 'a) Scad.t
44+
; b : ('d, 's, 'r, 'a) Scad.t
4545
}
4646
[@@deriving cad]
4747
end
@@ -141,7 +141,7 @@ let%test "rotate_about_pair" =
141141
let a = { reg = v3 5. 5. 0.; unit = v3 0. 1. 0. }
142142
and r = v3 0. 0. (Float.pi /. 2.)
143143
and p = v3 0. 5. 0. in
144-
let rot = zrot_vec_pair ~about:p r.z a in
144+
let rot = zrot_vec_pair ~about:p (V3.z r) a in
145145
V3.equal rot.reg (V3.rotate ~about:p r a.reg) && V3.equal rot.unit (V3.rotate r a.unit)
146146

147147
let%test "unit_prevents_translate" =

0 commit comments

Comments
 (0)