Skip to content

Commit

Permalink
nicely drawing halfplanes :)
Browse files Browse the repository at this point in the history
  • Loading branch information
noinia committed Mar 2, 2025
1 parent 3191cb7 commit aaa6c34
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ipe version="70005" creator="HGeometry"><ipestyle name="basic">
<ipe version="70005" creator="HGeometry"><ipestyle name="opacities">
<opacity name="10%" value="0.1"/>
<opacity name="20%" value="0.2"/>
<opacity name="30%" value="0.3"/>
<opacity name="40%" value="0.4"/>
<opacity name="50%" value="0.5"/>
<opacity name="60%" value="0.6"/>
<opacity name="70%" value="0.7"/>
<opacity name="80%" value="0.8"/>
<opacity name="90%" value="0.9"/>
</ipestyle><ipestyle name="basic">
<color name="red" value="1 0 0"/>
<color name="green" value="0 1 0"/>
<color name="blue" value="0 0 1"/>
Expand Down Expand Up @@ -140,7 +150,12 @@
160.000000000000 208.000000000000 l
112.000000000000 176.000000000000 l
h
</path><group><path>-708.800000000000 -1000.000000000000 m
</path><group><path fill="gray" opacity="20%">757.866666666666 1000.000000000000 m
-708.800000000000 -1000.000000000000 l
-1000.000000000000 -1000.000000000000 l
-1000.000000000000 1000.000000000000 l
h
</path><path>-708.800000000000 -1000.000000000000 m
757.866666666666 1000.000000000000 l
</path></group><group><path fill="red">103.255813953488 107.348837209302 m
172.487804878048 201.756097560975 l
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ipe version="70005" creator="HGeometry"><ipestyle name="basic">
<ipe version="70005" creator="HGeometry"><ipestyle name="opacities">
<opacity name="10%" value="0.1"/>
<opacity name="20%" value="0.2"/>
<opacity name="30%" value="0.3"/>
<opacity name="40%" value="0.4"/>
<opacity name="50%" value="0.5"/>
<opacity name="60%" value="0.6"/>
<opacity name="70%" value="0.7"/>
<opacity name="80%" value="0.8"/>
<opacity name="90%" value="0.9"/>
</ipestyle><ipestyle name="basic">
<color name="red" value="1 0 0"/>
<color name="green" value="0 1 0"/>
<color name="blue" value="0 0 1"/>
Expand Down Expand Up @@ -140,7 +150,12 @@
336.000000000000 112.000000000000 l
224.000000000000 208.000000000000 l
h
</path><group><path>-1000.000000000000 520.066070397942 m
</path><group><path fill="gray" opacity="20%">1000.000000000000 -174.493340015153 m
-1000.000000000000 520.066070397942 l
-1000.000000000000 1000.000000000000 l
1000.000000000000 1000.000000000000 l
h
</path><path>-1000.000000000000 520.066070397942 m
1000.000000000000 -174.493340015153 l
</path></group><group><path fill="red">96.464620234993 139.286160313325 m
258.606691901969 82.977509463238 l
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Data.Functor.Contravariant (phantom)
import Data.List.NonEmpty (NonEmpty(..))
import qualified Data.List.NonEmpty as NonEmpty
import Data.Maybe (isJust, mapMaybe, maybeToList)
import qualified Data.Text as Text
import Data.Traversable
import Data.Vector.NonEmpty (NonEmptyVector)
import Golden
Expand Down Expand Up @@ -526,9 +527,8 @@ testIpe inFp outFp = describe (show inFp) $ do
]
describe "compute intersection" $
goldenWith [osp|data/test-with-ipe/Polygon/Simple/|]
(ipeContentGolden { name = outFp })
content'
pure ()
(ipeFileGolden { name = outFp })
(addStyleSheet opacitiesStyle $ singlePageFromContent content')


renderComponent :: forall vertex f r.
Expand Down Expand Up @@ -556,11 +556,23 @@ instance (Fractional r, Ord r, Show r) => HasDefaultIpeOut (HalfSpaceF (LinePV 2
type DefaultIpeOut (HalfSpaceF (LinePV 2 r)) = Group
defIO = ipeHalfPlane

-- | Default rendering of halfplanes
ipeHalfPlane :: (Show r, Fractional r, Ord r) => IpeOut (HalfSpaceF (LinePV 2 r)) Group r
ipeHalfPlane = ipeHalfPlaneIn defaultBox

-- | Draw a halfplane in the given rectangle.
--
-- We draw both the border (in black) and the interior (20% transparant gray) of the halfpace
ipeHalfPlaneIn :: (Ord r, Fractional r, Show r)
=> Rectangle (Point 2 r) -> IpeOut (HalfSpaceF (LinePV 2 r)) Group r
ipeHalfPlaneIn rect' hl = ipeGroup [ iO $ ipeLineIn rect' (hl^.boundingHyperPlane)
]
-- TDOO: I think we also want to display the interior
ipeHalfPlaneIn rect' hl = case hl `intersect` rect' of
Nothing -> ipeGroup [] -- this should not really happen I guess?
Just is -> case is of
ActualPolygon interior -> ipeGroup [ iO $ ipeSimplePolygon interior
! attr SFill gray
! attr SOpacity (Text.pack "20%")
, boundary
]
_ -> ipeGroup [ boundary ]
where
boundary = iO $ ipeLineIn rect' (hl^.boundingHyperPlane)

0 comments on commit aaa6c34

Please sign in to comment.