Git Product home page Git Product logo

Comments (16)

danmarshall avatar danmarshall commented on June 9, 2024 1

just published in 0.17.4 on npm, the website is updating now.

from maker.js.

danmarshall avatar danmarshall commented on June 9, 2024

Hello, in your image, I see that 3 paths converge at one point:
image

I'm wondering if this is failing the chain-finding algorithm. Can you remove the convergence and try again?

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

Not sure that’s the case because I am running the chain algorithm separately on each path. Also it works for that path if margin is less and count is more than 1 for example in 2nd image.
For all the paths that are failing the count is 1 with same margin.
But let me try

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

Hello, in your image, I see that 3 paths converge at one point: image

I'm wondering if this is failing the chain-finding algorithm. Can you remove the convergence and try again?

Yep still not working after removing the path.

image

Also tried setting the margin as 1 and 0 when count is 1 but still same result.

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

Hi @danmarshall
I also tried placing rectangles without chilldrenOnChain but its placing it out of the path.
I am getting the location of placement from the path and using that to move the rectangle at the location.
the location is based on a object from pathModel.

makerjs.model.move(rectangle, location);
model =
    {
        ...model,
        [`path${i}`]: pathModel,
        [`row${i}`]: rectangle,
    };

image

from maker.js.

danmarshall avatar danmarshall commented on June 9, 2024

Hello @noobd3v, I'm having trouble using your path data. Let's simplify to one simple scenario so we can repro.
The paths array pathdata you provided, I'm not able to render in other online tools such as https://yqnn.github.io/svg-path-editor/ or https://svgomg.net/
Can you provide just one path data that is renderable?

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

Hi @danmarshall, Sorry my bad some of the paths were truncated while I copied . Please refer below the set of paths they all are working now


0:
'M4.388293-8.821126Q4.464356-8.917352 4.5375-9.003514M4.5375-9.003514Q4.596368-9.072858 4.65359-9.135965M4.65359-9.135965Q4.79427-9.291114 4.938767-9.422468M4.938767-9.422468Q5.003453-9.481271 5.068057-9.534488M5.068057-9.534488Q5.12793-9.583809 5.187824-9.628409M5.187824-9.628409Q5.242993-9.669489 5.298286-9.706644M5.298286-9.706644Q5.348987-9.740712 5.399916-9.771562M5.399916-9.771562Q5.446496-9.799777 5.493401-9.825381M5.493401-9.825381Q5.536285-9.84879 5.579583-9.870094M5.579583-9.870094Q5.619236-9.889605 5.659385-9.907422M5.659385-9.907422Q5.696284-9.923798 5.733751-9.93881M5.733751-9.93881Q5.768357-9.952675 5.803595-9.965437M5.803595-9.965437Q5.836335-9.977294 5.869764-9.988249M5.869764-9.988249Q5.901027-9.998495 5.933027-10.007996M5.933027-10.007996Q5.991647-10.025402 6.053464-10.040515M6.053464-10.040515Q6.10966-10.054255 6.169336-10.066306M6.169336-10.066306Q6.224756-10.077498 6.283913-10.087384M6.283913-10.087384Q6.295412-10.089306 6.307069-10.091181M6.307069-10.091181Q6.352033-10.098414 6.399582-10.104994M6.399582-10.104994Q6.456619-10.112887 6.518082-10.119935M6.518082-10.119935Q6.57682-10.126671 6.640692-10.132758M6.640692-10.132758Q6.700214-10.138431 6.766135-10.143722M4.388293-8.821126Q4.399829-8.7978 4.41173-8.774369M4.41173-8.774369Q4.45334-8.692443 4.499166-8.609669M4.499166-8.609669Q4.543648-8.529323 4.591445-8.449364M4.591445-8.449364Q4.640969-8.366514 4.693366-8.285233M4.693366-8.285233Q4.749453-8.198227 4.808287-8.113867M4.808287-8.113867Q4.872417-8.021913 4.93946-7.933614M4.93946-7.933614Q4.975471-7.886185 5.012291-7.839854M5.012291-7.839854Q5.045116-7.798548 5.078582-7.758119M5.078582-7.758119Q5.090011-7.744311 5.881601-6.802823M5.881601-6.802823L6.664162-5.872074M6.664162-5.872074Q6.750616-5.769248 6.845624-5.673418M6.845624-5.673418L6.9589-5.559162M6.9589-5.559162L8.145691-6.463383M8.145691-6.463383Q8.217907-6.518405 8.27882-6.583845M8.27882-6.583845L8.825905-7.171586M8.825905-7.171586L9.102077-7.468282M9.102077-7.468282C9.241424-7.617984 9.382549-7.766027 9.520825-7.91673M9.520825-7.91673Q9.599154-8.002099 9.668271-8.081936M9.668271-8.081936Q9.70432-8.123577 9.738177-8.164068M9.738177-8.164068Q9.773035-8.205759 9.805768-8.246469M9.805768-8.246469Q9.839527-8.288456 9.871221-8.329645M9.871221-8.329645Q9.903971-8.372206 9.93471-8.414166M9.93471-8.414166Q9.96653-8.457604 9.996387-8.500659M9.996387-8.500659Q10.023246-8.539392 10.05587-8.590027M10.05587-8.590027Q10.085606-8.636182 10.113712-8.682708M10.113712-8.682708Q10.142701-8.730698 10.170128-8.779372M10.170128-8.779372Q10.198395-8.829536 10.225185-8.880749M10.225185-8.880749Q10.230051-8.890051 10.234872-8.899395M10.234872-8.899395Q10.257351-8.942962 10.27891-8.987548M10.27891-8.987548Q10.305728-9.043013 10.331304-9.100433M10.331304-9.100433Q10.337752-9.11491 10.344129-9.12953M10.344129-9.12953Q10.385597-9.22459 10.417641-9.309912M10.417641-9.309912Q10.420461-9.317421 10.423248-9.324953M10.423248-9.324953Q10.438711-9.36674 10.453201-9.409344M10.453201-9.409344Q10.47179-9.463999 10.488901-9.520365M10.488901-9.520365Q10.495469-9.541999 10.501831-9.563924M10.501831-9.563924Q10.508479-9.586835 10.51491-9.610086M10.51491-9.610086Q10.499723-9.621446 10.484562-9.632512M10.484562-9.632512Q10.429641-9.672601 10.374975-9.70889M10.374975-9.70889Q10.339958-9.732135 10.305-9.753853M10.305-9.753853Q10.287732-9.76458 10.270471-9.77494M10.270471-9.77494Q10.259619-9.781453 10.248768-9.787821M10.248768-9.787821Q10.210143-9.810491 10.171481-9.831358M10.171481-9.831358Q10.124935-9.856482 10.078198-9.879066M10.078198-9.879066Q10.034541-9.900162 9.990552-9.919123M9.990552-9.919123Q9.949629-9.936762 9.90824-9.95263M9.90824-9.95263Q9.869801-9.967368 9.830773-9.980649M9.830773-9.980649Q9.794505-9.992991 9.757537-10.00414M9.757537-10.00414Q9.723101-10.014527 9.687862-10.023937M9.687862-10.023937Q9.65491-10.032737 9.621065-10.040734M9.621065-10.040734Q9.589266-10.048249 9.556494-10.055098M9.556494-10.055098Q9.525541-10.061568 9.493542-10.067482M9.493542-10.067482Q9.434522-10.07839 9.370393-10.087667M9.370393-10.087667Q9.312205-10.096085 9.248043-10.10343M9.248043-10.10343Q9.189179-10.110168 9.123803-10.116173M9.123803-10.116173Q9.063411-10.12172 8.995683-10.126803M8.995683-10.126803Q8.987897-10.127387 8.979998-10.127967M8.979998-10.127967Q8.909298-10.133154 8.827194-10.138114'
1:
'M10.700016-9.680782Q10.815473-9.72382 10.925484-9.762058M10.925484-9.762058Q11.039948-9.801843 11.150062-9.836969M11.150062-9.836969Q11.263421-9.873131 11.373771-9.904864M11.373771-9.904864Q11.486287-9.93722 11.596843-9.965308M11.596843-9.965308Q11.652711-9.979502 11.708292-9.992663M11.708292-9.992663Q11.764119-10.005881 11.819804-10.018092M11.819804-10.018092Q11.875648-10.030337 11.9315-10.041602M11.9315-10.041602Q11.956776-10.0467 11.982078-10.051602M11.982078-10.051602Q12.01277-10.057548 12.043525-10.063211M12.043525-10.063211Q12.099612-10.073539 12.156044-10.082948M12.156044-10.082948Q12.191079-10.088789 12.226307-10.094287M12.226307-10.094287Q12.247734-10.097631 12.269247-10.10085M12.269247-10.10085Q12.325915-10.109329 12.383343-10.116966M12.383343-10.116966Q12.440438-10.124559 12.498562-10.131355M12.498562-10.131355Q12.540832-10.136297 12.583809-10.140838'
2:
'M7.15883-5.155221L7.245348-5.069074M7.245348-5.069074Q7.358689-4.956219 7.459938-4.833736M7.459938-4.833736L8.25756-3.868828M8.25756-3.868828L9.016953-2.950166M9.016953-2.950166C9.054733-2.904462 9.092962-2.859131 9.130364-2.813115M9.130364-2.813115Q9.190695-2.738889 9.244501-2.66828M9.244501-2.66828Q9.312887-2.57854 9.374907-2.489214M9.374907-2.489214Q9.410463-2.438003 9.444362-2.38632M9.444362-2.38632Q9.480568-2.331121 9.51508-2.275086M9.51508-2.275086Q9.551226-2.216396 9.585673-2.156533M9.585673-2.156533Q9.587394-2.153543 9.58911-2.15055M9.58911-2.15055Q9.622694-2.091986 9.654777-2.032086M9.654777-2.032086Q9.688773-1.968616 9.721203-1.903427M9.721203-1.903427Q9.753341-1.838823 9.784059-1.772295M9.784059-1.772295Q9.793351-1.752168 9.802522-1.73185M9.802522-1.73185C10.292588-1.497379 10.778759-1.254848 11.269975-1.022757M11.269975-1.022757Q11.356811-0.981728 11.44304-0.943634M11.44304-0.943634Q11.527385-0.906371 11.611389-0.87181M11.611389-0.87181Q11.677427-0.84464 11.743398-0.819081M11.743398-0.819081Q11.759416-0.812875 11.775435-0.806762M11.775435-0.806762Q11.855444-0.776229 11.935636-0.747957M11.935636-0.747957Q11.985742-0.730292 12.036009-0.713478M12.036009-0.713478Q12.064217-0.704042 12.092493-0.694868M12.092493-0.694868Q12.169171-0.66999 12.246538-0.646979M12.246538-0.646979Q12.321966-0.624545 12.398325-0.603802M12.398325-0.603802Q12.47279-0.583574 12.548422-0.564879M12.548422-0.564879Q12.622211-0.546639 12.697393-0.529788M12.697393-0.529788Q12.770789-0.513338 12.845795-0.498148M12.845795-0.498148Q12.857917-0.495693 12.870086-0.49327M12.870086-0.49327Q12.931481-0.481046 12.994162-0.469616M12.994162-0.469616Q13.06757-0.456229 13.143002-0.443886M13.143002-0.443886Q13.168819-0.439661 13.194896-0.435555'
3:
'M9.709041-1.621731Q9.647363-1.550415 9.584615-1.48137M9.584615-1.48137Q9.528313-1.419419 9.470685-1.358786M9.470685-1.358786Q9.3612-1.243591 9.266393-1.152631M9.266393-1.152631Q9.21556-1.10386 9.165845-1.058961M9.165845-1.058961Q9.114414-1.012512 9.063953-0.970001M9.063953-0.970001Q9.012254-0.926448 8.961366-0.886853M8.961366-0.886853Q8.909864-0.846781 8.858998-0.810612M8.858998-0.810612Q8.808265-0.774539 8.757982-0.742218M8.757982-0.742218Q8.708651-0.71051 8.659573-0.682299M8.659573-0.682299Q8.6498-0.67668 8.640032-0.671198M8.640032-0.671198Q8.605699-0.651929 8.571385-0.634313M8.571385-0.634313Q8.568184-0.63267 8.564983-0.631041M8.564983-0.631041Q8.520163-0.608231 8.475194-0.58815M8.475194-0.58815Q8.433175-0.569387 8.390813-0.552911M8.390813-0.552911Q8.351674-0.537689 8.312009-0.524329M8.312009-0.524329Q8.275621-0.512073 8.23854-0.5013M8.23854-0.5013Q8.204624-0.491446 8.169861-0.482757M8.169861-0.482757Q8.138046-0.474804 8.105244-0.467756M8.105244-0.467756Q8.075123-0.461285 8.043886-0.455516M8.043886-0.455516Q8.015056-0.450191 7.98499-0.445413M7.98499-0.445413Q7.931164-0.436858 7.871692-0.429803M7.871692-0.429803Q7.833903-0.42532 7.792856-0.421322M7.792856-0.421322Q7.776909-0.419769 7.760364-0.418278M7.760364-0.418278Q7.707742-0.413535 7.647269-0.409274M7.647269-0.409274Q7.593273-0.405469 7.529684-0.401816M7.529684-0.401816Q7.474403-0.39864 7.406749-0.395288'
4:
'M5.983151-4.266626Q5.897256-4.201705 5.827182-4.12287M5.827182-4.12287L5.300278-3.530089M5.300278-3.530089Q4.902706-3.08281 4.865797-3.041287M4.865797-3.041287Q4.657794-2.807278 4.597771-2.737058M4.597771-2.737058Q4.512611-2.637431 4.433685-2.539934M4.433685-2.539934Q4.355792-2.443712 4.284793-2.35058M4.284793-2.35058Q4.24939-2.304139 4.215843-2.258651M4.215843-2.258651Q4.182144-2.212956 4.150398-2.168329M4.150398-2.168329Q4.118314-2.123228 4.088285-2.079301M4.088285-2.079301Q4.057698-2.034559 4.029276-1.991083M4.029276-1.991083Q4.000024-1.946337 3.973059-1.902924M3.973059-1.902924Q3.944921-1.857623 3.919215-1.813677M3.919215-1.813677Q3.89189-1.766963 3.867184-1.721558M3.867184-1.721558Q3.842624-1.676422 3.815943-1.623818M3.815943-1.623818Q3.788164-1.569051 3.763414-1.515973M3.763414-1.515973Q3.7626-1.514228 3.76179-1.512485M3.76179-1.512485Q3.718435-1.41923 3.674431-1.307327M3.674431-1.307327Q3.671048-1.298725 3.667708-1.290129M3.667708-1.290129Q3.653631-1.2539 3.640248-1.217618M3.640248-1.217618Q3.622178-1.168631 3.605226-1.119146M3.605226-1.119146Q3.592954-1.083322 3.581208-1.047068M3.581208-1.047068Q3.575214-1.028564 3.569349-1.009925M3.569349-1.009925Q3.561121-0.983777 3.553137-0.957326M3.553137-0.957326Q3.5817-0.935025 3.610033-0.91383M3.610033-0.91383Q3.660351-0.876188 3.71025-0.841806M3.71025-0.841806Q3.758791-0.808361 3.80718-0.77783M3.80718-0.77783Q3.839724-0.757297 3.872273-0.738036M3.872273-0.738036Q3.886325-0.72972 3.900386-0.721636M3.900386-0.721636Q3.944877-0.696059 3.989559-0.67275M3.989559-0.67275Q4.006888-0.66371 4.024264-0.655001M4.024264-0.655001Q4.049349-0.642429 4.074562-0.630532M4.074562-0.630532Q4.114775-0.611557 4.155443-0.594242M4.155443-0.594242Q4.19365-0.577975 4.232427-0.5631M4.232427-0.5631Q4.26881-0.549143 4.305873-0.536345M4.305873-0.536345Q4.340665-0.52433 4.376236-0.513274M4.376236-0.513274Q4.409695-0.502874 4.444026-0.493265M4.444026-0.493265Q4.476418-0.484199 4.509768-0.475786M4.509768-0.475786Q4.567676-0.461177 4.629353-0.448325M4.629353-0.448325Q4.633234-0.447517 4.637132-0.446714M4.637132-0.446714Q4.678661-0.438167 4.722417-0.430296M4.722417-0.430296Q4.741975-0.426778 4.762043-0.423382M4.762043-0.423382Q4.822098-0.413221 4.88755-0.404028M4.88755-0.404028Q4.948834-0.39542 5.016043-0.387492M5.016043-0.387492Q5.07946-0.380012 5.14936-0.372995M5.14936-0.372995Q5.179225-0.369997 5.210455-0.367065'
5:
'M3.541013-0.953168Q3.473933-0.930202 3.400011-0.905821M3.400011-0.905821Q3.350018-0.889333 3.171833-0.83137M3.171833-0.83137Q3.052707-0.792619 2.949772-0.761123M2.949772-0.761123Q2.839078-0.727254 2.731575-0.696868M2.731575-0.696868Q2.623328-0.666272 2.5165-0.638684M2.5165-0.638684Q2.459903-0.624068 2.403574-0.61026M2.403574-0.61026Q2.353714-0.598039 2.304027-0.586443M2.304027-0.586443Q2.19855-0.561826 2.093692-0.539988M2.093692-0.539988Q1.989137-0.518214 1.885054-0.499174M1.885054-0.499174Q1.781181-0.480172 1.677675-0.463873M1.677675-0.463873Q1.574255-0.447589 1.471111-0.433989M1.471111-0.433989Q1.377637-0.421664 1.284322-0.411535'
6:
'M3.035-9.46253C2.931846-9.51142 2.829565-9.56212 2.726594-9.611389M2.726594-9.611389Q2.593909-9.674876 2.482323-9.724137M2.482323-9.724137Q2.415947-9.75344 2.352969-9.779567M2.352969-9.779567Q2.28512-9.807716 2.219787-9.832774M2.219787-9.832774Q2.150815-9.859228 2.083592-9.882644M2.083592-9.882644Q2.013848-9.906938 1.945132-9.928262M1.945132-9.928262Q1.878606-9.948905 1.812381-9.966971M1.812381-9.966971Q1.808672-9.967983 1.804962-9.968987M1.804962-9.968987Q1.734341-9.988103 1.663326-10.004486M1.663326-10.004486Q1.592254-10.020883 1.520074-10.034707M1.520074-10.034707Q1.453626-10.047433 1.374643-10.059826M1.374643-10.059826Q1.294667-10.072375 1.232247-10.081067M1.232247-10.081067Q1.229366-10.081469 1.226499-10.081865M1.226499-10.081865Q1.212694-10.083774 1.199167-10.085582'


from maker.js.

danmarshall avatar danmarshall commented on June 9, 2024

Hello, I'm going to close this issue since #550 is similar and making sure count > 1 is probably the workaround.

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

As a workaround for now, can you ensure your calling code only calls layout with a count > 1?

well it is very much needed in some cases. That's why I was trying to figure out the alternates also with childrenOnPath. I was trying to place single rect on a path. And as alternate I also tried placing it on one of the coordinates from the path but the actual placement after exporting was different.
For example these coordinates [13.204878491338434, 7.632513965353765] belong to one of the path

1:
'M10

But I am getting following result not sure what I am doing wrong. I also tried walking the path to see the offset but the offset was 0,0.
image
I was setting the origin in the rect.
let rectClone= makerjs.model.clone(rect); rectClone.origin = [13.204878491338434, 7.632513965353765];
I also wanted to give rotation using following code
makerjs.model.rotate(rectClone, rotation);
but after rotation my result was way off which is in this screenshot

image

Original code stays the same only using a clone object manually

here is the code I am using.
let model: any = {
models: {
}

from maker.js.

danmarshall avatar danmarshall commented on June 9, 2024

Can you provide code for the repro?

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

Currently I am using the hardcoded point of origin here.
The provided point in the last comment was incorrect. But I am also calculating the middle using arc straighten. added the logic below let me know if its incorrect.

let pathsArray = [
            'M4.388293-8.821126Q4.464356-8.917352 4.5375-9.003514M4.5375-9.003514Q4.596368-9.072858 4.65359-9.135965M4.65359-9.135965Q4.79427-9.291114 4.938767-9.422468M4.938767-9.422468Q5.003453-9.481271 5.068057-9.534488M5.068057-9.534488Q5.12793-9.583809 5.187824-9.628409M5.187824-9.628409Q5.242993-9.669489 5.298286-9.706644M5.298286-9.706644Q5.348987-9.740712 5.399916-9.771562M5.399916-9.771562Q5.446496-9.799777 5.493401-9.825381M5.493401-9.825381Q5.536285-9.84879 5.579583-9.870094M5.579583-9.870094Q5.619236-9.889605 5.659385-9.907422M5.659385-9.907422Q5.696284-9.923798 5.733751-9.93881M5.733751-9.93881Q5.768357-9.952675 5.803595-9.965437M5.803595-9.965437Q5.836335-9.977294 5.869764-9.988249M5.869764-9.988249Q5.901027-9.998495 5.933027-10.007996M5.933027-10.007996Q5.991647-10.025402 6.053464-10.040515M6.053464-10.040515Q6.10966-10.054255 6.169336-10.066306M6.169336-10.066306Q6.224756-10.077498 6.283913-10.087384M6.283913-10.087384Q6.295412-10.089306 6.307069-10.091181M6.307069-10.091181Q6.352033-10.098414 6.399582-10.104994M6.399582-10.104994Q6.456619-10.112887 6.518082-10.119935M6.518082-10.119935Q6.57682-10.126671 6.640692-10.132758M6.640692-10.132758Q6.700214-10.138431 6.766135-10.143722M4.388293-8.821126Q4.399829-8.7978 4.41173-8.774369M4.41173-8.774369Q4.45334-8.692443 4.499166-8.609669M4.499166-8.609669Q4.543648-8.529323 4.591445-8.449364M4.591445-8.449364Q4.640969-8.366514 4.693366-8.285233M4.693366-8.285233Q4.749453-8.198227 4.808287-8.113867M4.808287-8.113867Q4.872417-8.021913 4.93946-7.933614M4.93946-7.933614Q4.975471-7.886185 5.012291-7.839854M5.012291-7.839854Q5.045116-7.798548 5.078582-7.758119M5.078582-7.758119Q5.090011-7.744311 5.881601-6.802823M5.881601-6.802823L6.664162-5.872074M6.664162-5.872074Q6.750616-5.769248 6.845624-5.673418M6.845624-5.673418L6.9589-5.559162M6.9589-5.559162L8.145691-6.463383M8.145691-6.463383Q8.217907-6.518405 8.27882-6.583845M8.27882-6.583845L8.825905-7.171586M8.825905-7.171586L9.102077-7.468282M9.102077-7.468282C9.241424-7.617984 9.382549-7.766027 9.520825-7.91673M9.520825-7.91673Q9.599154-8.002099 9.668271-8.081936M9.668271-8.081936Q9.70432-8.123577 9.738177-8.164068M9.738177-8.164068Q9.773035-8.205759 9.805768-8.246469M9.805768-8.246469Q9.839527-8.288456 9.871221-8.329645M9.871221-8.329645Q9.903971-8.372206 9.93471-8.414166M9.93471-8.414166Q9.96653-8.457604 9.996387-8.500659M9.996387-8.500659Q10.023246-8.539392 10.05587-8.590027M10.05587-8.590027Q10.085606-8.636182 10.113712-8.682708M10.113712-8.682708Q10.142701-8.730698 10.170128-8.779372M10.170128-8.779372Q10.198395-8.829536 10.225185-8.880749M10.225185-8.880749Q10.230051-8.890051 10.234872-8.899395M10.234872-8.899395Q10.257351-8.942962 10.27891-8.987548M10.27891-8.987548Q10.305728-9.043013 10.331304-9.100433M10.331304-9.100433Q10.337752-9.11491 10.344129-9.12953M10.344129-9.12953Q10.385597-9.22459 10.417641-9.309912M10.417641-9.309912Q10.420461-9.317421 10.423248-9.324953M10.423248-9.324953Q10.438711-9.36674 10.453201-9.409344M10.453201-9.409344Q10.47179-9.463999 10.488901-9.520365M10.488901-9.520365Q10.495469-9.541999 10.501831-9.563924M10.501831-9.563924Q10.508479-9.586835 10.51491-9.610086M10.51491-9.610086Q10.499723-9.621446 10.484562-9.632512M10.484562-9.632512Q10.429641-9.672601 10.374975-9.70889M10.374975-9.70889Q10.339958-9.732135 10.305-9.753853M10.305-9.753853Q10.287732-9.76458 10.270471-9.77494M10.270471-9.77494Q10.259619-9.781453 10.248768-9.787821M10.248768-9.787821Q10.210143-9.810491 10.171481-9.831358M10.171481-9.831358Q10.124935-9.856482 10.078198-9.879066M10.078198-9.879066Q10.034541-9.900162 9.990552-9.919123M9.990552-9.919123Q9.949629-9.936762 9.90824-9.95263M9.90824-9.95263Q9.869801-9.967368 9.830773-9.980649M9.830773-9.980649Q9.794505-9.992991 9.757537-10.00414M9.757537-10.00414Q9.723101-10.014527 9.687862-10.023937M9.687862-10.023937Q9.65491-10.032737 9.621065-10.040734M9.621065-10.040734Q9.589266-10.048249 9.556494-10.055098M9.556494-10.055098Q9.525541-10.061568 9.493542-10.067482M9.493542-10.067482Q9.434522-10.07839 9.370393-10.087667M9.370393-10.087667Q9.312205-10.096085 9.248043-10.10343M9.248043-10.10343Q9.189179-10.110168 9.123803-10.116173M9.123803-10.116173Q9.063411-10.12172 8.995683-10.126803M8.995683-10.126803Q8.987897-10.127387 8.979998-10.127967M8.979998-10.127967Q8.909298-10.133154 8.827194-10.138114',
            'M10.700016-9.680782Q10.815473-9.72382 10.925484-9.762058M10.925484-9.762058Q11.039948-9.801843 11.150062-9.836969M11.150062-9.836969Q11.263421-9.873131 11.373771-9.904864M11.373771-9.904864Q11.486287-9.93722 11.596843-9.965308M11.596843-9.965308Q11.652711-9.979502 11.708292-9.992663M11.708292-9.992663Q11.764119-10.005881 11.819804-10.018092M11.819804-10.018092Q11.875648-10.030337 11.9315-10.041602M11.9315-10.041602Q11.956776-10.0467 11.982078-10.051602M11.982078-10.051602Q12.01277-10.057548 12.043525-10.063211M12.043525-10.063211Q12.099612-10.073539 12.156044-10.082948M12.156044-10.082948Q12.191079-10.088789 12.226307-10.094287M12.226307-10.094287Q12.247734-10.097631 12.269247-10.10085M12.269247-10.10085Q12.325915-10.109329 12.383343-10.116966M12.383343-10.116966Q12.440438-10.124559 12.498562-10.131355M12.498562-10.131355Q12.540832-10.136297 12.583809-10.140838',
            'M7.15883-5.155221L7.245348-5.069074M7.245348-5.069074Q7.358689-4.956219 7.459938-4.833736M7.459938-4.833736L8.25756-3.868828M8.25756-3.868828L9.016953-2.950166M9.016953-2.950166C9.054733-2.904462 9.092962-2.859131 9.130364-2.813115M9.130364-2.813115Q9.190695-2.738889 9.244501-2.66828M9.244501-2.66828Q9.312887-2.57854 9.374907-2.489214M9.374907-2.489214Q9.410463-2.438003 9.444362-2.38632M9.444362-2.38632Q9.480568-2.331121 9.51508-2.275086M9.51508-2.275086Q9.551226-2.216396 9.585673-2.156533M9.585673-2.156533Q9.587394-2.153543 9.58911-2.15055M9.58911-2.15055Q9.622694-2.091986 9.654777-2.032086M9.654777-2.032086Q9.688773-1.968616 9.721203-1.903427M9.721203-1.903427Q9.753341-1.838823 9.784059-1.772295M9.784059-1.772295Q9.793351-1.752168 9.802522-1.73185M9.802522-1.73185C10.292588-1.497379 10.778759-1.254848 11.269975-1.022757M11.269975-1.022757Q11.356811-0.981728 11.44304-0.943634M11.44304-0.943634Q11.527385-0.906371 11.611389-0.87181M11.611389-0.87181Q11.677427-0.84464 11.743398-0.819081M11.743398-0.819081Q11.759416-0.812875 11.775435-0.806762M11.775435-0.806762Q11.855444-0.776229 11.935636-0.747957M11.935636-0.747957Q11.985742-0.730292 12.036009-0.713478M12.036009-0.713478Q12.064217-0.704042 12.092493-0.694868M12.092493-0.694868Q12.169171-0.66999 12.246538-0.646979M12.246538-0.646979Q12.321966-0.624545 12.398325-0.603802M12.398325-0.603802Q12.47279-0.583574 12.548422-0.564879M12.548422-0.564879Q12.622211-0.546639 12.697393-0.529788M12.697393-0.529788Q12.770789-0.513338 12.845795-0.498148M12.845795-0.498148Q12.857917-0.495693 12.870086-0.49327M12.870086-0.49327Q12.931481-0.481046 12.994162-0.469616M12.994162-0.469616Q13.06757-0.456229 13.143002-0.443886M13.143002-0.443886Q13.168819-0.439661 13.194896-0.435555'
            ];
        let model: any = {
            models: {
            }
        };
        
        const rect = new makerjs.models.Rectangle(1, 1);
        const margin = 8;
        const FRACTION_HALF = 0.5;
        for (let i = 0; i < pathsArray.length; i++) {
            let pathModel = makerjs.importer.fromSVGPathData(pathsArray[i]);
            let pathsArry: any[] = [];
            if (pathModel.models) {
                Object.entries(pathModel.models).forEach(([key, value]) => {
                    if (value && value.paths) Object.entries(value.paths).forEach(([k, v]) => {
                        v.layer = "red";
                        pathsArry.push(v);
                    });
                });
            }
            if (pathModel.paths) {
                Object.entries(pathModel.paths).forEach(([key, value]) => {
                    if (value)
                        value.layer = "red";
                    pathsArry.push(value);
                });
            }
            const chain = makerjs.model.findSingleChain(pathModel);
            const count = Math.ceil(chain.pathLength / margin);
            if(count > 1) {
                const row = makerjs.layout.cloneToRow(rect, count, margin);
                makerjs.layout.childrenOnChain(row, chain, 0.5, false, true);
                model.models=
                {
                    ...model.models,
                    [`path${i}`]: pathModel,
                    [`row${i}`]: row,
                };
            }
            else
            {
                let rectClone= makerjs.model.clone(rect);
                const middleLen = chain.pathLength * FRACTION_HALF;
                let currLen = 0;
                let middlePathIndex = 0;
                let extraDistanceFromMiddle = 0;
                for (let i = 0; i < pathsArry.length; i++) {
                    currLen += makerjs.measure.pathLength(pathsArry[i]);
                    if (currLen >= middleLen) {
                        middlePathIndex = i;
                        extraDistanceFromMiddle = currLen - middleLen;
                        break;
                    }
                }
                const pathLen = makerjs.measure.pathLength(pathsArry[middlePathIndex]);
                let middle: makerjs.IPoint = [0, 0];
                
                if (makerjs.isPathArc(pathsArry[middlePathIndex])) {
                    // let path: IPathArc = pathsArry[middlePathIndex];
                    let strtModel = makerjs.path.straighten(pathsArry[middlePathIndex]);
                    if (strtModel.paths && strtModel.origin) {                 
                        middle = getPointAtDistance(strtModel.paths['ShapeLine1'] as makerjs.IPathLine, extraDistanceFromMiddle);
                        middle[0] = strtModel.origin[0];
                        middle[1] = strtModel.origin[1];
                    }
                }
                else if (makerjs.isPathLine(pathsArry[middlePathIndex])) {
                    middle = getPointAtDistance(pathsArry[middlePathIndex], extraDistanceFromMiddle);
                }
                rectClone.origin = middle;
                model.models=
                {
                    ...model.models,
                    [`path${i}`]: pathModel,
                    [`row${i}`]: rectClone,
                };
            }        
        }
        makerjs.exporter.toSVG(model);

 function getPointAtDistance(line: makerjs.IPathLine, distance: number): makerjs.IPoint {
        const angle = makerjs.angle.ofPointInRadians(line.origin, line.end);
        const x = line.origin[0] + (distance * Math.cos(angle));
        const y = line.origin[1] + (distance * Math.sin(angle));
        return [x, y];
    }

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

I see one problem with my code i.e. Arc is from a Bezier curve and that data is not taken in context while generating the straight lines. But there s not a straighten method that will take full model context in arguments to provide the straighten arc. How can I straighten such arcs? There is some data in seed object but not sure how to utilize that.

from maker.js.

danmarshall avatar danmarshall commented on June 9, 2024

Fix is coming:
image

Here's some simplified code:

var makerjs = require('makerjs');

var pathsArray = [
  'M4.388293-8.821126Q4.464356-8.917352 4.5375-9.003514M4.5375-9.003514Q4.596368-9.072858 4.65359-9.135965M4.65359-9.135965Q4.79427-9.291114 4.938767-9.422468M4.938767-9.422468Q5.003453-9.481271 5.068057-9.534488M5.068057-9.534488Q5.12793-9.583809 5.187824-9.628409M5.187824-9.628409Q5.242993-9.669489 5.298286-9.706644M5.298286-9.706644Q5.348987-9.740712 5.399916-9.771562M5.399916-9.771562Q5.446496-9.799777 5.493401-9.825381M5.493401-9.825381Q5.536285-9.84879 5.579583-9.870094M5.579583-9.870094Q5.619236-9.889605 5.659385-9.907422M5.659385-9.907422Q5.696284-9.923798 5.733751-9.93881M5.733751-9.93881Q5.768357-9.952675 5.803595-9.965437M5.803595-9.965437Q5.836335-9.977294 5.869764-9.988249M5.869764-9.988249Q5.901027-9.998495 5.933027-10.007996M5.933027-10.007996Q5.991647-10.025402 6.053464-10.040515M6.053464-10.040515Q6.10966-10.054255 6.169336-10.066306M6.169336-10.066306Q6.224756-10.077498 6.283913-10.087384M6.283913-10.087384Q6.295412-10.089306 6.307069-10.091181M6.307069-10.091181Q6.352033-10.098414 6.399582-10.104994M6.399582-10.104994Q6.456619-10.112887 6.518082-10.119935M6.518082-10.119935Q6.57682-10.126671 6.640692-10.132758M6.640692-10.132758Q6.700214-10.138431 6.766135-10.143722M4.388293-8.821126Q4.399829-8.7978 4.41173-8.774369M4.41173-8.774369Q4.45334-8.692443 4.499166-8.609669M4.499166-8.609669Q4.543648-8.529323 4.591445-8.449364M4.591445-8.449364Q4.640969-8.366514 4.693366-8.285233M4.693366-8.285233Q4.749453-8.198227 4.808287-8.113867M4.808287-8.113867Q4.872417-8.021913 4.93946-7.933614M4.93946-7.933614Q4.975471-7.886185 5.012291-7.839854M5.012291-7.839854Q5.045116-7.798548 5.078582-7.758119M5.078582-7.758119Q5.090011-7.744311 5.881601-6.802823M5.881601-6.802823L6.664162-5.872074M6.664162-5.872074Q6.750616-5.769248 6.845624-5.673418M6.845624-5.673418L6.9589-5.559162M6.9589-5.559162L8.145691-6.463383M8.145691-6.463383Q8.217907-6.518405 8.27882-6.583845M8.27882-6.583845L8.825905-7.171586M8.825905-7.171586L9.102077-7.468282M9.102077-7.468282C9.241424-7.617984 9.382549-7.766027 9.520825-7.91673M9.520825-7.91673Q9.599154-8.002099 9.668271-8.081936M9.668271-8.081936Q9.70432-8.123577 9.738177-8.164068M9.738177-8.164068Q9.773035-8.205759 9.805768-8.246469M9.805768-8.246469Q9.839527-8.288456 9.871221-8.329645M9.871221-8.329645Q9.903971-8.372206 9.93471-8.414166M9.93471-8.414166Q9.96653-8.457604 9.996387-8.500659M9.996387-8.500659Q10.023246-8.539392 10.05587-8.590027M10.05587-8.590027Q10.085606-8.636182 10.113712-8.682708M10.113712-8.682708Q10.142701-8.730698 10.170128-8.779372M10.170128-8.779372Q10.198395-8.829536 10.225185-8.880749M10.225185-8.880749Q10.230051-8.890051 10.234872-8.899395M10.234872-8.899395Q10.257351-8.942962 10.27891-8.987548M10.27891-8.987548Q10.305728-9.043013 10.331304-9.100433M10.331304-9.100433Q10.337752-9.11491 10.344129-9.12953M10.344129-9.12953Q10.385597-9.22459 10.417641-9.309912M10.417641-9.309912Q10.420461-9.317421 10.423248-9.324953M10.423248-9.324953Q10.438711-9.36674 10.453201-9.409344M10.453201-9.409344Q10.47179-9.463999 10.488901-9.520365M10.488901-9.520365Q10.495469-9.541999 10.501831-9.563924M10.501831-9.563924Q10.508479-9.586835 10.51491-9.610086M10.51491-9.610086Q10.499723-9.621446 10.484562-9.632512M10.484562-9.632512Q10.429641-9.672601 10.374975-9.70889M10.374975-9.70889Q10.339958-9.732135 10.305-9.753853M10.305-9.753853Q10.287732-9.76458 10.270471-9.77494M10.270471-9.77494Q10.259619-9.781453 10.248768-9.787821M10.248768-9.787821Q10.210143-9.810491 10.171481-9.831358M10.171481-9.831358Q10.124935-9.856482 10.078198-9.879066M10.078198-9.879066Q10.034541-9.900162 9.990552-9.919123M9.990552-9.919123Q9.949629-9.936762 9.90824-9.95263M9.90824-9.95263Q9.869801-9.967368 9.830773-9.980649M9.830773-9.980649Q9.794505-9.992991 9.757537-10.00414M9.757537-10.00414Q9.723101-10.014527 9.687862-10.023937M9.687862-10.023937Q9.65491-10.032737 9.621065-10.040734M9.621065-10.040734Q9.589266-10.048249 9.556494-10.055098M9.556494-10.055098Q9.525541-10.061568 9.493542-10.067482M9.493542-10.067482Q9.434522-10.07839 9.370393-10.087667M9.370393-10.087667Q9.312205-10.096085 9.248043-10.10343M9.248043-10.10343Q9.189179-10.110168 9.123803-10.116173M9.123803-10.116173Q9.063411-10.12172 8.995683-10.126803M8.995683-10.126803Q8.987897-10.127387 8.979998-10.127967M8.979998-10.127967Q8.909298-10.133154 8.827194-10.138114',
  'M10.700016-9.680782Q10.815473-9.72382 10.925484-9.762058M10.925484-9.762058Q11.039948-9.801843 11.150062-9.836969M11.150062-9.836969Q11.263421-9.873131 11.373771-9.904864M11.373771-9.904864Q11.486287-9.93722 11.596843-9.965308M11.596843-9.965308Q11.652711-9.979502 11.708292-9.992663M11.708292-9.992663Q11.764119-10.005881 11.819804-10.018092M11.819804-10.018092Q11.875648-10.030337 11.9315-10.041602M11.9315-10.041602Q11.956776-10.0467 11.982078-10.051602M11.982078-10.051602Q12.01277-10.057548 12.043525-10.063211M12.043525-10.063211Q12.099612-10.073539 12.156044-10.082948M12.156044-10.082948Q12.191079-10.088789 12.226307-10.094287M12.226307-10.094287Q12.247734-10.097631 12.269247-10.10085M12.269247-10.10085Q12.325915-10.109329 12.383343-10.116966M12.383343-10.116966Q12.440438-10.124559 12.498562-10.131355M12.498562-10.131355Q12.540832-10.136297 12.583809-10.140838',
  'M7.15883-5.155221L7.245348-5.069074M7.245348-5.069074Q7.358689-4.956219 7.459938-4.833736M7.459938-4.833736L8.25756-3.868828M8.25756-3.868828L9.016953-2.950166M9.016953-2.950166C9.054733-2.904462 9.092962-2.859131 9.130364-2.813115M9.130364-2.813115Q9.190695-2.738889 9.244501-2.66828M9.244501-2.66828Q9.312887-2.57854 9.374907-2.489214M9.374907-2.489214Q9.410463-2.438003 9.444362-2.38632M9.444362-2.38632Q9.480568-2.331121 9.51508-2.275086M9.51508-2.275086Q9.551226-2.216396 9.585673-2.156533M9.585673-2.156533Q9.587394-2.153543 9.58911-2.15055M9.58911-2.15055Q9.622694-2.091986 9.654777-2.032086M9.654777-2.032086Q9.688773-1.968616 9.721203-1.903427M9.721203-1.903427Q9.753341-1.838823 9.784059-1.772295M9.784059-1.772295Q9.793351-1.752168 9.802522-1.73185M9.802522-1.73185C10.292588-1.497379 10.778759-1.254848 11.269975-1.022757M11.269975-1.022757Q11.356811-0.981728 11.44304-0.943634M11.44304-0.943634Q11.527385-0.906371 11.611389-0.87181M11.611389-0.87181Q11.677427-0.84464 11.743398-0.819081M11.743398-0.819081Q11.759416-0.812875 11.775435-0.806762M11.775435-0.806762Q11.855444-0.776229 11.935636-0.747957M11.935636-0.747957Q11.985742-0.730292 12.036009-0.713478M12.036009-0.713478Q12.064217-0.704042 12.092493-0.694868M12.092493-0.694868Q12.169171-0.66999 12.246538-0.646979M12.246538-0.646979Q12.321966-0.624545 12.398325-0.603802M12.398325-0.603802Q12.47279-0.583574 12.548422-0.564879M12.548422-0.564879Q12.622211-0.546639 12.697393-0.529788M12.697393-0.529788Q12.770789-0.513338 12.845795-0.498148M12.845795-0.498148Q12.857917-0.495693 12.870086-0.49327M12.870086-0.49327Q12.931481-0.481046 12.994162-0.469616M12.994162-0.469616Q13.06757-0.456229 13.143002-0.443886M13.143002-0.443886Q13.168819-0.439661 13.194896-0.435555'
];

var model = {
  models: {
    svgpaths: { models: {}, layer: 'red' },
    rows: { models: {} }
  }
};

var rect = new makerjs.models.Rectangle(1, 1);
var margin = 8;
for (var i = 0; i < pathsArray.length; i++) {
  var pathModel = makerjs.importer.fromSVGPathData(pathsArray[i]);
  var chain = makerjs.model.findSingleChain(pathModel);
  var count = Math.ceil(chain.pathLength / margin);
  var row;

  if(count > 1) {
    row = makerjs.layout.cloneToRow(rect, count, margin);
  } else {
    row = {models: { rect: makerjs.cloneObject(rect) } };
  }

  makerjs.layout.childrenOnChain(row, chain, 0.5, false, true);
  model.models.svgpaths.models[i]= pathModel;
  model.models.rows.models[i] = row;

}

module.exports = model;

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

@danmarshall Thank You !!

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

Is it part of version 0.17.3 ?

from maker.js.

noobd3v avatar noobd3v commented on June 9, 2024

Okay Thanks a lot.

from maker.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.