Skip to content

Commit

Permalink
Add mirror primitives
Browse files Browse the repository at this point in the history
This leaves the integration with the parser for a later patch.
  • Loading branch information
bgamari committed Dec 1, 2012
1 parent 11855f3 commit 6352721
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Graphics/Implicit/Definitions.hs
Expand Up @@ -102,6 +102,7 @@ data SymbolicObj2 =
| IntersectR2 [SymbolicObj2] | IntersectR2 [SymbolicObj2]
-- Simple transforms -- Simple transforms
| Translate2 ℝ2 SymbolicObj2 | Translate2 ℝ2 SymbolicObj2
| Mirror2 ℝ2 SymbolicObj2
| Scale2 ℝ2 SymbolicObj2 | Scale2 ℝ2 SymbolicObj2
| Rotate2 SymbolicObj2 | Rotate2 SymbolicObj2
-- Boundary mods -- Boundary mods
Expand All @@ -125,6 +126,7 @@ data SymbolicObj3 =
| DifferenceR3 [SymbolicObj3] | DifferenceR3 [SymbolicObj3]
-- Simple transforms -- Simple transforms
| Translate3 ℝ3 SymbolicObj3 | Translate3 ℝ3 SymbolicObj3
| Mirror3 ℝ3 SymbolicObj3
| Scale3 ℝ3 SymbolicObj3 | Scale3 ℝ3 SymbolicObj3
| Rotate3 (,,) SymbolicObj3 | Rotate3 (,,) SymbolicObj3
-- Boundary mods -- Boundary mods
Expand Down
9 changes: 9 additions & 0 deletions Graphics/Implicit/ObjectUtil/GetBox2.hs
Expand Up @@ -68,6 +68,15 @@ getBox2 (Translate2 v symbObj) =
then ((0,0),(0,0)) then ((0,0),(0,0))
else (a^+^v, b^+^v) else (a^+^v, b^+^v)


getBox2 (Mirror2 a symbObj) =
let
(a,b) = getBox2 symbObj
mirror p =
let c = 2 * (p a) / (a a)
in c *^ a ^-^ p
in
(mirror a, mirror b)

getBox2 (Scale2 s symbObj) = getBox2 (Scale2 s symbObj) =
let let
(a,b) = getBox2 symbObj (a,b) = getBox2 symbObj
Expand Down
9 changes: 9 additions & 0 deletions Graphics/Implicit/ObjectUtil/GetBox3.hs
Expand Up @@ -79,6 +79,15 @@ getBox3 (Translate3 v symbObj) =
in in
(a^+^v, b^+^v) (a^+^v, b^+^v)


getBox3 (Mirror3 a symbObj) =
let
(a,b) = getBox3 symbObj
mirror p =
let c = 2 * (p a) / (a a)
in p ^-^ c *^ a
in
(mirror a, mirror b)

getBox3 (Scale3 s symbObj) = getBox3 (Scale3 s symbObj) =
let let
(a,b) = getBox3 symbObj (a,b) = getBox3 symbObj
Expand Down
9 changes: 9 additions & 0 deletions Graphics/Implicit/ObjectUtil/GetImplicit2.hs
Expand Up @@ -75,6 +75,15 @@ getImplicit2 (Translate2 v symbObj) =
in in
\p -> obj (p ^-^ v) \p -> obj (p ^-^ v)


getImplicit2 (Mirror2 a symbObj) =
let
obj = getImplicit2 symbObj
in
\p ->
let
c = 2 * (p a) / (a a)
in obj $ c *^ a ^-^ p

getImplicit2 (Scale2 s@(sx,sy) symbObj) = getImplicit2 (Scale2 s@(sx,sy) symbObj) =
let let
obj = getImplicit2 symbObj obj = getImplicit2 symbObj
Expand Down
9 changes: 9 additions & 0 deletions Graphics/Implicit/ObjectUtil/GetImplicit3.hs
Expand Up @@ -77,6 +77,15 @@ getImplicit3 (Scale3 s@(sx,sy,sz) symbObj) =
in in
\p -> k * obj (p ⋯/ s) \p -> k * obj (p ⋯/ s)


getImplicit3 (Mirror3 a symbObj) =
let
obj = getImplicit3 symbObj
in
\p ->
let
c = 2 * (p a) / (a a)
in obj $ p ^-^ c *^ a

getImplicit3 (Rotate3 (yz, xz, xy) symbObj) = getImplicit3 (Rotate3 (yz, xz, xy) symbObj) =
let let
obj = getImplicit3 symbObj obj = getImplicit3 symbObj
Expand Down
8 changes: 8 additions & 0 deletions Graphics/Implicit/Primitives.hs
Expand Up @@ -71,6 +71,12 @@ class Object obj vec | obj -> vec where
-> obj -- ^ Object to translate -> obj -- ^ Object to translate
-> obj -- ^ Resulting object -> obj -- ^ Resulting object


-- | Mirror an object
mirror ::
vec -- ^ Vector defining plane to mirror across
-> obj -- ^ Object to mirror
-> obj -- ^ Resulting mirrored object

-- | Scale an object -- | Scale an object
scale :: scale ::
vec -- ^ Amount to scale by vec -- ^ Amount to scale by
Expand Down Expand Up @@ -130,6 +136,7 @@ class Object obj vec | obj -> vec where


instance Object SymbolicObj2 ℝ2 where instance Object SymbolicObj2 ℝ2 where
translate = Translate2 translate = Translate2
mirror = Mirror2
scale = Scale2 scale = Scale2
complement = Complement2 complement = Complement2
unionR = UnionR2 unionR = UnionR2
Expand All @@ -143,6 +150,7 @@ instance Object SymbolicObj2 ℝ2 where


instance Object SymbolicObj3 ℝ3 where instance Object SymbolicObj3 ℝ3 where
translate = Translate3 translate = Translate3
mirror = Mirror3
scale = Scale3 scale = Scale3
complement = Complement3 complement = Complement3
unionR = UnionR3 unionR = UnionR3
Expand Down

0 comments on commit 6352721

Please sign in to comment.