Skip to content

Commit

Permalink
- Create segment with optional second point omitted (issue #84)
Browse files Browse the repository at this point in the history
- Release patch v1.2.23
  • Loading branch information
alexbol99 committed May 16, 2021
1 parent bf7a901 commit d286ed5
Show file tree
Hide file tree
Showing 58 changed files with 4,126 additions and 3,923 deletions.
114 changes: 82 additions & 32 deletions .idea/workspace.xml

Large diffs are not rendered by default.

22 changes: 20 additions & 2 deletions dist/main.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4503,6 +4503,12 @@ class Segment {
return;
}

// second point omitted issue #84
if (args.length === 1 && args[0] instanceof Flatten.Point) {
this.ps = args[0].clone();
return;
}

if (args.length === 2 && args[0] instanceof Flatten.Point && args[1] instanceof Flatten.Point) {
this.ps = args[0].clone();
this.pe = args[1].clone();
Expand Down Expand Up @@ -5796,10 +5802,22 @@ class Arc {
return this.transform(m);
}

/**
* Return new arc scaled by scaleX, scaleY.
* @param {number} scaleX - scale value by X
* @param {number} scaleY - scale value by Y
* @returns {Arc}
*/
scale(scaleX = 1, scaleY = 1) {
let m = new Flatten.Matrix();
m = m.scale(scaleX, scaleY);
return this.transform(m);
}

/**
* Return new arc transformed using affine transformation matrix <br/>
* Note 1. Non-equal scaling by x and y (matrix[0] != matrix[3]) produce illegal result because
* it should create elliptic arc but library does not support ellipses
* Note 1. Non-equal scaling by x and y (abs(matrix[0]) != abs(matrix[3])) produce illegal result because
* it should create elliptic arc but this package does not support ellipses
* Note 2. Mirror transformation (matrix[0] * matrix[3] < 0) change direction of the arc to the opposite
* TODO: support non-equal scaling arc to ellipse or throw exception ?
* @param {Matrix} matrix - affine transformation matrix
Expand Down
22 changes: 20 additions & 2 deletions dist/main.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4499,6 +4499,12 @@ class Segment {
return;
}

// second point omitted issue #84
if (args.length === 1 && args[0] instanceof Flatten.Point) {
this.ps = args[0].clone();
return;
}

if (args.length === 2 && args[0] instanceof Flatten.Point && args[1] instanceof Flatten.Point) {
this.ps = args[0].clone();
this.pe = args[1].clone();
Expand Down Expand Up @@ -5792,10 +5798,22 @@ class Arc {
return this.transform(m);
}

/**
* Return new arc scaled by scaleX, scaleY.
* @param {number} scaleX - scale value by X
* @param {number} scaleY - scale value by Y
* @returns {Arc}
*/
scale(scaleX = 1, scaleY = 1) {
let m = new Flatten.Matrix();
m = m.scale(scaleX, scaleY);
return this.transform(m);
}

/**
* Return new arc transformed using affine transformation matrix <br/>
* Note 1. Non-equal scaling by x and y (matrix[0] != matrix[3]) produce illegal result because
* it should create elliptic arc but library does not support ellipses
* Note 1. Non-equal scaling by x and y (abs(matrix[0]) != abs(matrix[3])) produce illegal result because
* it should create elliptic arc but this package does not support ellipses
* Note 2. Mirror transformation (matrix[0] * matrix[3] < 0) change direction of the arc to the opposite
* TODO: support non-equal scaling arc to ellipse or throw exception ?
* @param {Matrix} matrix - affine transformation matrix
Expand Down
22 changes: 20 additions & 2 deletions dist/main.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4505,6 +4505,12 @@
return;
}

// second point omitted issue #84
if (args.length === 1 && args[0] instanceof Flatten.Point) {
this.ps = args[0].clone();
return;
}

if (args.length === 2 && args[0] instanceof Flatten.Point && args[1] instanceof Flatten.Point) {
this.ps = args[0].clone();
this.pe = args[1].clone();
Expand Down Expand Up @@ -5798,10 +5804,22 @@
return this.transform(m);
}

/**
* Return new arc scaled by scaleX, scaleY.
* @param {number} scaleX - scale value by X
* @param {number} scaleY - scale value by Y
* @returns {Arc}
*/
scale(scaleX = 1, scaleY = 1) {
let m = new Flatten.Matrix();
m = m.scale(scaleX, scaleY);
return this.transform(m);
}

/**
* Return new arc transformed using affine transformation matrix <br/>
* Note 1. Non-equal scaling by x and y (matrix[0] != matrix[3]) produce illegal result because
* it should create elliptic arc but library does not support ellipses
* Note 1. Non-equal scaling by x and y (abs(matrix[0]) != abs(matrix[3])) produce illegal result because
* it should create elliptic arc but this package does not support ellipses
* Note 2. Mirror transformation (matrix[0] * matrix[3] < 0) change direction of the arc to the opposite
* TODO: support non-equal scaling arc to ellipse or throw exception ?
* @param {Matrix} matrix - affine transformation matrix
Expand Down
1,009 changes: 598 additions & 411 deletions docs/Arc.html

Large diffs are not rendered by default.

312 changes: 155 additions & 157 deletions docs/Box.html

Large diffs are not rendered by default.

285 changes: 141 additions & 144 deletions docs/Circle.html

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions docs/CircularLinkedList.html

Large diffs are not rendered by default.

144 changes: 70 additions & 74 deletions docs/DE9IM.html

Large diffs are not rendered by default.

299 changes: 148 additions & 151 deletions docs/Edge.html

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions docs/Errors.html

Large diffs are not rendered by default.

586 changes: 278 additions & 308 deletions docs/Face.html

Large diffs are not rendered by default.

402 changes: 197 additions & 205 deletions docs/Line.html

Large diffs are not rendered by default.

278 changes: 138 additions & 140 deletions docs/LinkedList.html

Large diffs are not rendered by default.

201 changes: 92 additions & 109 deletions docs/Matrix.html

Large diffs are not rendered by default.

488 changes: 244 additions & 244 deletions docs/Multiline.html

Large diffs are not rendered by default.

204 changes: 98 additions & 106 deletions docs/PlanarSet.html

Large diffs are not rendered by default.

508 changes: 246 additions & 262 deletions docs/Point.html

Large diffs are not rendered by default.

967 changes: 467 additions & 500 deletions docs/Polygon.html

Large diffs are not rendered by default.

99 changes: 47 additions & 52 deletions docs/Ray.html

Large diffs are not rendered by default.

615 changes: 304 additions & 311 deletions docs/Segment.html

Large diffs are not rendered by default.

596 changes: 293 additions & 303 deletions docs/Vector.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/algorithms_boolean_op.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/algorithms_distance.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/algorithms_inversion.js.html

Large diffs are not rendered by default.

32 changes: 22 additions & 10 deletions docs/algorithms_ray_shooting.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/algorithms_relation.js.html

Large diffs are not rendered by default.

26 changes: 22 additions & 4 deletions docs/classes_arc.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_box.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_circle.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_edge.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_face.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_line.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_matrix.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_multiline.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_point.js.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes_polygon.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_ray.js.html

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions docs/classes_segment.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes_vector.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/data_structures_circular_linked_list.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/data_structures_de9im.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/data_structures_linked_list.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/data_structures_planar_set.js.html

Large diffs are not rendered by default.

510 changes: 249 additions & 261 deletions docs/global.html

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions docs/index.html

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions docs/module-BooleanOperations.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/module-RayShoot.html

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions docs/module-Relation.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/utils_constants.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/utils_errors.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/utils_utils.js.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ declare namespace Flatten {
translate(vec: Vector): Arc;
translate(x:number, y:number): Arc;
rotate(angle: number, center: Point): Arc;
scale(scaleX: number, scaleY: number) : Arc;
transform(matrix?: Matrix): Arc;
sortPoints(pts: Array<Point>): Array<Point>;
toJSON() : Object;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flatten-js/core",
"version": "1.2.22",
"version": "1.2.23",
"description": "Javascript library for 2d geometry",
"main": "dist/main.cjs.js",
"umd:main": "dist/main.umd.js",
Expand Down
16 changes: 14 additions & 2 deletions src/classes/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,22 @@ export class Arc {
return this.transform(m);
}

/**
* Return new arc scaled by scaleX, scaleY.
* @param {number} scaleX - scale value by X
* @param {number} scaleY - scale value by Y
* @returns {Arc}
*/
scale(scaleX = 1, scaleY = 1) {
let m = new Flatten.Matrix();
m = m.scale(scaleX, scaleY);
return this.transform(m);
}

/**
* Return new arc transformed using affine transformation matrix <br/>
* Note 1. Non-equal scaling by x and y (matrix[0] != matrix[3]) produce illegal result because
* it should create elliptic arc but library does not support ellipses
* Note 1. Non-equal scaling by x and y (abs(matrix[0]) != abs(matrix[3])) produce illegal result because
* it should create elliptic arc but this package does not support ellipses
* Note 2. Mirror transformation (matrix[0] * matrix[3] < 0) change direction of the arc to the opposite
* TODO: support non-equal scaling arc to ellipse or throw exception ?
* @param {Matrix} matrix - affine transformation matrix
Expand Down
6 changes: 6 additions & 0 deletions src/classes/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export class Segment {
return;
}

// second point omitted issue #84
if (args.length === 1 && args[0] instanceof Flatten.Point) {
this.ps = args[0].clone();
return;
}

if (args.length === 2 && args[0] instanceof Flatten.Point && args[1] instanceof Flatten.Point) {
this.ps = args[0].clone();
this.pe = args[1].clone();
Expand Down
14 changes: 13 additions & 1 deletion test/classes/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect } from 'chai';
import Flatten from '../../index';

import {Point, Vector, Circle, Line, Segment, Arc, Box, Polygon, Edge, Face, Ray} from '../../index';
import {point, vector, circle, line, segment, arc, ray} from '../../index';
import {point, vector, circle, line, segment, arc, matrix, ray} from '../../index';

describe('#Flatten.Arc', function() {
it('May create new instance of Arc', function () {
Expand Down Expand Up @@ -319,6 +319,18 @@ describe('#Flatten.Arc', function() {
expect(reversed_arc.counterClockwise).to.equal(Flatten.CW);
expect(Flatten.Utils.EQ(arc.sweep,reversed_arc.sweep)).to.be.true;
})
it('Can mirror arc by Y axis using transformation matrix', () => {
let a1 = arc(point(0, 10), 20, -Math.PI / 4, Math.PI / 4, true);
let m = matrix().scale(-1, 1);
let a2 = a1.transform(m);
expect(a2.start.x).to.be.closeTo(-a1.start.x, Flatten.DP_TOL);
expect(a2.start.y).to.be.closeTo(a1.start.y, Flatten.DP_TOL);
expect(a2.end.x).to.be.closeTo(-a1.end.x, Flatten.DP_TOL);
expect(a2.end.y).to.be.closeTo(a1.end.y, Flatten.DP_TOL);
expect(a2.center.x).to.be.closeTo(-a1.center.x, Flatten.DP_TOL);
expect(a2.center.y).to.be.closeTo(a1.center.y, Flatten.DP_TOL);
expect(a2.counterClockwise).to.be.equal(!a1.counterClockwise);
});
it('Method svg() without parameters creates svg string with default attributes', function() {
let arc = new Arc(point(), 5, Math.PI/4, 3*Math.PI/4, Flatten.CCW);
let svg = arc.svg();
Expand Down
6 changes: 6 additions & 0 deletions test/classes/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe('#Flatten.Segment', function() {
expect(segment.start).to.deep.equal({x:1, y:1});
expect(segment.end).to.deep.equal({x:2, y:3});
});
it('May construct segment when second point is omitted', function () {
let ps = new Point(10,10);
let segment = new Segment(ps);
expect(segment.start).to.deep.equal({x:10, y:10});
expect(segment.end).to.deep.equal({x:0, y:0});
});
it('May constructor by array [4] ', function () {
let ps = new Point(1,1);
let pe = new Point(2,3);
Expand Down

0 comments on commit d286ed5

Please sign in to comment.