module Graphics.Implicit.Primitives where
import Graphics.Implicit.Definitions
import Data.List (sortBy)
import Graphics.Implicit.MathUtil (pack)
import Graphics.Implicit.ObjectUtil (getBox2, getBox3, getImplicit2, getImplicit3)
sphere ::
ℝ
-> SymbolicObj3
sphere r = Sphere r
rect3R ::
ℝ
-> ℝ3
-> ℝ3
-> SymbolicObj3
rect3R = Rect3R
cylinder2 ::
ℝ
-> ℝ
-> ℝ
-> SymbolicObj3
cylinder2 r1 r2 h = Cylinder h r1 r2
cylinder r = cylinder2 r r
circle ::
ℝ
-> SymbolicObj2
circle = Circle
rectR ::
ℝ
-> ℝ2
-> ℝ2
-> SymbolicObj2
rectR = RectR
polygonR ::
ℝ
-> [ℝ2]
-> SymbolicObj2
polygonR = PolygonR
polygon = polygonR 0
class Object obj vec | obj -> vec where
translate ::
vec
-> obj
-> obj
scale ::
vec
-> obj
-> obj
complement ::
obj
-> obj
unionR ::
ℝ
-> [obj]
-> obj
intersectR ::
ℝ
-> [obj]
-> obj
differenceR ::
ℝ
-> [obj]
-> obj
outset ::
ℝ
-> obj
-> obj
shell ::
ℝ
-> obj
-> obj
getBox ::
obj
-> (vec, vec)
getImplicit ::
obj
-> (vec -> ℝ)
implicit ::
(vec -> ℝ)
-> (vec, vec)
-> obj
instance Object SymbolicObj2 ℝ2 where
translate = Translate2
scale = Scale2
complement = Complement2
unionR = UnionR2
intersectR = IntersectR2
differenceR = DifferenceR2
outset = Outset2
shell = Shell2
getBox = getBox2
getImplicit = getImplicit2
implicit a b= EmbedBoxedObj2 (a,b)
instance Object SymbolicObj3 ℝ3 where
translate = Translate3
scale = Scale3
complement = Complement3
unionR = UnionR3
intersectR = IntersectR3
differenceR = DifferenceR3
outset = Outset3
shell = Shell3
getBox = getBox3
getImplicit = getImplicit3
implicit a b= EmbedBoxedObj3 (a,b)
union = unionR 0
difference = differenceR 0
intersect = intersectR 0
extrudeR = ExtrudeR
extrudeRM = ExtrudeRM
rotateExtrude = RotateExtrude
extrudeOnEdgeOf = ExtrudeOnEdgeOf
rotate3 = Rotate3
rotate3V = Rotate3V
pack3 :: ℝ2 -> ℝ -> [SymbolicObj3] -> Maybe SymbolicObj3
pack3 (dx, dy) sep objs =
let
boxDropZ ((a,b,c),(d,e,f)) = ((a,b),(d,e))
withBoxes :: [(Box2, SymbolicObj3)]
withBoxes = map (\obj -> ( boxDropZ $ getBox3 obj, obj)) objs
in case pack ((0,0),(dy,dy)) sep withBoxes of
(a, []) -> Just $ union $ map (\((x,y),obj) -> translate (x,y,0) obj) a
_ -> Nothing
rotate = Rotate2
pack2 :: ℝ2 -> ℝ -> [SymbolicObj2] -> Maybe SymbolicObj2
pack2 (dx, dy) sep objs =
let
withBoxes :: [(Box2, SymbolicObj2)]
withBoxes = map (\obj -> ( getBox2 obj, obj)) objs
in case pack ((0,0),(dy,dy)) sep withBoxes of
(a, []) -> Just $ union $ map (\((x,y),obj) -> translate (x,y) obj) a
_ -> Nothing