Comments (3)
Hello @postspectacular, @heyarne.
As per the official guide (https://clojure.org/reference/reader#tagged_literals)
"Reader tags without namespace qualifiers are reserved for Clojure."
So maybe #vec2
can be changed to #thi.ng/vec2
?
It seems print-method
definitions are only needed for the Clojure part of vectors.
For ClojureScript, vectors already implement IPrintWithWriter
https://github.com/thi-ng/geom/blob/feature/no-org/src/thi/ng/geom/vector.cljc#L361-L364
The code you tried for the data readers:
{'thi.ng.geom.types.Circle2 c/circle}
will only work in Clojure because the reader will automatically initialize the record without calling the function you specified. But if you try to run this in ClojureScript, c/circle
will be called with a map, and will return:
#thi.ng.geom.types.Circle2{:p [0 0], :r {:p [0 0], :r 100}}
.
The proper way would be to use the automatically generated map->Circle2
function.
'thi.ng.geom.types.Circle2 thi.ng.geom.types/map->Circle2
I've made the proposed changes in my local repository. It needs more testing but so far it seems to work and I can send a PR -- dimovich@e0aa76a
from geom.
Hey @heyarne! I don't remember the specifics, but serialization related to pr-writer
& print-method
stuff used to be semi-magic, undocumented and had some weird quirks & differences between CLJ & CLJS. It seems things have changed/improved since 2014 😄 ... We could try adding the following multimethod impls and test/experiment more with those:
(require '[thi.ng.geom.vector :as v])
(defmethod print-method thi.ng.geom.vector.Vec2 [a ^java.io.Writer w]
(.write w (print-str "#vec2" (.toString a))))
(defmethod print-method thi.ng.geom.vector.Vec3 [a ^java.io.Writer w]
(.write w (print-str "#vec3" (.toString a))))
(v/vec2 10 20)
; #vec2 [10.0 20.0]
Testing this with *data-readers*
seems to work now:
(require
'[thi.ng.geom.core :as g]
'[thi.ng.geom.circle :as c])
(def readers {
'thi.ng.geom.types.Circle2 c/circle
'vec2 v/vec2
})
(def foo (binding [*data-readers* readers]
(read-string (pr-str (c/circle 100)))))
; #'user/foo
foo
; #thi.ng.geom.types.Circle2{:p #vec2 [0.0 0.0], :r 100.0}
(g/as-polygon foo 3)
; #thi.ng.geom.types.Polygon2{:points [#vec2 [100.0 0.0] #vec2 [-49.99999999999998 86.60254037844388] #vec2 [-50.00000000000004 -86.60254037844383]]}
I haven't got bandwidth to test this further right now, but if you do and find it's working, then I'd be grateful for a PR. Also related to this (and nice for UX/DX) would be adding a data_readers.cljc
file...
from geom.
Thanks, @dimovich - sure my Clojure foo is slowly getting rusty! I had a hunch about map->Circle2
probably being the right choice, but only quickly tested this in the Clojure REPL and it seemed to work... These changes look good & thank you for offering a PR, looking forward to it!
from geom.
Related Issues (20)
- [CLJS] Replacement for byte-array in commits->matrix for GitHub heatmap?
- Force Directed Graph layout HOT 1
- vector.org xforms in to vector.clj bot vector.cljs when building development branch HOT 1
- Getting error on latest clojurescript HOT 3
- question about drawing 3d objects in worldwind HOT 3
- inconsistent results in `subdivide` for rects divided six or seven times HOT 4
- ml group wants you HOT 2
- Octree gives various clojure.lang level errors HOT 11
- how to export step/igs/webgl from Obj? HOT 4
- How to create the smooth perfect mesh on 3d data points i.e. ply file using geom
- Missing IMathOps :- method for java.lang.Double when using csg/mesh->csg HOT 4
- How have you enhanced your Stacked intervals?
- Bar plots can't be drawn with a negative y-axis
- Should g/IArea always return absolute value of area?
- Handle degenerate cases in circumcircle-raw, triangle-spec
- `thi.ng.geom.polygon/tesselate*` sometimes returns nil for certain pt orderings of polygons HOT 1
- JOGL examples not working HOT 3
- Incomplete SVG path specfication HOT 4
- Unable to specify colors per vertex
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geom.