@@ -196,7 +196,7 @@ export class DimensionsService {
196196 } ) as number ;
197197
198198 if ( inputs . radians ) {
199- angle = this . math . degToRad ( { number : angle } ) ;
199+ angle = this . math . degToRad ( { number : angle } ) ;
200200 }
201201
202202 const txtOpt = new Inputs . OCCT . TextWiresDto ( ) ;
@@ -252,19 +252,75 @@ export class DimensionsService {
252252 extensionEnd : 0 ,
253253 } ) ;
254254
255- const text = this . wiresService . textWiresWithData ( {
256- text : inputs . label ,
257- xOffset : 0 ,
258- yOffset : 0 ,
259- height : inputs . labelSize ,
260- centerOnOrigin : true ,
255+ const txtOpt = new Inputs . OCCT . TextWiresDto ( ) ;
256+ txtOpt . text = inputs . label ;
257+ txtOpt . xOffset = 0 ;
258+ txtOpt . yOffset = 0 ;
259+ txtOpt . height = inputs . labelSize ;
260+ txtOpt . centerOnOrigin = true ;
261+
262+ const text = this . wiresService . textWiresWithData ( txtOpt ) ;
263+
264+ const textWidth = text . data . width ;
265+ const dirNorm = this . vector . normalized ( { vector : inputs . direction } ) ;
266+ const offsetLabelVec = this . vector . mul ( { vector : dirNorm , scalar : textWidth / 2 + inputs . labelOffset } ) ;
267+ // const translateTxtVec = this.vector.add({ first: inputs.direction, second: offsetLabelVec }) as Inputs.Base.Vector3;
268+
269+ const endPtLabelLine = this . point . translatePoints ( {
270+ points : [ inputs . endPoint ] ,
271+ translation : inputs . direction ,
272+ } ) [ 0 ] ;
273+
274+ const lineBeneathLabel = this . wiresService . createLineWireWithExtensions ( {
275+ start : inputs . endPoint ,
276+ end : endPtLabelLine ,
277+ extensionStart : 0 ,
278+ extensionEnd : 0 ,
261279 } ) ;
262- const labelTransformed = this . transformsService . translate ( {
280+
281+ const normalThreePoints = this . point . normalFromThreePoints ( {
282+ point1 : inputs . startPoint ,
283+ point2 : inputs . endPoint ,
284+ point3 : endPtLabelLine ,
285+ reverseNormal : false ,
286+ } ) ;
287+ const rotated = this . transformsService . rotate ( {
263288 shape : text . compound ,
264- translation : inputs . endPoint ,
289+ angle : - 90 ,
290+ axis : [ 0 , 1 , 0 ] ,
291+ } ) ;
292+
293+ const shapesToDelete = text . shapes . map ( ( s ) => s . shape ) ;
294+
295+ const alignedLabelTxtToDir = this . transformsService . alignNormAndAxis ( {
296+ shape : rotated ,
297+ fromOrigin : [ 0 , 0 , 0 ] ,
298+ fromNorm : [ 0 , 1 , 0 ] ,
299+ fromAx : [ 0 , 0 , 1 ] ,
300+ toOrigin : [ 0 , 0 , 0 ] ,
301+ toNorm : normalThreePoints ,
302+ toAx : dirNorm as Inputs . Base . Vector3 ,
265303 } ) ;
266304
267- const res = this . converterService . makeCompound ( { shapes : [ pinLine , labelTransformed ] } ) ;
305+ shapesToDelete . push ( rotated ) ;
306+
307+ const addToDir = this . vector . add ( {
308+ first : endPtLabelLine ,
309+ second : offsetLabelVec ,
310+ } ) as Inputs . Base . Vector3 ;
311+
312+ const labelTransformed = this . transformsService . translate ( {
313+ shape : alignedLabelTxtToDir ,
314+ translation : addToDir ,
315+ } ) ;
316+ shapesToDelete . push ( alignedLabelTxtToDir ) ;
317+
318+ const res = this . converterService . makeCompound ( { shapes : [ pinLine , labelTransformed , lineBeneathLabel ] } ) ;
319+
320+ // delete shapes
321+ shapesToDelete . forEach ( ( shape ) => {
322+ shape . delete ( ) ;
323+ } ) ;
268324 return res ;
269325 }
270326
0 commit comments