Permalink
Browse files

Merge pull request #47 from canadaduane/cleanup

Cleanup order of functions in ObjectUtil to match Definitions
  • Loading branch information...
colah committed Apr 18, 2012
2 parents 43b311a + 6e28658 commit 32f1891e689e4bdc80bfd98aa2aafc17bb0b9871
@@ -84,20 +84,20 @@ data SymbolicObj2 =
-- | A symbolic 3D format!
data SymbolicObj3 =
- -- Some simple primitives
+ -- Primitives
Rect3R ℝ3 ℝ3
| Sphere
| Cylinder -- h r1 r2
- -- Some (rounded) CSG
+ -- (Rounded) CSG
| Complement3 SymbolicObj3
| UnionR3 [SymbolicObj3]
| IntersectR3 [SymbolicObj3]
| DifferenceR3 [SymbolicObj3]
- -- Some simple transofrms
+ -- Simple transforms
| Translate3 ℝ3 SymbolicObj3
| Scale3 ℝ3 SymbolicObj3
| Rotate3 (,,) SymbolicObj3
- -- Some boundary based transforms
+ -- Boundary mods
| Outset3 SymbolicObj3
| Shell3 SymbolicObj3
-- Misc
@@ -109,11 +109,11 @@ data SymbolicObj3 =
| ExtrudeOnEdgeOf SymbolicObj2 SymbolicObj2
deriving Show
--- | Rectiliniar 2D set
-type Rectiliniar2 = [Box2]
+-- | Rectilinear 2D set
+type Rectilinear2 = [Box2]
--- | Rectiliniar 2D set
-type Rectiliniar3 = [Box3]
+-- | Rectilinear 2D set
+type Rectilinear3 = [Box3]
-- | Make ALL the functions Showable!
-- This is very handy when testing functions in interactive mode...
@@ -14,15 +14,17 @@ import Data.List (nub)
getBox2 :: SymbolicObj2 -> Box2
-getBox2 (EmbedBoxedObj2 (obj,box)) = box
-
+-- Primitives
getBox2 (RectR r a b) = (a,b)
getBox2 (Circle r ) = ((-r, -r), (r,r))
getBox2 (PolygonR r points) = ((minimum xs, minimum ys), (maximum xs, maximum ys))
where (xs, ys) = unzip points
+-- (Rounded) CSG
+getBox2 (Complement2 symbObj) =
+ ((-infty, -infty), (infty, infty)) where infty = (1::)/(0 ::)
getBox2 (UnionR2 r symbObjs) =
let
@@ -38,6 +40,12 @@ getBox2 (UnionR2 r symbObjs) =
in
((left-r,bot-r),(right+r,top+r))
+getBox2 (DifferenceR2 r symbObjs) =
+ let
+ firstBox:_ = map getBox2 symbObjs
+ in
+ firstBox
+
getBox2 (IntersectR2 r symbObjs) =
let
boxes = map getBox2 symbObjs
@@ -51,22 +59,7 @@ getBox2 (IntersectR2 r symbObjs) =
in
((left-r,bot-r),(right+r,top+r))
-getBox2 (DifferenceR2 r symbObjs) =
- let
- firstBox:_ = map getBox2 symbObjs
- in
- firstBox
-
-getBox2 (Complement2 symbObj) =
- ((-infty, -infty), (infty, infty)) where infty = (1::)/(0 ::)
-
-getBox2 (Shell2 w symbObj) =
- let
- (a,b) = getBox2 symbObj
- d = w/(2.0::)
- in
- (a - (d,d), b + (d,d))
-
+-- Simple transforms
getBox2 (Translate2 v symbObj) =
let
(a,b) = getBox2 symbObj
@@ -96,10 +89,19 @@ getBox2 (Rotate2 θ symbObj) =
in
((minx, miny), (maxx, maxy))
-getBox2 (Outset2 d symbObj) =
+-- Boundary mods
+getBox2 (Shell2 w symbObj) =
let
(a,b) = getBox2 symbObj
+ d = w/(2.0::)
in
(a - (d,d), b + (d,d))
+getBox2 (Outset2 d symbObj) =
+ let
+ (a,b) = getBox2 symbObj
+ in
+ (a - (d,d), b + (d,d))
+-- Misc
+getBox2 (EmbedBoxedObj2 (obj,box)) = box
@@ -14,14 +14,17 @@ import Graphics.Implicit.ObjectUtil.GetBox2 (getBox2)
getBox3 :: SymbolicObj3 -> Box3
-getBox3 (EmbedBoxedObj3 (obj,box)) = box
-
-getBox3 (Cylinder h r1 r2) = ( (-r,-r,0), (r,r,h) ) where r = max r1 r2
-
+-- Primitives
getBox3 (Rect3R r a b) = (a,b)
getBox3 (Sphere r ) = ((-r, -r, -r), (r,r,r))
+getBox3 (Cylinder h r1 r2) = ( (-r,-r,0), (r,r,h) ) where r = max r1 r2
+
+-- (Rounded) CSG
+getBox3 (Complement3 symbObj) =
+ ((-infty, -infty, -infty), (infty, infty, infty)) where infty = (1::)/(0 ::)
+
getBox3 (UnionR3 r symbObjs) = ((left,bot,inward), (right,top,out))
where
boxes = map getBox3 symbObjs
@@ -59,17 +62,7 @@ getBox3 (DifferenceR3 r symbObjs) = firstBox
where
firstBox:_ = map getBox3 symbObjs
-getBox3 (Complement3 symbObj) =
- ((-infty, -infty, -infty), (infty, infty, infty)) where infty = (1::)/(0 ::)
-
-getBox3 (Shell3 w symbObj) =
- let
- (a,b) = getBox3 symbObj
- d = w/(2.0::)
- in
- (a - (d,d,d), b + (d,d,d))
-
-
+-- Simple transforms
getBox3 (Translate3 v symbObj) =
let
(a,b) = getBox3 symbObj
@@ -82,17 +75,29 @@ getBox3 (Scale3 s symbObj) =
in
(s ⋯* a, s ⋯* b)
+getBox3 (Rotate3 _ symbObj) = ( (-d, -d, -d), (d, d, d) )
+ where
+ ((x1,y1, z1), (x2,y2, z2)) = getBox3 symbObj
+ d = (sqrt (2::) *) $ maximum $ map abs [x1, x2, y1, y2, z1, z2]
+
+-- Boundary mods
+getBox3 (Shell3 w symbObj) =
+ let
+ (a,b) = getBox3 symbObj
+ d = w/(2.0::)
+ in
+ (a - (d,d,d), b + (d,d,d))
+
getBox3 (Outset3 d symbObj) =
let
(a,b) = getBox3 symbObj
in
(a - (d,d,d), b + (d,d,d))
-getBox3 (Rotate3 _ symbObj) = ( (-d, -d, -d), (d, d, d) )
- where
- ((x1,y1, z1), (x2,y2, z2)) = getBox3 symbObj
- d = (sqrt (2::) *) $ maximum $ map abs [x1, x2, y1, y2, z1, z2]
+-- Misc
+getBox3 (EmbedBoxedObj3 (obj,box)) = box
+-- 2D Based
getBox3 (ExtrudeR r symbObj h) = ((x1,y1,0),(x2,y2,h))
where
((x1,y1),(x2,y2)) = getBox2 symbObj
@@ -105,13 +110,10 @@ getBox3 (ExtrudeRMod r mod symbObj h) =
in
((x1 - dx, y1 - dy, 0),(x2 + dx, y2+ dy, h))
-
-
getBox3 (ExtrudeOnEdgeOf symbObj1 symbObj2) =
let
((ax1,ay1),(ax2,ay2)) = getBox2 symbObj1
((bx1,by1),(bx2,by2)) = getBox2 symbObj2
in
((bx1+ax1, by1+ax1, ay2), (bx2+ax2, by2+ax2, ay2))
-
@@ -14,13 +14,11 @@ import Data.List (nub)
getImplicit2 :: SymbolicObj2 -> Obj2
-getImplicit2 (EmbedBoxedObj2 (obj,box)) = obj
-
+-- Primitives
getImplicit2 (RectR r (x1,y1) (x2,y2)) = \(x,y) -> MathUtil.rmaximum r
[abs (x-dx/(2::)-x1) - dx/(2::), abs (y-dy/(2::)-y1) - dy/(2::)]
where (dx, dy) = (x2-x1, y2-y1)
-
getImplicit2 (Circle r ) =
\(x,y) -> sqrt (x**2 + y**2) - r
@@ -40,6 +38,12 @@ getImplicit2 (PolygonR r points) =
in
minimum dists * if isIn then - (1 :: ) else (1 :: )
+-- (Rounded) CSG
+getImplicit2 (Complement2 symbObj) =
+ let
+ obj = getImplicit2 symbObj
+ in
+ \p -> - obj p
getImplicit2 (UnionR2 r symbObjs) =
let
@@ -49,14 +53,6 @@ getImplicit2 (UnionR2 r symbObjs) =
then \p -> minimum $ map ($p) objs
else \p -> MathUtil.rminimum r $ map ($p) objs
-getImplicit2 (IntersectR2 r symbObjs) =
- let
- objs = map getImplicit2 symbObjs
- in
- if r == 0
- then \p -> maximum $ map ($p) objs
- else \p -> MathUtil.rmaximum r $ map ($p) objs
-
getImplicit2 (DifferenceR2 r symbObjs) =
let
obj:objs = map getImplicit2 symbObjs
@@ -66,35 +62,21 @@ getImplicit2 (DifferenceR2 r symbObjs) =
then \p -> maximum $ map ($p) $ obj:(map complement objs)
else \p -> MathUtil.rmaximum r $ map ($p) $ obj:(map complement objs)
-getImplicit2 (Complement2 symbObj) =
- let
- obj = getImplicit2 symbObj
- in
- \p -> - obj p
-
-getImplicit2 (Shell2 w symbObj) =
- let
- obj = getImplicit2 symbObj
+getImplicit2 (IntersectR2 r symbObjs) =
+ let
+ objs = map getImplicit2 symbObjs
in
- \p -> abs (obj p) - w/(2.0::)
+ if r == 0
+ then \p -> maximum $ map ($p) objs
+ else \p -> MathUtil.rmaximum r $ map ($p) objs
+-- Simple transforms
getImplicit2 (Translate2 v symbObj) =
let
obj = getImplicit2 symbObj
in
\p -> obj (p-v)
---getImplicit2 :: SymbolicObj2 -> (ℝ2 -> ℝ)
---getImplicit2 (Scale2 (sx,sy)@s symbObj) =
--- let
--- obj = getImplicit2 symbObj
--- in
--- \p -> s * obj (p/s)
--- \(x,y) -> max s * obj (x/s, y/s)
--- \p -> (max sx sy) * obj (p / s)
---Originally: \ℝ2 -> ℝ * (ℝ2 -> ℝ)(ℝ2 / ℝ)
---Now: \ℝ2 -> ℝ2 * (ℝ2 -> ℝ)(ℝ2 .../ ℝ2)
-
getImplicit2 (Scale2 s@(sx,sy) symbObj) =
let
obj = getImplicit2 symbObj
@@ -107,10 +89,19 @@ getImplicit2 (Rotate2 θ symbObj) =
in
\(x,y) -> obj ( cos(θ)*x + sin(θ)*y, cos(θ)*y - sin(θ)*x)
+-- Boundary mods
+getImplicit2 (Shell2 w symbObj) =
+ let
+ obj = getImplicit2 symbObj
+ in
+ \p -> abs (obj p) - w/(2.0::)
+
getImplicit2 (Outset2 d symbObj) =
let
obj = getImplicit2 symbObj
in
\p -> obj p - d
+-- Misc
+getImplicit2 (EmbedBoxedObj2 (obj,box)) = obj
Oops, something went wrong.

0 comments on commit 32f1891

Please sign in to comment.