packages feed

brush-strokes-0.1.0.0: brush-strokes.cabal

cabal-version:  3.0
name:           brush-strokes
version:        0.1.0.0
synopsis:       Toolkit for Bézier curves and brush stroking
category:       Calligraphy, Geometry, Graphics
license:        BSD-3-Clause
homepage:       https://gitlab.com/sheaf/metabrush/-/tree/master/brush-strokes
author:         Sam Derbyshire
maintainer:     Sam Derbyshire
build-type:     Simple
description:
  A toolkit for handling quadratic and cubic Bézier curves, splines, and
  stroking.
extra-doc-files:
  changelog.md
  readme.md
  img/*.svg
  img/*.png

extra-source-files:
  cbits/lp_2d.cpp
  cbits/lp_2d.hpp
  cbits/mul.S
  cbits/rounding.c
  src/arc-length/bench/plot_bench.py

source-repository head
  type:     git
  location: https://gitlab.com/sheaf/MetaBrush

flag use-simd
  description: Use SIMD instructions to implement interval arithmetic.
  default: False
  manual:  True

flag use-fma
  description: Use fused-muliply add instructions to implement interval arithmetic.
  default: False
  manual:  True

flag asserts
  description: Enable debugging assertions.
  default: False
  manual:  True

common common

    build-depends:
      -- This package requires GHC >= 9.14 due to usage of expressions in SPECIALISE pragmas.
      -- Corresponding base version: 4.22
        base
           >= 4.22    && < 5
      , code-page
          ^>= 0.2.1
      , containers
           >= 0.6.0.1 && < 0.8
      , deepseq
           >= 1.4.4.0 && < 1.6
      , primitive
          ^>= 0.9
      , tree-view
          ^>= 0.5

    default-extensions:
        BangPatterns
        BlockArguments
        ConstraintKinds
        DataKinds
        DeriveAnyClass
        DeriveTraversable
        DeriveGeneric
        DerivingVia
        FlexibleContexts
        FlexibleInstances
        FunctionalDependencies
        GADTs
        GeneralisedNewtypeDeriving
        InstanceSigs
        LambdaCase
        LexicalNegation
        MagicHash
        MultiWayIf
        NamedFieldPuns
        NoStarIsType
        PatternSynonyms
        RankNTypes
        RecordWildCards
        RoleAnnotations
        StandaloneDeriving
        StandaloneKindSignatures
        TupleSections
        TypeAbstractions
        TypeApplications
        TypeFamilyDependencies
        TypeOperators
        UnboxedTuples
        ViewPatterns

    ghc-options:
        -fexpose-all-unfoldings
     -- -funfolding-use-threshold=1000
        -fspecialise-aggressively
        -fpolymorphic-specialisation
        -flate-dmd-anal
        -fmax-worker-args=200
        -optc-O3
        -Wall
        -Wcompat
        -fwarn-missing-local-signatures
        -fwarn-incomplete-patterns
        -fwarn-incomplete-uni-patterns
        -fwarn-missing-deriving-strategies
        -fno-warn-unticked-promoted-constructors

    if flag(use-fma)
      cpp-options:
          -DUSE_FMA
      ghc-options:
          -mfma

    if flag(use-simd)
      cpp-options:
          -DUSE_SIMD
      ghc-options:
          -mavx

    if flag(asserts)
      cpp-options:
          -DASSERTS

common extra

    build-depends:
        acts
          ^>= 0.3.1.0
      , generic-lens
           >= 2.2     && < 2.3
      , groups
          ^>= 0.5.3

library

    import:
        common, extra

    hs-source-dirs:
        src/lib

    default-language:
        Haskell2010

    exposed-modules:
        Calligraphy.Brushes
      , Math.Algebra.Dual
      , Math.Bezier.ArcLength
      , Math.Bezier.Cubic
      , Math.Bezier.Cubic.Fit
      , Math.Bezier.Quadratic
      , Math.Bezier.Spline
      , Math.Bezier.Stroke
      , Math.Bezier.Stroke.EnvelopeEquation
      , Math.Differentiable
      , Math.Epsilon
      , Math.Float.Utils
      , Math.Interval
      , Math.Linear
      , Math.Linear.Solve
      , Math.Module
      , Math.Monomial
      , Math.Orientation
      , Math.Ring
      , Math.Roots
      , Math.Root.Isolation
      , Math.Root.Isolation.Bisection
      , Math.Root.Isolation.Core
      , Math.Root.Isolation.Degree
      , Math.Root.Isolation.Narrowing
      , Math.Root.Isolation.Newton
      , Math.Root.Isolation.Newton.GaussSeidel
      , Math.Root.Isolation.Newton.LP
      , Math.Root.Isolation.Utils
      , Math.Taylor
      , Debug.Utils

    other-modules:
        Math.Algebra.Dual.Internal
      , Math.Interval.Internal
      , Math.Interval.Internal.FMA
      , Math.Linear.Internal
      , Math.Module.Internal
      , TH.Utils

    if flag(use-simd)
      other-modules:
        Math.Interval.Internal.SIMD
      build-depends:
          simd-interval
        , ghc-prim
            >= 0.13 && < 1.0

    if !flag(use-fma) && !flag(use-simd)
      other-modules:
        Math.Interval.Internal.RoundedHW

    build-depends:
        template-haskell
           >= 2.18       && < 3
      , bifunctors
           >= 5.5.4      && < 5.7
      , directory
           >= 1.3.7.1    && < 1.4
      , eigen
          ^>= 3.3.7.0
      , filepath
           >= 1.4        && < 1.6
      , fp-ieee
          ^>= 0.1.0.4
      , groups-generic
          ^>= 0.3.1.0
      , parallel
           >= 3.2.2.0 && < 3.4
      , rounded-hw
          ^>= 0.4
      , time
           >= 1.12.2 && < 1.15
      , transformers
           >= 0.5.6.2 && < 0.7

    include-dirs:
      cbits
    c-sources:
      -- C code for: setting the rounding mode
      cbits/rounding.c
    cxx-sources:
      -- Walter's C++ code for 2D linear systems of interval equations
      cbits/lp_2d.cpp
    cxx-options:
      -std=c++20
      -mavx2
      -mfma
      -frounding-math
      -ffp-contract=off
      -fno-math-errno
      -fno-signed-zeros
      -fno-trapping-math
      -Wno-unused-result
      -Wno-sign-compare
      -Wno-switch
      -march=native
      -mtune=native
      -DNDEBUG
    build-depends:
      system-cxx-std-lib == 1.0

-- Separate library to implement interval arithmetic using SIMD,
-- to work around TH linking bugs:
--
--  - https://gitlab.haskell.org/ghc/ghc/-/issues/25240
--  - https://github.com/haskell/cabal/issues/5623
library simd-interval

    import: common

    default-language:
        Haskell2010

    hs-source-dirs:
        src/simd-interval

    exposed-modules:
        Math.Interval.Internal.SIMD.Internal

    include-dirs:
        cbits
    asm-sources:
        -- X86 assembly for interval multiplication using SIMD instructions
        cbits/mul.S

    build-depends:
        ghc-prim
           >= 0.13 && < 1
      , rounded-hw
          ^>= 0.4

--executable convert-metafont
--
--    import:
--        common
--
--    hs-source-dirs:
--        src/metafont
--
--    default-language:
--        Haskell2010
--
--    main-is:
--        Main.hs
--
--    other-modules:
--        Calligraphy.MetaFont.Convert
--
--    build-depends:
--        diagrams-contrib,
--        diagrams-lib,
--        linear,
--        parsec

--executable inspect
--
--    import:
--        common, extra
--
--    hs-source-dirs:
--        src/cusps/inspect
--
--    default-language:
--        Haskell2010
--
--    main-is:
--        Main.hs
--
--    other-modules:
--        Math.Interval.Abstract
--
--    build-depends:
--        brush-strokes
--      , data-reify
--          ^>= 0.6.3

test-suite tests

    import:
      common

    type:
      exitcode-stdio-1.0

    hs-source-dirs:
      src/test

    default-language:
      Haskell2010

    main-is:
      Main.hs

    build-depends:
        brush-strokes
      , falsify
          ^>= 0.2
      , hspray
          ^>= 0.1.3
      , tasty
          ^>= 1.5
      , unordered-containers
          >= 0.2.15 && < 0.3

test-suite test-arc-length

    import:
      common

    type:
      exitcode-stdio-1.0

    hs-source-dirs:
      src/arc-length/test

    default-language:
      Haskell2010

    main-is:
      TestArcLength.hs

    ghc-options:
      -threaded -rtsopts

    build-depends:
        brush-strokes
      , falsify
          ^>= 0.2
      , optparse-applicative
          >= 0.17 && < 0.19
      , parallel
          >= 3.2.2.0 && < 3.4
      , tasty
          ^>= 1.5

benchmark bench-arc-length

  import:
    common

  hs-source-dirs:
    src/arc-length/bench

  main-is:
    BenchArcLength.hs

  build-depends:
    brush-strokes

  type:
    exitcode-stdio-1.0

  default-language:
    Haskell2010

  ghc-options:
    -O2
    -threaded
    -rtsopts

benchmark cusps

  import:
    common

  hs-source-dirs:
    src/cusps/bench

  main-is:
    Main.hs

  other-modules:
    Bench.Types
    Bench.Cases

  build-depends:
      brush-strokes

  type:
    exitcode-stdio-1.0

  default-language:
    Haskell2010

  ghc-options:
    -threaded
    -rtsopts