@eturnity/eturnity_maths 7.2.3-qa-7.6.0 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_maths",
3
- "version": "7.2.3-qa-7.6.0",
3
+ "version": "7.4.0",
4
4
  "author": "Eturnity Team",
5
5
  "main": "src/index.js",
6
6
  "private": false,
package/src/geometry.js CHANGED
@@ -98,7 +98,7 @@ export function getParallelLinePassingByPoint(A, B, C) {
98
98
  console.error("A == B Can't make a parallel line")
99
99
  return null
100
100
  }
101
- const D = new Point(C.x + B.x - A.x, C.y + B.y - A.y, C.z + B.z - A.z)
101
+ const D = new Point(C.x + B.x - A.x, C.y + B.y - A.y)
102
102
  return new Line(C, D, '')
103
103
  }
104
104
 
@@ -110,15 +110,10 @@ export function getDataAboutTwo3DLines(A,u,B,v){
110
110
  [u.z,v.z,w.z]
111
111
  ]
112
112
  let mInv=inverse3x3matrix(m)
113
- if(!mInv){
114
- return null
115
- }
116
113
  let AB=substractVector(B,A)
117
114
  let [t1,t2,t3] = multiplyMatrices(mInv,[[AB.x],[AB.y],[AB.z]])
118
- //M point on Au
119
115
  let M=addVector(A,multiplyVector(t1,u))
120
- //N point on Bv
121
- let N=addVector(B,multiplyVector(-t2,v))
116
+ let N=addVector(B,multiplyVector(t2,v))
122
117
  let distance=get3DDistanceBetweenPoints(M,N)
123
118
  return {m,mInv,M,N,A,B,u,v,w,distance,t1,t2,t3}
124
119
 
@@ -145,15 +140,11 @@ export function get3DDistanceBetweenPoints(firstPoint, secondPoint) {
145
140
  )
146
141
  return distance
147
142
  }
148
-
149
- export function getDegreeVectors(u,v){
150
- return getDegree(u,{x:0,y:0,z:0},v)
151
- }
152
-
143
+
153
144
  export function getDegree(H, I, J) {
154
- const a = get3DDistanceBetweenPoints(H, I)
155
- const b = get3DDistanceBetweenPoints(I, J)
156
- const c = get3DDistanceBetweenPoints(H, J)
145
+ const a = getDistanceBetweenPoints(H, I)
146
+ const b = getDistanceBetweenPoints(I, J)
147
+ const c = getDistanceBetweenPoints(H, J)
157
148
 
158
149
  let angle = (Math.acos((a * a + b * b - c * c) / (2 * a * b)) * 180) / Math.PI
159
150
 
@@ -557,56 +548,27 @@ export function get3DDistanceBetweenPoints(firstPoint, secondPoint) {
557
548
  return null
558
549
  }
559
550
  let P = {}
560
- if(M.z == undefined || A.z== undefined || B.z== undefined){
561
- const AM = {
562
- x: M.x - A.x,
563
- y: M.y - A.y
564
- }
565
- const AB = {
566
- x: B.x - A.x,
567
- y: B.y - A.y
568
- }
569
-
570
- const dot = AM.x * AB.x + AM.y * AB.y
571
- const distanceAB = getDistanceBetweenPoints(A, B)
572
- let param = -1
573
- if (distanceAB == 0) {
574
- //A et B sont confondu
575
- console.error("A and B don't make a line : A==B")
576
- P = M
577
- } else {
578
- // in case of 0 length line
579
- const distanceAP = dot / distanceAB
580
- P.x = A.x + (distanceAP * AB.x) / distanceAB
581
- P.y = A.y + (distanceAP * AB.y) / distanceAB
582
- }
583
- }else{
584
- //make 3D projection on line
585
- const AM = {
586
- x: M.x - A.x,
587
- y: M.y - A.y,
588
- z: M.z - A.z,
589
- }
590
- const AB = {
591
- x: B.x - A.x,
592
- y: B.y - A.y,
593
- z: B.z - A.z
594
- }
595
-
596
- const dot = AM.x * AB.x + AM.y * AB.y + AM.z * AB.z
597
- const distanceAB = get3DDistanceBetweenPoints(A, B)
598
- let param = -1
599
- if (distanceAB == 0) {
600
- //A et B sont confondu
601
- console.error("A and B don't make a line : A==B")
602
- P = M
603
- } else {
604
- // in case of 0 length line
605
- const distanceAP = dot / distanceAB
606
- P.x = A.x + (distanceAP * AB.x) / distanceAB
607
- P.y = A.y + (distanceAP * AB.y) / distanceAB
608
- P.z = A.z + (distanceAP * AB.z) / distanceAB
609
- }
551
+ const AM = {
552
+ x: M.x - A.x,
553
+ y: M.y - A.y
554
+ }
555
+ const AB = {
556
+ x: B.x - A.x,
557
+ y: B.y - A.y
558
+ }
559
+
560
+ const dot = AM.x * AB.x + AM.y * AB.y
561
+ const distanceAB = getDistanceBetweenPoints(A, B)
562
+ let param = -1
563
+ if (distanceAB == 0) {
564
+ //A et B sont confondu
565
+ console.error("A and B don't make a line : A==B")
566
+ P = M
567
+ } else {
568
+ // in case of 0 length line
569
+ const distanceAP = dot / distanceAB
570
+ P.x = A.x + (distanceAP * AB.x) / distanceAB
571
+ P.y = A.y + (distanceAP * AB.y) / distanceAB
610
572
  }
611
573
  //projection of the point to the line
612
574
  return P
@@ -1,13 +1,12 @@
1
1
 
2
2
  import {
3
+ getDistanceBetweenPoints,
3
4
  translate2D,
4
5
  verticalProjectionOnPlane,
5
- get3DDistanceBetweenPoints,
6
- getDistanceBetweenPoints,
6
+ get3DDistanceBetweenPoints
7
7
  } from '../geometry'
8
8
  import { v4 as uuidv4 } from 'uuid'
9
9
  import {Point} from './Point'
10
- import { addVector, multiplyVector, substractVector,vectorLength,crossProduct,dotProduct,normalizeVector } from '../vector'
11
10
 
12
11
 
13
12
 
@@ -31,25 +30,6 @@ export class Circle {
31
30
  circle.id = uuidv4()
32
31
  return circle
33
32
  }
34
- getIntersections(object){
35
- const intersections=[]
36
- if(!object)return
37
- if(object.type=="point"){
38
- if(get3DDistanceBetweenPoints(object,this.center)==this.radius){
39
- intersections.push({...object})
40
- }
41
- }else if(object.type=="line"){
42
- let P=object.getProjectedPoint(this.center)
43
- let distance = get3DDistanceBetweenPoints(P,this.center)
44
- if(distance<=this.radius){
45
- let A=addVector(P,multiplyVector(Math.sqrt(Math.pow(this.radius,2)-Math.pow(distance,2)),object.getDirectionVector()))
46
- let B=addVector(P,multiplyVector(-Math.sqrt(Math.pow(this.radius,2)-Math.pow(distance,2)),object.getDirectionVector()))
47
- intersections.push({...A})
48
- intersections.push({...B})
49
- }
50
- }
51
- return intersections
52
- }
53
33
  getPxDistanceTo(point, canvasContext) {
54
34
  const toCanvasRef = canvasContext.toCanvasRef
55
35
  let pxCenter = toCanvasRef(this.center)
@@ -61,20 +41,6 @@ export class Circle {
61
41
  }
62
42
  return Math.abs(get3DDistanceBetweenPoints(point, pxCenter) - pxRadius)
63
43
  }
64
- getDistanceToPoint(point) {
65
- return get3DDistanceBetweenPoints(point, this.getProjectedPoint(point))
66
- }
67
- getHorizontalDistanceToPoint(point) {
68
- return getDistanceBetweenPoints(point, this.getVerticalProjectedPoint(point))
69
- }
70
- isInPlane(plane){
71
- if(!plane) return false
72
- const {point,normalVector}=plane
73
- const circleNormalVector=this.normalVector || {x:0,y:0,z:1}
74
- if(vectorLength(crossProduct(circleNormalVector,normalVector))>0.1) return false
75
- if(dotProduct(normalizeVector(substractVector(point,this.center)),normalVector)>0.1) return false
76
- return true
77
- }
78
44
  getProjectedPoint(point) {
79
45
  if(this.normalVector){
80
46
  point.z=verticalProjectionOnPlane(point,this.normalVector,this.center).z
@@ -88,13 +54,9 @@ export class Circle {
88
54
  }
89
55
  let x = this.center.x + (point.x - this.center.x) * (this.radius / distance)
90
56
  let y = this.center.y + (point.y - this.center.y) * (this.radius / distance)
91
- let z = this.center.z + (point.z - this.center.z) * (this.radius / distance)
92
- let P = new Point(x, y, z, this.layer)
57
+ let P = new Point(x, y, 0, this.layer)
93
58
  return P
94
59
  }
95
- getVerticalProjectedPoint(point) {
96
- return this.getProjectedPoint(point)
97
- }
98
60
  translate(vectorInMm) {
99
61
  this.center = translate2D(this.center, vectorInMm)
100
62
  }
@@ -6,12 +6,9 @@ import {
6
6
  isSamePoint3D,
7
7
  translate2D,
8
8
  midPoint,
9
- getDataAboutTwo3DLines,
10
- isPointBetweenSegment,
11
9
  } from '../geometry'
12
10
  import { v4 as uuidv4 } from 'uuid'
13
11
  import {Point} from './Point'
14
- import { substractVector,normalizeVector, addVector, multiplyVector,dotProduct } from '../vector'
15
12
 
16
13
 
17
14
  export class Line {
@@ -38,35 +35,6 @@ export class Line {
38
35
  line.infiniteLine = this.infiniteLine
39
36
  return line
40
37
  }
41
- getDirectionVector(){
42
- return normalizeVector(substractVector(this.outline[1],this.outline[0]))
43
- }
44
- getIntersections(object){
45
- const intersections=[]
46
- if(!object)return
47
- if(object.type=="point"){
48
- if(isSamePoint3D(this.getProjectedPoint(object),object)){
49
- intersections.push({...object})
50
- }
51
- }else if(object.type=="line"){
52
- const data = getDataAboutTwo3DLines(this.outline[0],this.getDirectionVector(),object.outline[0],object.getDirectionVector())
53
- if(!data){return []}
54
- let {distance,N} = data
55
- if(distance<0.1 && !!N){
56
- intersections.push({...N})
57
- }
58
- }else if(object.type=="circle"){
59
- let P=this.getProjectedPoint(object.center)
60
- let distance = get3DDistanceBetweenPoints(P,object.center)
61
- if(distance<=object.radius){
62
- let A=addVector(P,multiplyVector(Math.sqrt(Math.pow(object.radius,2)-Math.pow(distance,2)),this.getDirectionVector()))
63
- let B=addVector(P,multiplyVector(-Math.sqrt(Math.pow(object.radius,2)-Math.pow(distance,2)),this.getDirectionVector()))
64
- intersections.push({...A})
65
- intersections.push({...B})
66
- }
67
- }
68
- return intersections
69
- }
70
38
  pxLength(canvasContext) {
71
39
  return (
72
40
  getDistanceBetweenPoints(this.outline[0], this.outline[1]) /
@@ -101,47 +69,8 @@ export class Line {
101
69
  }
102
70
 
103
71
  let realityRefPoint = toRealityRef(point)
104
- let A={x:this.outline[0].x,y:this.outline[0].y,z:0}
105
- let B={x:this.outline[1].x,y:this.outline[1].y,z:0}
106
- let M={x:realityRefPoint.x,y:realityRefPoint.y,z:0}
107
- let P = getPointOnLine(realityRefPoint, A, B)
108
- P.z = 0
109
- return getDistanceBetweenPoints(M, P) / canvasContext.mmPerPx
110
- }
111
- isInPlane(plane){
112
- if(!plane) return false
113
- const {point,normalVector}=plane
114
- if(dotProduct(this.getDirectionVector(),normalVector)>0.1) return false
115
- if(dotProduct(normalizeVector(substractVector(point,this.outline[0])),normalVector)>0.1) return false
116
- return true
117
- }
118
- includesPoint2D(point,tolerance){
119
- const projection=this.getVerticalProjectedPoint(point)
120
- return this.getHorizontalDistanceToPoint(point) < tolerance && isPointBetweenSegment( projection, this.outline[0], this.outline[1])
121
- }
122
- getDistanceToPoint(point) {
123
- return get3DDistanceBetweenPoints(point, this.getProjectedPoint(point))
124
- }
125
- getHorizontalDistanceToPoint(point) {
126
- return getDistanceBetweenPoints(point, this.getVerticalProjectedPoint(point))
127
- }
128
- getVerticalProjectedPoint(point){
129
- if (this.outline.length == 0) {
130
- return null
131
- }
132
- if (isSamePoint3D(this.outline[0], this.outline[1])) {
133
- console.error("A == B Can't project point on Line")
134
- return null
135
- }
136
- let A= {...this.outline[0],z:0}
137
- let B= {...this.outline[1],z:0}
138
- let P = getPointOnLine({...point,z:0}, A,B)
139
- let AP = substractVector(P,A)
140
- let AB = substractVector(B,A)
141
- let k=dotProduct(AP,AB)/dotProduct(AB,AB)
142
- let zP=this.outline[0].z+k*(this.outline[1].z-this.outline[0].z)
143
- P.z=zP
144
- return P
72
+ let P = getPointOnLine(realityRefPoint, this.outline[0], this.outline[1])
73
+ return getDistanceBetweenPoints(realityRefPoint, P) / canvasContext.mmPerPx
145
74
  }
146
75
  getProjectedPoint(point) {
147
76
  if (this.outline.length == 0) {
@@ -1,12 +1,9 @@
1
1
 
2
- import { v4 as uuidv4 } from 'uuid'
3
2
  import {
4
3
  getDistanceBetweenPoints,
5
- get3DDistanceBetweenPoints,
6
- isSamePoint3D,
7
4
  translate2D,
8
5
  } from '../geometry'
9
- import { substractVector,dotProduct } from '../vector'
6
+ import { v4 as uuidv4 } from 'uuid'
10
7
 
11
8
  export class Point {
12
9
  constructor(x = 0, y = 0, z = 0, layer = null) {
@@ -22,24 +19,6 @@ export class Point {
22
19
  this.visible = true
23
20
  this.hasWarning = false
24
21
  }
25
- getIntersections(object){
26
- const intersections=[]
27
- if(!object)return
28
- if(object.type=="line"){
29
- if(isSamePoint3D(object.getProjectedPoint(this),this)){
30
- intersections.push({...this})
31
- }
32
- }else if(object.type=="point"){
33
- if(isSamePoint3D(object,this)){
34
- intersections.push({...object})
35
- }
36
- }else if(object.type=="circle"){
37
- if(get3DDistanceBetweenPoints(this,object.center)==object.radius){
38
- intersections.push({...this})
39
- }
40
- }
41
- return intersections
42
- }
43
22
  getPxDistanceTo(point, canvasContext) {
44
23
  const toRealityRef = canvasContext.toRealityRef
45
24
  const realityPoint = toRealityRef(point)
@@ -48,21 +27,6 @@ export class Point {
48
27
  getProjectedPoint(point) {
49
28
  return this
50
29
  }
51
- getVerticalProjectedPoint(point) {
52
- return this
53
- }
54
- getDistanceToPoint(point) {
55
- return get3DDistanceBetweenPoints(point, this.getProjectedPoint(point))
56
- }
57
- getHorizontalDistanceToPoint(point) {
58
- return getDistanceBetweenPoints(point, this.getVerticalProjectedPoint(point))
59
- }
60
- isInPlane(plane){
61
- if(!plane) return false
62
- const {point,normalVector}=plane
63
- if(dotProduct(substractVector(point,this),normalVector)>0.1) return false
64
- return true
65
- }
66
30
  translate(vectorInMm) {
67
31
  let translatedPoint = translate2D({ x: this.x, y: this.y }, vectorInMm)
68
32
  this.x = translatedPoint.x
@@ -124,10 +124,7 @@ export class Polygon {
124
124
  x: p.x,
125
125
  y: p.y,
126
126
  z: p.z,
127
- selected:p.selected,
128
- open:p.open,
129
- }
130
- }),
127
+ }}),
131
128
  holes: this.holes.map((p) => p.id),
132
129
  layer: this.layer,
133
130
  highlight: this.highlight,
package/src/vector.js CHANGED
@@ -25,12 +25,6 @@ export function addVector(u, v) {
25
25
  const result = u.x * v.x + u.y * v.y + u.z * v.z
26
26
  return result
27
27
  }
28
- export function areCollinear(u,v){
29
- return vectorLength(crossProduct(u,v)) == 0
30
- }
31
- export function areAlmostCollinear(u,v,tolerance){
32
- return vectorLength(crossProduct(u,v)) < tolerance
33
- }
34
28
  export function crossProduct(u, v) {
35
29
  const result = {}
36
30
  result.x = u.y * v.z - u.z * v.y