Skip to content

Commit

Permalink
some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
noinia committed Feb 3, 2025
1 parent 9d5cce7 commit de48b67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import HGeometry.Plane.LowerEnvelope.Connected.Regions
import HGeometry.Plane.LowerEnvelope.Connected.Type
import HGeometry.Point

import qualified Data.Foldable as F
import Debug.Trace
--------------------------------------------------------------------------------
-- * The naive O(n^4) time algorithm.

Expand All @@ -50,9 +52,14 @@ computeVertexForm :: ( Plane_ plane r, Ord plane, Ord r, Fractional r, Fo
, Show plane, Show r
)
=> set plane -> VertexForm r plane
computeVertexForm planes = NEMap.unsafeFromMap
computeVertexForm planes = f . NEMap.nonEmptyMap
. unionsWithKey mergeDefiners
. traceShowWith ("foo",F.toList planes,)
. map (asVertex planes) $ uniqueTriplets planes
where
f = \case
Nothing -> error "BruteForce.computeVertexForm: no vertices !?"
Just x -> x

asVertex :: (Plane_ plane r, Foldable f, Ord plane, Ord r, Fractional r)
=> f plane -> Three plane -> Map (Point 3 r) (Definers plane)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ computeVertexForm' :: forall plane r.
computeVertexForm' hs = NEMap.unsafeFromMap $ lowerEnvelope hs
where
n = length hs
r = sqrt . sqrt @Double . fromIntegral $ n
r = max 3 $ sqrt . sqrt @Double . fromIntegral $ n

lowerEnvelope :: Foldable set => set plane -> Map (Point 3 r) (Definers plane)
lowerEnvelope planes | traceShow (toList planes) False = undefined
lowerEnvelope planes = NEMap.mapMaybe hasNoConflict verticesRNet
<>
foldMap lowerEnvelopeIn triangulatedEnv
lowerEnvelope planes | traceShow ("LE",toList planes) False = undefined
lowerEnvelope planes
| null planes = mempty
| otherwise = NEMap.mapMaybe hasNoConflict verticesRNet
<>
foldMap lowerEnvelopeIn triangulatedEnv
where
(rNet,remaining) = takeSample (round $ r * logBase 2 r) planes

Expand All @@ -86,7 +88,7 @@ computeVertexForm' hs = NEMap.unsafeFromMap $ lowerEnvelope hs
lowerEnvelopeIn :: (Foldable set, Monoid (set plane))
=> Triangular r (Point 2 r :+ set plane)
-> Map (Point 3 r) (Definers plane)
lowerEnvelopeIn tri | traceShow (toList $ conflictListOf tri) False = undefined
lowerEnvelopeIn tri | traceShow ("LEI",toList $ conflictListOf tri) False = undefined
lowerEnvelopeIn tri = Map.filterWithKey (inRegion tri)
$ lowerEnvelope (conflictListOf tri)

Expand Down
6 changes: 3 additions & 3 deletions hgeometry/test/Plane/LowerEnvSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ spec :: Spec
spec = describe "Lower Envelope tests" $ do
it "manual" $
let seed = 0
planes = NonDegenerate $ NonEmpty.fromList [ Plane 0 1 2
, Plane 3 (-2) 5
, Plane (-1) 8 (-1)
planes = NonDegenerate $ NonEmpty.fromList [ Plane 1 0 2
, Plane (-1) 0 3
, Plane 0 1 10
]
in Randomized.computeVertexForm (mkStdGen seed) planes
`shouldBe`
Expand Down

0 comments on commit de48b67

Please sign in to comment.