Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralize Sorting #150

Merged
merged 47 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f6d99c2
use sortPLinesByReference more.
julialongtin Jan 14, 2024
afd0275
play with concurrency in github.
julialongtin Jan 19, 2024
6567d7b
move from PL to DL (1 of 2)
julialongtin Jan 19, 2024
6cf663f
move from PL to DL (2 of 2)
julialongtin Jan 19, 2024
83b6c21
better error messages.
julialongtin Jan 20, 2024
384ebd0
add sortPLinesByReferenceSafe, and sortPLinesWithoutReference.
julialongtin Jan 20, 2024
62df4be
add tests for sortPLinesByReferenceSafe
julialongtin Jan 21, 2024
8c75cab
add more test cases, from our golden tests.
julialongtin Jan 21, 2024
8faba70
use safe version of sortPLinesByReference.
julialongtin Jan 21, 2024
ab18a19
fix sortPLinesByReferenceSafe, remove sortedPLines.
julialongtin Jan 27, 2024
1e12780
cleanup imports.
julialongtin Jan 27, 2024
17fcda1
remove unnecessary function.
julialongtin Jan 27, 2024
5a4c6d3
speedup.
julialongtin Jan 27, 2024
18680ab
make face logic use sortPLinesWithoutReference
julialongtin Jan 27, 2024
7fd3a2e
add a unit test for a failure condition we have since fixed.
julialongtin Jan 27, 2024
daa061b
add a test for an error condition we filter out.
julialongtin Jan 27, 2024
24d9217
better error messages, and use more normal variable names.
julialongtin Jan 27, 2024
5af80b6
make outAndErrOf inlinable.
julialongtin Jan 27, 2024
9c1a823
stop sorting iNodes twice.
julialongtin Jan 27, 2024
49c42f4
rename pLine1 to pLine.
julialongtin Jan 27, 2024
f7b5f3a
Improve error display, and optimize the interface of areaBetween and …
julialongtin Jan 28, 2024
a4f95e2
change the ordering of divisions, so that they are always in counter-…
julialongtin Jan 28, 2024
93ad96d
reorder some tests, and add the now working C5 inset and face tests.
julialongtin Jan 28, 2024
8682a31
try to get concurrency to work.
julialongtin Jan 28, 2024
98c39a1
give up on concurrency changes.
julialongtin Jan 28, 2024
53bd45e
add ghc 9.6.4 to our matrix.
julialongtin Jan 28, 2024
de67892
add remove ghc 8.8.
julialongtin Jan 28, 2024
36df30a
remove ghc 9.6.
julialongtin Jan 28, 2024
1f2c917
update dependencies of ormolu.
julialongtin Jan 28, 2024
3b5ac5c
attempt to ormolu smarter.
julialongtin Jan 28, 2024
94cd235
be more specific about cabal version.
julialongtin Jan 28, 2024
49366e4
drop GHC version.
julialongtin Jan 28, 2024
3862401
stop trying to freeze for ormolu.
julialongtin Jan 28, 2024
2a0c88a
bump ormolu version.
julialongtin Jan 28, 2024
bc74fa5
bump ghc version for ormolu.
julialongtin Jan 28, 2024
7f955ce
re-add freezing.
julialongtin Jan 28, 2024
77b3227
only run CI on pushes.
julialongtin Jan 28, 2024
c129748
break CI into three stages: build, test, and haddock.
julialongtin Jan 28, 2024
d4b4253
break CI into three stages: build, test, and haddock.
julialongtin Jan 28, 2024
11bdd6b
smarter caching usage?
julialongtin Jan 28, 2024
45f67b6
continue being more specific about cacheing.
julialongtin Jan 28, 2024
4de3e74
continue being more specific about cacheing.
julialongtin Jan 28, 2024
c918db9
continue being more specific about cacheing.
julialongtin Jan 28, 2024
5c20d28
continue being more specific about cacheing.
julialongtin Jan 28, 2024
9dc726c
cache more directories.
julialongtin Jan 28, 2024
9bc1f04
caching working!
julialongtin Jan 28, 2024
a4971fd
cache more, in case of upstream changes mid-build
julialongtin Jan 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 137 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
name: Haskell CI
on:
- push

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -18,16 +22,147 @@ jobs:
fi
- name: freeze
run: cabal freeze
- uses: "actions/cache@v2"
- name: Restore build artifacts
id: build-hslice-restore
uses: "actions/cache/restore@v4"
with:
key: "${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}"
path: "${{ steps.setup-haskell-cabal.outputs.cabal-store }} dist-newstyle"
path: |
"${{ steps.setup-haskell-cabal.outputs.cabal-store }}"
~/.cabal/packages
~/.cabal/store
~/.cabal/bin
dist-newstyle
~/.local/bin
- name: Install dependencies
run: cabal build all --enable-tests --enable-benchmarks --only-dependencies
- name: build all
run: cabal build all --enable-tests --enable-benchmarks
- name: Save build artifacts
uses: "actions/cache/save@v4"
with:
key: "${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}"
path: |
"${{ steps.setup-haskell-cabal.outputs.cabal-store }}"
~/.cabal/packages
~/.cabal/store
~/.cabal/bin
dist-newstyle
~/.local/bin
strategy:
matrix:
cabal:
- '3.10'
ghc:
- '9.4.6'
- '9.2.8'
- '9.0.2'
- '8.10.7'
test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v3"
- id: setup-haskell-cabal
uses: "haskell-actions/setup@v2"
with:
cabal-version: "${{ matrix.cabal }}"
enable-stack: false
ghc-version: "${{ matrix.ghc }}"
- name: Update Hackage repository
run: cabal update
- name: cabal.project.local.ci
run: |
if [ -e cabal.project.local.ci ]; then
cp cabal.project.local.ci cabal.project.local
fi
- name: freeze
run: cabal freeze
- name: Restore build artifacts
uses: "actions/cache/restore@v4"
id: build-hslice-restore
with:
key: "${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}"
path: |
"${{ steps.setup-haskell-cabal.outputs.cabal-store }}"
~/.cabal/packages
~/.cabal/store
~/.cabal/bin
dist-newstyle
~/.local/bin
- name: Install dependencies
run: cabal build all --enable-tests --enable-benchmarks --only-dependencies
- name: build all
run: cabal build all --enable-tests --enable-benchmarks
- name: Save build artifacts
uses: "actions/cache/save@v4"
with:
key: "${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}"
path: |
"${{ steps.setup-haskell-cabal.outputs.cabal-store }}"
~/.cabal/packages
~/.cabal/store
~/.cabal/bin
dist-newstyle
~/.local/bin
- name: test all
run: cabal test test-hslice --enable-tests
strategy:
matrix:
cabal:
- '3.10'
ghc:
- '9.4.6'
- '9.2.8'
- '9.0.2'
- '8.10.7'
haddock:
needs: build
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v3"
- id: setup-haskell-cabal
uses: "haskell-actions/setup@v2"
with:
cabal-version: "${{ matrix.cabal }}"
enable-stack: false
ghc-version: "${{ matrix.ghc }}"
- name: Update Hackage repository
run: cabal update
- name: cabal.project.local.ci
run: |
if [ -e cabal.project.local.ci ]; then
cp cabal.project.local.ci cabal.project.local
fi
- name: freeze
run: cabal freeze
- name: Restore build artifacts
uses: "actions/cache/restore@v4"
id: build-hslice-restore
with:
key: "${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}"
path: |
"${{ steps.setup-haskell-cabal.outputs.cabal-store }}"
~/.cabal/packages
~/.cabal/store
~/.cabal/bin
dist-newstyle
~/.local/bin
- name: Install dependencies
run: cabal build all --enable-tests --enable-benchmarks --only-dependencies
- name: build all
run: cabal build all --enable-tests --enable-benchmarks
- name: Save build artifacts
uses: "actions/cache/save@v4"
with:
key: "${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}"
path: |
"${{ steps.setup-haskell-cabal.outputs.cabal-store }}"
~/.cabal/packages
~/.cabal/store
~/.cabal/bin
dist-newstyle
~/.local/bin
- name: haddock all
run: cabal haddock all
strategy:
Expand All @@ -39,8 +174,3 @@ jobs:
- '9.2.8'
- '9.0.2'
- '8.10.7'
- '8.8.4'
name: Haskell CI
on:
- push
- pull_request
24 changes: 16 additions & 8 deletions .github/workflows/ormolu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ jobs:
ormolu:
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v1"
- uses: "actions/checkout@v3"

- uses: "haskell/actions/setup@v1"
- uses: "haskell-actions/setup@v2"
with:
cabal-version: "${{ matrix.cabal }}"
enable-stack: false
ghc-version: "${{ matrix.ghc }}"

- name: Update Hackage repository
run: cabal update
- name: cabal.project.local.ci
run: |
if [ -e cabal.project.local.ci ]; then
cp cabal.project.local.ci cabal.project.local
fi
- name: freeze
run: cabal freeze
- uses: "actions/cache@v2"
name: Cache
with:
key: "${{ runner.os }}"
key: "${{ runner.os }}-${{ matrix.ghc }}-cabal-${{ hashFiles('cabal.project.freeze') }}"
path: |
"${{ steps.setup-haskell-cabal.outputs.cabal-store }}"
~/.cabal/packages
Expand All @@ -32,11 +40,11 @@ jobs:
run: |
export PATH=$PATH:$HOME/.cabal/bin:$HOME/.local/bin
export ORMOLU_VERSION=$(cat ./layout/ormolu.version)
(ormolu -v 2>/dev/null | grep -q $ORMOLU_VERSION) || (cabal update && cabal install ormolu --constraint="ormolu ==$ORMOLU_VERSION")
(ormolu -v 2>/dev/null | grep -q $ORMOLU_VERSION) || (cabal install ormolu --constraint="ormolu ==$ORMOLU_VERSION")
test -e $HOME/.local/bin/yq || pip3 install yq
shell: bash

- name: Ormolu
- name: Run Ormolu
run: |
export PATH=$PATH:$HOME/.cabal/bin:$HOME/.local/bin
./layout/ormolu.sh -c
Expand All @@ -45,6 +53,6 @@ jobs:
strategy:
matrix:
cabal:
- '3.6.2.0'
- '3.10.2.1'
ghc:
- '8.8.1'
- '9.4.6'
16 changes: 13 additions & 3 deletions Graphics/Slicer/Math/Arcs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Graphics.Slicer.Math.Arcs (getFirstArc, getInsideArc, getOutsideArc, towa

import Prelude (Bool, ($), (<>), (==), (>), (<=), (&&), (||), error, mempty, otherwise, show)

import Data.Maybe (isNothing)

import Graphics.Slicer.Math.Definitions (Point2, addPoints, distance, makeLineSeg, scalePoint)

import Graphics.Slicer.Math.GeometricAlgebra (addVecPairWithErr, ulpVal)
Expand All @@ -32,6 +34,8 @@ import Graphics.Slicer.Math.Intersections (intersectionOf, isAntiCollinear, isCo

import Graphics.Slicer.Math.PGA (PLine2Err(PLine2Err), PPoint2Err, ProjectiveLine(PLine2), ProjectiveLine2, ProjectivePoint2, angleBetween2PL, distance2PP, eToPL, flipL, join2PP, normalizeL, vecOfL)

import Graphics.Slicer.Math.PGAPrimitives (canonicalizedIntersectionOf2PL)

-- | Get a Projective Line in the direction of the inside of a contour. Generates a line bisecting the angle of the intersection between a line constructed from the first two points, and another line constrected from the last two points.
getFirstArc :: Point2 -> Point2 -> Point2 -> (ProjectiveLine, PLine2Err)
getFirstArc a b c = (res, resErr)
Expand Down Expand Up @@ -60,6 +64,8 @@ getAcuteArcFromPoints p1 p2 p3

-- | Get a projective line along the angle bisector of the intersection of the two given lines, pointing in the 'acute' direction.
-- A wrapper of getAcuteAngleBisectorFromLines, dropping the returning of normalization error of the inputs.
-- Warning: assumes one PLine is toward the point of intersection, and the other is away from the point of intersection
-- FIXME: Precision Loss
getInsideArc :: (ProjectiveLine2 a, ProjectiveLine2 b) => (a, PLine2Err) -> (b, PLine2Err) -> (ProjectiveLine, PLine2Err)
getInsideArc line1 line2 = (res, resErr)
where
Expand All @@ -70,11 +76,15 @@ getInsideArc line1 line2 = (res, resErr)
{-# INLINABLE getAcuteAngleBisectorFromLines #-}
getAcuteAngleBisectorFromLines :: (ProjectiveLine2 a, ProjectiveLine2 b) => (a, PLine2Err) -> (b, PLine2Err) -> (ProjectiveLine, (PLine2Err, PLine2Err, PLine2Err))
getAcuteAngleBisectorFromLines line1@(pl1, _) line2@(pl2, _)
| isCollinear line1 line2 = error "Asked to find the acute bisector of two colinear lines!"
| isAntiCollinear line1 line2 = error "Asked to find the acute bisector of two anti-colinear lines!"
| noIntersection line1 line2 = error $ "No intersection between line " <> show line1 <> " and line " <> show line2 <> ".\n"
-- something is wrong? throw an error.
| isNothing (canonicalizedIntersectionOf2PL pl1 pl2) = makeError
| otherwise = (PLine2 addVecRes, (npline1Err, npline2Err, PLine2Err addVecErrs mempty mempty mempty mempty mempty))
where
makeError
| isCollinear line1 line2 = error $ "Asked to find the acute bisector of two colinear lines!\n" <> show pl1 <> "\n" <> show pl2 <> "\n"
| isAntiCollinear line1 line2 = error $ "Asked to find the acute bisector of two anti-colinear lines!\n" <> show pl1 <> "\n" <> show pl2 <> "\n"
| noIntersection line1 line2 = error $ "No intersection between line " <> show pl1 <> " and line " <> show pl2 <> ".\n"
| otherwise = error "no error. just seeing how you're doing."
(addVecRes, addVecErrs) = addVecPairWithErr lv1 lv2
lv1 = vecOfL $ flipL npline1
lv2 = vecOfL npline2
Expand Down
1 change: 1 addition & 0 deletions Graphics/Slicer/Math/PGA.hs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class (Show a) => Arcable a where

-- | If there is an output arc, return it, along with it's error quotent.
outAndErrOf :: (Arcable a) => a -> (ProjectiveLine, PLine2Err)
{-# INLINABLE outAndErrOf #-}
outAndErrOf a
| hasArc a = (outOf a, errOfOut a)
| otherwise = error $ "Asked for out and err of Arcable with no out!\n" <> show a <> "\n"
Expand Down
10 changes: 5 additions & 5 deletions Graphics/Slicer/Math/Skeleton/Cells.hs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ matchDirectionOfSegments firstSegOfNodeTree lastSegOfNodeTree (CellDivide (Divid
| lastSegOfNodeTree == outSeg = LastFirst
| otherwise = NoMatch

-- adjust the last output of the NodeTree so that it goes through the line it's supposed to.
-- | Adjust the last inode of the NodeTree's output so that it goes through the line it's supposed to.
redirectLastOut :: NodeTree -> (ProjectiveLine, PLine2Err) -> NodeTree
redirectLastOut inNodeTree@(NodeTree eNodes maybeINodeSet) myCrossoverLine
| isJust maybeINodeSet =
Expand Down Expand Up @@ -645,12 +645,12 @@ nodeTreeFromDivision cellDivision@(CellDivide motorcycles target) crossoverIn cr
-- Note: If we are using the motorcycle as an out, we use nothing as an out, and use the motorcycle as an in.
iNodeOfENodeDivision :: CellDivide -> (ProjectiveLine, PLine2Err) -> (ProjectiveLine, PLine2Err) -> INodeDirection -> MaybeMatch -> ENode -> INode
iNodeOfENodeDivision cellDivision crossoverIn crossoverOut iNodeDirection matchDirection eNode
-- FIXME: we don't care about match direction here? flipping the order causes fun. maybe call a sort instead of hand building this?
| iNodeDirection == TowardMotorcycle = makeINode [eNodeOut, crossoverIn, motorcycle, crossoverOut] Nothing
| iNodeDirection == TowardOut && matchDirection == LastFirst = makeINode [motorcycle, crossoverIn, eNodeOut] (Just crossoverOut)
| iNodeDirection == TowardOut && matchDirection == FirstLast = makeINode [eNodeOut, crossoverIn, motorcycle] (Just crossoverOut)
| iNodeDirection == TowardIn && matchDirection == LastFirst = makeINode [motorcycle, crossoverOut, eNodeOut] (Just crossoverIn)
| iNodeDirection == TowardIn && matchDirection == FirstLast = makeINode [eNodeOut, crossoverOut, motorcycle] (Just crossoverIn)
| iNodeDirection == TowardMotorcycle && matchDirection == LastFirst = makeINode [crossoverOut, motorcycle, crossoverIn, eNodeOut] Nothing
| iNodeDirection == TowardMotorcycle && matchDirection == FirstLast = makeINode [eNodeOut, crossoverIn, motorcycle, crossoverOut] Nothing
| matchDirection == NoMatch = error "no match!"
| otherwise = error "wtf!"
where
Expand All @@ -662,12 +662,12 @@ iNodeOfENodeDivision cellDivision crossoverIn crossoverOut iNodeDirection matchD
-- Note: If we are using the motorcycle as an out, we use nothing as an out, and use the motorcycle as an in.
iNodeOfPlainDivision :: CellDivide -> (ProjectiveLine, PLine2Err) -> (ProjectiveLine, PLine2Err) -> INodeDirection -> MaybeMatch -> INode
iNodeOfPlainDivision cellDivision crossoverIn crossoverOut iNodeDirection matchDirection
-- FIXME: we don't care about match direction here? flipping the order causes fun. maybe call a sort instead of hand building this?
| iNodeDirection == TowardMotorcycle = makeINode [crossoverIn, motorcycle, crossoverOut] Nothing
| iNodeDirection == TowardOut && matchDirection == LastFirst = makeINode [motorcycle, crossoverIn] (Just crossoverOut)
| iNodeDirection == TowardOut && matchDirection == FirstLast = makeINode [crossoverIn, motorcycle] (Just crossoverOut)
| iNodeDirection == TowardIn && matchDirection == LastFirst = makeINode [motorcycle, crossoverOut] (Just crossoverIn)
| iNodeDirection == TowardIn && matchDirection == FirstLast = makeINode [crossoverOut, motorcycle] (Just crossoverIn)
| iNodeDirection == TowardMotorcycle && matchDirection == LastFirst = makeINode [crossoverOut, motorcycle, crossoverIn] Nothing
| iNodeDirection == TowardMotorcycle && matchDirection == FirstLast = makeINode [crossoverIn, motorcycle, crossoverOut] Nothing
| matchDirection == NoMatch = error "no match!"
| otherwise = error "wtf!"
where
Expand Down
8 changes: 4 additions & 4 deletions Graphics/Slicer/Math/Skeleton/Concave.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import Graphics.Slicer.Math.Lossy (distanceBetweenPPointsWithErr)

import Graphics.Slicer.Math.PGA (Arcable(hasArc, outOf), Pointable(canPoint), ProjectiveLine, PLine2Err, cPPointAndErrOf, cPPointOf, distance2PP, flipL, join2PP, outAndErrOf, pLineIsLeft)

import Graphics.Slicer.Math.Skeleton.Definitions (ENode, ENodeSet(ENodeSet), INode(INode), INodeSet(INodeSet), NodeTree(NodeTree), concaveLines, finalINodeOf, finalOutOf, firstInOf, getFirstLineSeg, getLastLineSeg, getPairs, indexPLinesTo, insOf, isLoop, linePairs, loopOfSegSets, makeENode, makeENodes, makeInitialGeneration, makeINode, makeSide, sortedPLines, sortPLinePair)
import Graphics.Slicer.Math.Skeleton.Definitions (ENode, ENodeSet(ENodeSet), INode(INode), INodeSet(INodeSet), NodeTree(NodeTree), concaveLines, finalINodeOf, finalOutOf, firstInOf, getFirstLineSeg, getLastLineSeg, getPairs, insOf, isLoop, linePairs, loopOfSegSets, makeENode, makeENodes, makeInitialGeneration, makeINode, makeSide, sortPLinePair, sortPLinesByReferenceSafe)

import Graphics.Slicer.Math.Skeleton.NodeTrees (makeNodeTree, findENodeByOutput, findINodeByOutput)

Expand Down Expand Up @@ -524,14 +524,14 @@ sortINodesByENodes loop eNodes inSegSets inINodeSet@(INodeSet inChildGenerations
withoutPLine :: (ProjectiveLine, PLine2Err) -> [(ProjectiveLine, PLine2Err)] -> [(ProjectiveLine, PLine2Err)]
withoutPLine myPLine = filter (\a -> fst a /= fst myPLine)

-- Order the input nodes of an INode.
-- Order the inputs of an INode.
orderInsByENodes :: INode -> INode
orderInsByENodes inode@(INode _ _ _ out)
| isJust out = outRes
| otherwise = noOutRes
where
outRes = makeINode (indexPLinesTo flippedOut $ sortedPLines $ insOf inode) out
noOutRes = makeINode (indexPLinesTo firstPLine $ sortedPLines $ indexPLinesTo firstPLine $ insOf inode) Nothing
outRes = makeINode (sortPLinesByReferenceSafe flippedOut $ insOf inode) out
noOutRes = makeINode (sortPLinesByReferenceSafe firstPLine $ insOf inode) Nothing
flippedOut = case out of
(Just (outPLine, outPLineErr)) -> (flipL outPLine, outPLineErr)
Nothing -> error "tried to evaluate flippedOut when out was Nothing."
Expand Down
Loading
Loading