Skip to content

tommyettinger/crux

Repository files navigation

crux

tl;dr

If you already know you need this, this is the Gradle dependency:

api "com.github.tommyettinger:crux:0.1.3"

Shared interfaces for point types

This library provides some small interfaces meant to be shared by (subclasses of) various incompatible types such as libGDX's GridPoint2, Vector2, GridPoint3, Vector3, and Vector4, as well as SquidSquad's Coord, and potentially AWT's Point. The code here was pulled from gand, and now gand depends on this.

The interfaces provided here can be used for mutable or immutable points, using int or float components. Anything they provide in the form of default methods can (and is sometimes meant to) be overridden by an implementing class. Code can often be written to accept a more general type, such as Point2, instead of requiring a specific class, such as Vector2 or GridPoint2. You can get a component as a float with the x() method or int with the xi() method, with more of these for higher dimensions (y for 2D, z for 3D, etc.). There's also overloads of these that take float (for x()) or int (for xi()) parameters, to set that component. Setting edits the point in place if it is mutable, but if the point is immutable, it either creates a copy or sometimes obtains an existing immutable point from some type of pool. You can use set() to set with floats, or seti() to set with ints.

Sometimes, though not often, you can even go as general as the superinterface of all point types here, PointN. Using PointN is a little more limited, since it doesn't even know what components a particular point will have, but an example of types using it (from gand) would be:

public class PathSmoother<V extends PointN<V>> {
    //...
}

There are also PointNFloat and PointNInt interfaces for point types that specifically store their components as ints or floats. These don't add much functionality to PointN, but do provide get() and setAt() methods that return or take the appropriate primitive type. These methods allow looking up a coordinate by its index, rather than its name.

You may want the more specialized library gdcrux, which extends existing types from libGDX when possible, but also implements crux interfaces. You might also be after a different specialization using digital for core methods, which can be found in SquidSquad, specifically its SquidGrid submodule. If you stick to methods defined in crux, these two specializations can interoperate.

Installation

The main way should be via Maven Central, where most libraries in the JVM ecosystem tend to be downloaded from. The dependency, which goes in the dependencies block of your core/build.gradle project if it is a typical libGDX project, is:

api "com.github.tommyettinger:crux:$cruxVersion"

where cruxVersion is often defined in gradle.properties with

cruxVersion=0.1.3

You could instead replace any occurrences of $cruxVersion with 0.1.3 .

To depend on this on GWT, in addition to the earlier dependency in your core module (assuming a libGDX project), you would have this dependency in your html module:

implementation "com.github.tommyettinger:crux:$cruxVersion:sources"

And this line in your GdxDefinition.gwt.xml file, before any inherits that might use crux:

<inherits name="com.github.tommyettinger.crux" />

You can also use JitPack instead of Maven Central. You probably want the latest commit, not the -SNAPSHOT version. If you target GWT, you still need to append :sources after the version of the JitPack dependency and use that in the html module, and use the same inherits line.

License

CC0 version 1.0.

Name

The name was picked because the crux is a crucial point between (inter-, as in interface) two parts. This is meant to bridge the libGDX-based position code used by some of my libraries, like gand, with the independent position code used by SquidSquad's SquidGrid module.

About

Shared interfaces for point types.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages