-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Analytical CSG (Constructive Solid Geometry) library -- -- Analytical CSG (Constructive Solid Geometry) library @package csg @version 0.1 -- | Types and routines for constructive solid geometry. -- -- This module provides constructors for complex solids as well as -- membership predicates and routines to compute intersections of such -- solids with a ray. module Data.CSG -- | CSG solid is a recursive composition of primitive objects or other -- solids. data Solid -- | A half-space defined by an arbitary point on the boundary plane and an -- outward normal (not necessarily a unit vector). plane :: Point -> Vec3 -> Solid -- | A sphere defined by a center point and a radius. sphere :: Vec3 -> Double -> Solid -- | An infinite circular cylinder defined by two arbitary points on axis -- and a radius. cylinder :: Point -> Point -> Double -> Solid -- | An infinite right circular cone defined by an outward axis vector, an -- apex point and an angle between the generatrix and the axis (in -- degrees, less than 90). cone :: Vec3 -> Point -> Double -> Solid -- | A rectangular cuboid with faces parallel to axes, defined by two -- opposite vertices. cuboid :: Point -> Point -> Solid -- | A conical frustum defined by two points on its axis with radii at that -- points. One of radii may be zero (in which case one of frustum ends -- will be the apex). coneFrustum :: (Point, Double) -> (Point, Double) -> Solid -- | A finite right circular cylinder defined by two points on its top and -- bottom and a radius. cylinderFrustum :: Point -> Point -> Double -> Solid -- | Intersection of two solids. intersect :: Solid -> Solid -> Solid -- | Union of two solids. unite :: Solid -> Solid -> Solid -- | Complement to a solid (normals flipped). complement :: Solid -> Solid -- | Subtract a solid from another. subtract :: Solid -> Solid -> Solid type Point = Vec3 -- | We use CVec3 as a simple replacement for (Double, Double, -- Double). CVec3 implements a contiguous storage scheme for -- Unboxed and Storable vectors which shows better performance. Compile -- this package with triples flag and run benchmarks to see the -- difference. type Vec3 = CVec3 -- | A ray described by the equation p(t) = p_0 + v * t with an -- initial point p_0 and a direction v. Substituting a -- specific time t' in the equation yields a position of a point -- p(t') on the ray. For negative values of t', -- position precedes the initial point. newtype Ray Ray :: (Point, Vec3) -> Ray -- | A point at which a ray intersects a surface, given as a distance from -- the ray's initial point and an outward normal to the surface at the -- hit point. If hit is in infinity, then normal is Nothing. If -- the hit occures on the same line but precedes the initial point of the -- ray, the distance is negative. -- -- Note that this datatype is strict only on first argument: we do not -- compare normals when combining traces and thus do not force -- calculation of normals. data HitPoint HitPoint :: !Double -> (Maybe Vec3) -> HitPoint -- | A segment of ray inside a solid. type HitSegment = (Pair HitPoint HitPoint) -- | Trace of a ray/line on a solid is a list of segments corresponding to -- the portions of the ray inside the solid. -- --
--   O - ray
--    -- >                         -- >                          +------------
--   
type Trace = [HitSegment] -- | Trace of a ray on a solid. trace :: Solid -> Ray -> Trace -- | Find the next point where a ray hits a solid, if any. -- -- Here we consider only future intersections: the HitPoint is -- guaranteed to have non-negative distance (unlike when using -- trace). -- -- This means that if the ray starts inside the solid the only way to -- tell that from cast result is to compare it's direction and the -- surface normal at the hit point. cast :: Ray -> Solid -> Maybe HitPoint -- | True if the point is in inside the solid. inside :: Point -> Solid -> Bool instance GHC.Show.Show Data.CSG.Solid instance GHC.Classes.Eq Data.CSG.Solid instance GHC.Show.Show Data.CSG.HitPoint instance GHC.Classes.Eq Data.CSG.HitPoint instance Test.QuickCheck.Arbitrary.Arbitrary Data.CSG.Solid instance GHC.Classes.Ord Data.CSG.HitPoint -- | Parser for CSG solid definition format. The format uses text files and -- is inspired by NETGEN 4.x .geo format. -- -- Each definition may contain several solid definitions and ends with -- the top level object declaration. Right hand side of solid equations -- may reference other solids to allow composing of complex solids. -- --
--   # comment
--   
--   # define several primitives
--   solid b1 = sphere (0, 0, 0; 5);
--   solid p1 = plane (0, 0, 0; 1, 0, 0);
--   
--   # define a composition
--   solid comp = b1 and p1;
--   
--   # make it the top level object
--   tlo comp;
--   
-- -- Statements must end with a semicolon (newlines are optional). -- Whitespace is ignored. -- -- Multiple-solid compositions are right-associative, so b1 -- and b2 or b3 really means b1 and (b2 or b3). Keep -- simpler objects on the left and when in doubt stick to combining two -- solids at a time. -- -- Top-level object line must reference a previously defined solid. -- -- Syntax for primitives follows the signatures of CSG -- constructors for plane and sphere, but differs for -- cylinder and cone, as this module provides access only to frustums -- (cylinderFrustum and coneFrustum). -- -- module Data.CSG.Parser -- | Read solid definition. If parsing fails, return error message as a -- string. parseGeometry :: ByteString -> Either String Solid -- | Read solid definition from a file. If parsing fails, return error -- message as a string. parseGeometryFile :: FilePath -> IO (Either String Solid)