Giter VIP home page Giter VIP logo

gg's Introduction

Gg — Basic types and tools for computer graphics in OCaml

%%VERSION%%

Gg provides basic types for computer graphics. It defines types and functions for floats, vectors, points, sizes, matrices, quaternions, axis-aligned boxes, colors, color spaces, and raster data.

On top of this the Gg_kit library provides a few more tools and algorithms for working with geometry and graphics.

Gg and Gg_kit have no dependencies. Gg is distributed under the ISC license. Gg_kit is distributed under the ISC license and some color schemes are distributed under the Apache 2.0 and CC0 licenses.

Home page: http://erratique.ch/software/gg

Installation

Gg can be installed with opam:

opam install gg

If you don't use opam consult the opam file for build instructions and a complete specification of the dependencies.

Documentation

The documentation can be consulted online or via odig doc gg.

Questions are welcome but better asked on the OCaml forum than on the issue tracker.

A few basic sample programs can be found in the test directory.

gg's People

Contributors

chris00 avatar dbuenzli avatar edwintorok avatar rand00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gg's Issues

Are you interested in high level operations for quaternions?

Dear Daniel,

There is an interesting method for almost uniform sampling of SO(3) (i.e. the space
of all possible rotations).
This can be useful in some numerical simulations.

cf. "Super-Fibonacci Spirals: Fast, Low-Discrepancy Sampling of SO(3)"
by Marc Alexa

Regards,
F.

Box.add_pt

On thing that would be useful — to me at least — for boxes is to be able to "add" a point, i.e., to enlarge a box to make sure it contains an additional point. Signature (with maybe a better name):

val add_pt : box -> p -> box

(can be implemented for all box types). Doing it for a collection of points would also be interesting:

val bounding : p list -> box

Box improvements

Transforms that map boxes to boxes e.g. for Box2. Need to find a name and location though.

let map_box ~src ~dst =
  M3.mul (M3.move2 (Box2.o dst)) @@
  M3.mul (M3.scale2 (V2.div (Box2.size dst) (Box2.size src))) @@
  M3.move2 (V2.neg (Box2.o src))

Out of gammut colors on Color.{to,of}_lch_uv round trips

utop # Color.red |> Color.to_lch_uv |> Color.of_lch_uv;;
- : v4 = (1 -9.96856e-09 -1.70861e-08 1) 

Colors with negative components are not rendered as far as I tested.

It seems to be quite easy to get invalid colors, here is another example with a larger negative component.

utop # V4.v 80. 120. 2. 1. |> Color.of_lch_uv;;
- : v4 = (0.198288 0.741156 -0.0747728 1)

I even got some components bigger than 1. on some examples.

LCH color space

The documentation

h represents hue in degrees in the range [0.] to [2pi]

should be fixed: either it is in degrees and then in the range 0..360, or it is in radians.

Have a function normalizing a vector but returning zero on zero

Hi,

Both of the times I used Gg, I found myself wanting {V2,V3}.unit to return {V2,V3}.zero on {V2,V3}.zero.
It's kind of a special case, but I think it is common in practice, so it would be useful to have a function ({V2,V3}.normalize ?) implementing this behavior.

What's your opinion about this?

-- Armael

`Gg.Box2.mem` does not satisfy its specification

My understanding of the specification should ensure that the following program always returns true, but if it is executed, we will see that most of the time it returns false. I expect this is related to floating point arithmetic.

Seq.ints 0 |> Seq.take 100 |> List.of_seq
    |> List.for_all (fun _ ->
           let x = Gg.P2.v (Random.float 10.) (Random.float 10.) in
           let y = Gg.P2.v (Random.float 10.) (Random.float 10.) in
           let box = Gg.Box2.of_pts x y in
           Gg.Box2.mem x box && Gg.Box2.mem y box )

For a concrete example, one can use the following snippet:

let x =
  Gg.P2.v 1.227721875450257238426843287016
                 1.217602532403128101634592894698
in
let y =
    Gg.P2.v 3.330991420098936561799973787856
                   0.148412743612841291351855943503
in
let box = Gg.Box2.of_pts x y in
Gg.Box2.mem x box && Gg.Box2.mem y box

Not sure how to fix that. Should we provide an optional eps argument to the Gg.Box2.mem function?

Box2 with negative sizes

I have a usecase where I use Box2.t to represent arrows pointing in 2d-space. This means that they can have sizes that are negative in the x or y dimension. This has worked well until I found that maxx and friends don't support this.

The documentation of Box2 doesn't state that negative sizes are not allowed, and I like my current usecase. Should all Box2 functions be made to support negative sizes?

This would mean that BoxN and SizeN modules would also need to support negative sizes

META: gg.top should depend on gg

Subject says it. I don't think there is a reason to require gg.top but not gg, and adding a dependency means one #require less.

Box2.subset seems wrong

# let big = Box2.v V2.zero (Size2.v 10. 10.);;
# let small = Box2.v (V2.v 100. 100.) (Size2.v 1. 1.);;
# Box2.subset small big;;
- : bool = true

(same issue with Box3.subset)

Faster Float functions

Are you sure that the compiler does use the signature to specialize functions such as Float.is_nan? I think adding a type annotation would be better/clearer, e.g.

let is_nan x = (x: float) <> x

[Question] Size ≠ extent

The comment at the beginning of the Sizes section saying "An n-dimensional {e size} [s] represents extents in n-dimensional space" seems misleading to me. Indeed, at least in Cairo's parlance, an extent is equivalent to a bounding box. Or is it ambiguous and extent should be explained rather than being used as an explanation! 😊

Maybe native English speakers could tell whether "extent" usually refers more to the "distance over which it extends" or also the location of the object?
/cc @avsm @dsheets @talex5 @yallop @amirmc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.