Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@folkertdev
folkertdev / Main.elm
Created August 19, 2018 16:35
Sutherland-Hodgman polygon clipping
module Main exposing (..)
import Point2d exposing (Point2d)
import Svg exposing (Svg)
import Svg.Attributes exposing (fill, strokeWidth, stroke, width, height, viewBox, cx, cy, r, strokeOpacity)
import Html exposing (text)
import Geometry.Svg
import Polygon2d
import Html.Attributes exposing (style, defaultValue)
import BoundingBox2d
@folkertdev
folkertdev / RTree.elm
Created August 8, 2018 21:01
A more optimized/less readable RTree
module RTree exposing (..)
import BoundingBox2d exposing (BoundingBox2d)
import Point2d exposing (Point2d)
import List.Extra as List
-- bounding boxes can go to infintiy
-- minNode <= maxNode // 2
-- the root node has at least 2 children, unless it is a leaf
@folkertdev
folkertdev / RTree.elm
Created August 4, 2018 21:01
rtree in elm
module RTree exposing (..)
import BoundingBox2d exposing (BoundingBox2d)
import Point2d exposing (Point2d)
import List.Extra as List
-- bounding boxes can go to infintiy
-- minNode <= maxNode // 2
-- the root node has at least 2 children, unless it is a leaf
@folkertdev
folkertdev / FixedRadius.elm
Created June 8, 2018 14:56
Fixed radius near neighbours in elm
module FixedRadius exposing (Buckets, Point, fromList, search, searchReflexive, map)
{-| A module for fixed-radious near neighbours
@docs Point, Buckets, fromList, search, searchReflexive, map
-}
import Dict exposing (Dict)
@folkertdev
folkertdev / Smallest.hs
Last active February 19, 2018 19:42
n-th smallest number in a matrix where the row and column are monotonically increasing
{-# LANGUAGE ScopedTypeVariables #-}
module Smallest where
type List a = [ a]
merge :: Ord a => List a -> List a -> List a
merge as bs =
case (as, bs) of
([], _) -> bs
(_, []) -> as
@folkertdev
folkertdev / Split.elm
Created September 6, 2017 18:57
a polymorphic splitting function that splits until the increase of accuracy of splitting again is below some threshold
module Geometry.Split exposing (..)
type alias Config a =
{ length : a -> Float
, split : Float -> a -> ( a, a )
, percentageError : Float
}
@folkertdev
folkertdev / ExtentWith.elm
Last active August 16, 2017 15:26
extentWith
extentWith : (a -> a -> Order) -> List a -> Maybe ( a, a )
extentWith toOrder list =
let
max a b =
case toOrder a b of
GT ->
a
_ ->
b
@folkertdev
folkertdev / SubPath.elm
Created August 5, 2017 15:11
A proposal to allow easier composition of SubPaths
module SubPath exposing (..)
import Path exposing (DrawTo(..), MoveTo(..), lineTo, closePath, moveTo)
import Deque exposing (Deque)
import Vector2 as Vec2 exposing (Vec2)
import List.Extra as List
type SubPath
= SubPath { moveto : MoveTo, drawtos : Deque DrawTo }
@folkertdev
folkertdev / PathParser.elm
Last active June 12, 2017 21:39
Elm SVG/Graphics notes
module Svg.PathParser exposing (..)
{-| Module for parsing SVG path syntax, using [elm-tools/parser](http://package.elm-lang.org/packages/elm-tools/parser/latest)
The data structure and parser is modeled according to [this W3C grammar](https://www.w3.org/TR/SVG/paths.html#PathDataBNF)
### data
The building blocks are
@folkertdev
folkertdev / MatrixProduct.hs
Last active March 17, 2017 21:50
Use a flat array to calculate the optimal order for a series of matrix multiplications with STUArray and the ST Monad
import Control.Monad.ST
import Data.Array.IArray as Array
import Data.STRef
import Data.Array.ST as Array.ST
import Data.Array.MArray as MArray
import Data.Array.Unboxed
solve :: Int -> List Int -> Word32
solve _ [] = 0