PHPackages                             anton-panfilov/1d-integer-geometry - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. anton-panfilov/1d-integer-geometry

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

anton-panfilov/1d-integer-geometry
==================================

1.4.0(1y ago)01121MITPHPPHP ^8.1

Since Mar 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/anton-panfilov/1d-integer-geometry)[ Packagist](https://packagist.org/packages/anton-panfilov/1d-integer-geometry)[ Docs](https://github.com/anton-panfilov/1d-integer-geometry)[ RSS](/packages/anton-panfilov-1d-integer-geometry/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (8)Used By (1)

1D Integer Geometry Library
===========================

[](#1d-integer-geometry-library)

The 1D Integer Geometry Library, `anton-panfilov/1d-integer-geometry`, provides a comprehensive set of tools for performing geometric operations on 1-dimensional integer shapes. This includes functionality for determining intersections, exclusions, and sorting of geometric shapes such as points, segments, and vectors. The library is designed to be intuitive and easy to use, catering to a wide range of applications in computational geometry, computer graphics, and related fields.

Key Features
------------

[](#key-features)

- **Exclusion**: Compute the geometric difference between shapes, effectively excluding one shape from another.
- **Intersection**: Determine whether two shapes intersect and obtaining the shape obtained at the intersection.
- **Shapes**: Create and manipulate basic 1D geometric shapes, including points, segments, and vectors.

Installation
------------

[](#installation)

The library can be installed using Composer, a dependency manager for PHP. To add the 1D Integer Geometry Library to your project, run the following command in your project's root directory:

```
composer require anton-panfilov/1d-integer-geometry
```

Usage
-----

[](#usage)

### Excluding shapes

[](#excluding-shapes)

```
$result = Exclude::exclude(
    Shape::s(-9, 5),
    Shape::s(-10, 10)
);
```

### Get the shape obtained by intersection

[](#get-the-shape-obtained-by-intersection)

```
$result = Intersects::getIntersectsShape(
    Shape::s(0, 10),
    Shape::s(5, 15)
);
// Shape::s(5, 10)

$result = Intersects::getIntersectsShape(
    Shape::s(0, 10),
    Shape::s(10, 15)
);
// Shape::p(10)
```

### Check if the figures intersect

[](#check-if-the-figures-intersect)

```
$result = Intersects::intersectsShapes(
    Shape::p(10),
    Shape::s(5, 34)
);
// true

$result = Intersects::intersectsShapes(
    Shape::vp(10),
    Shape::s(5, 7)
);
// false
```

### Creating Shapes

[](#creating-shapes)

```
$point = Shape::p(10);
$segment = Shape::s(-9, 5);

// Convert Point or Segment to Segment (with point1
