@@ -399,6 +399,75 @@ namespace cgl
399
399
}
400
400
};
401
401
402
+ PackedRecord GetOffsetPathImpl (const Path& originalPath, double offset)
403
+ {
404
+ auto factory = gg::GeometryFactory::create ();
405
+ gg::PrecisionModel model (gg::PrecisionModel::Type::FLOATING);
406
+
407
+ // gob::BufferParameters param(10, gob::BufferParameters::CAP_ROUND, gob::BufferParameters::JOIN_BEVEL, 10.0);
408
+ gob::BufferParameters param (10 , gob::BufferParameters::CAP_FLAT, gob::BufferParameters::JOIN_BEVEL, 10.0 );
409
+
410
+ gob::OffsetCurveBuilder builder (&model, param);
411
+
412
+ std::vector<gg::CoordinateSequence*> resultLines;
413
+ bool isClosedPath = false ;
414
+ if (originalPath.empty ())
415
+ {
416
+ CGL_Error (" Original Path is Empty" );
417
+ }
418
+
419
+ if (2 <= originalPath.cs ->size ())
420
+ {
421
+ const auto front = originalPath.cs ->front ();
422
+ const auto back = originalPath.cs ->back ();
423
+
424
+ isClosedPath = (front.x == back.x && front.y == back.y );
425
+ }
426
+
427
+ const bool isLeftSide = 0.0 <= offset;
428
+ // builder.getLineCurve(&points, 15.0, result);
429
+ builder.getSingleSidedLineCurve (originalPath.cs .get (), std::abs (offset), resultLines, isLeftSide, !isLeftSide);
430
+
431
+ const auto coord = [&](double x, double y)
432
+ {
433
+ PackedRecord record;
434
+ record.add (" x" , x);
435
+ record.add (" y" , y);
436
+ return record;
437
+ };
438
+ const auto appendCoord = [&](PackedList& list, double x, double y)
439
+ {
440
+ const auto record = coord (x, y);
441
+ list.add (record);
442
+ };
443
+
444
+ PackedList polygonList;
445
+ for (size_t i = 0 ; i < resultLines.size (); ++i)
446
+ {
447
+ const auto line = resultLines[i];
448
+ for (size_t p = 0 ; p < line->getSize (); ++p)
449
+ {
450
+ appendCoord (polygonList, line->getX (p), line->getY (p));
451
+ }
452
+ }
453
+
454
+ // getSingleSidedLineCurveがClosedPathを返すので最後の点を消す
455
+ if (!isClosedPath)
456
+ {
457
+ polygonList.data .pop_back ();
458
+ }
459
+
460
+ // getSingleSidedLineCurveに左と右を指定したとき方向が逆になるので合わせる
461
+ if (!isLeftSide)
462
+ {
463
+ std::reverse (polygonList.data .begin (), polygonList.data .end ());
464
+ }
465
+
466
+ PackedRecord result;
467
+ result.add (" line" , polygonList);
468
+ return result;
469
+ }
470
+
402
471
PackedRecord ShapeResult (const PackedVal& lhs = PackedList())
403
472
{
404
473
return MakeRecord (
@@ -1116,75 +1185,6 @@ namespace cgl
1116
1185
return ShapeResult (MakeRecord (" line" , polygonList));
1117
1186
}
1118
1187
1119
- PackedRecord GetOffsetPathImpl (const Path& originalPath, double offset)
1120
- {
1121
- auto factory = gg::GeometryFactory::create ();
1122
- gg::PrecisionModel model (gg::PrecisionModel::Type::FLOATING);
1123
-
1124
- // gob::BufferParameters param(10, gob::BufferParameters::CAP_ROUND, gob::BufferParameters::JOIN_BEVEL, 10.0);
1125
- gob::BufferParameters param (10 , gob::BufferParameters::CAP_FLAT, gob::BufferParameters::JOIN_BEVEL, 10.0 );
1126
-
1127
- gob::OffsetCurveBuilder builder (&model, param);
1128
-
1129
- std::vector<gg::CoordinateSequence*> resultLines;
1130
- bool isClosedPath = false ;
1131
- if (originalPath.empty ())
1132
- {
1133
- CGL_Error (" Original Path is Empty" );
1134
- }
1135
-
1136
- if (2 <= originalPath.cs ->size ())
1137
- {
1138
- const auto front = originalPath.cs ->front ();
1139
- const auto back = originalPath.cs ->back ();
1140
-
1141
- isClosedPath = (front.x == back.x && front.y == back.y );
1142
- }
1143
-
1144
- const bool isLeftSide = 0.0 <= offset;
1145
- // builder.getLineCurve(&points, 15.0, result);
1146
- builder.getSingleSidedLineCurve (originalPath.cs .get (), std::abs (offset), resultLines, isLeftSide, !isLeftSide);
1147
-
1148
- const auto coord = [&](double x, double y)
1149
- {
1150
- PackedRecord record;
1151
- record.add (" x" , x);
1152
- record.add (" y" , y);
1153
- return record;
1154
- };
1155
- const auto appendCoord = [&](PackedList& list, double x, double y)
1156
- {
1157
- const auto record = coord (x, y);
1158
- list.add (record);
1159
- };
1160
-
1161
- PackedList polygonList;
1162
- for (size_t i = 0 ; i < resultLines.size (); ++i)
1163
- {
1164
- const auto line = resultLines[i];
1165
- for (size_t p = 0 ; p < line->getSize (); ++p)
1166
- {
1167
- appendCoord (polygonList, line->getX (p), line->getY (p));
1168
- }
1169
- }
1170
-
1171
- // getSingleSidedLineCurveがClosedPathを返すので最後の点を消す
1172
- if (!isClosedPath)
1173
- {
1174
- polygonList.data .pop_back ();
1175
- }
1176
-
1177
- // getSingleSidedLineCurveに左と右を指定したとき方向が逆になるので合わせる
1178
- if (!isLeftSide)
1179
- {
1180
- std::reverse (polygonList.data .begin (), polygonList.data .end ());
1181
- }
1182
-
1183
- PackedRecord result;
1184
- result.add (" line" , polygonList);
1185
- return ShapeResult (result);
1186
- }
1187
-
1188
1188
PackedRecord GetOffsetPath (const PackedRecord& packedPathRecord, double offset)
1189
1189
{
1190
1190
Path originalPath = std::move (ReadPathPacked (packedPathRecord));
0 commit comments