Skip to content

Commit

Permalink
update print licence
Browse files Browse the repository at this point in the history
  • Loading branch information
agehama committed May 1, 2018
1 parent 683d396 commit 058d3ff
Show file tree
Hide file tree
Showing 12 changed files with 997 additions and 119 deletions.
45 changes: 26 additions & 19 deletions docs/pita_doc/content/_index.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,37 @@
title: "はじめに"
---

# 作図用プログラミング言語 Pita
# Pita 作図のためのプログラミング言語

**Pita**は、作図のためのプログラミング言語です。
Pitaは、ベクター画像を生成するためのプログラミング言語です。
ユーザーが記述した図形の仕様(ルール)を受け取り、それを満たすような図形を計算します。
手続きを用いた生成的な図形表現や、制約を用いた宣言的な図形の定義を高速に行うことができます。
Pitaは容易に図形の定義ができて後からの変更を行いやすいように設計されています。

---

## Pitaの特徴

* [簡潔な構文]({{%relref "/features/syntax/_index.md" %}})
* [図形処理]({{%relref "/features/geometry/_index.md" %}})
* [制約]({{%relref "/features/constraint/_index.md" %}})

![Screenshot](https://github.com/matcornic/hugo-theme-learn/raw/master/images/screenshot.png?width=40pc&classes=shadow)
![Pitaで記述した図の例](https://github.com/agehama/Pita/raw/master/docs/pita_doc/images/pita_examples.png?classes=shadow)

### 1. 制約による図形記述
Pitaの最大の特徴は、図を定義するのに座標やアルゴリズムを書く必要がないという点です。
Pitaは図の定義に、図が満たすべき仕様(図形同士が接触している、平行である、...)を与えることができます。
処理系はこの仕様を満たす図形を自動的に計算します。

## Contribute to this documentation
Feel free to update this content, just click the **Edit this page** link displayed on top right of each page, and pullrequest it
### 2. 図形の部品化
Pitaは一度図形を作ったら、それを継承することで似たような図形を簡単に作ることができます。
また、図形同士のブーリアン演算も行うことができます。
さらに図形定義から他の図形定義を参照することもでき、作図工程のモジュール化を支援します。

{{% notice info %}}
Your modification will be deployed automatically when merged.
{{% /notice %}}
### 3. 高い表現力
Pitaは図形に関する高度な演算機能(図形をパスに沿うよう変形させる、障害物を迂回する経路を探索する、...)を提供します。
また、分岐やループなどの制御構文、レコードやリストなどのデータ構造、第一級関数など汎用性の高い言語機能を備えているので、複雑な図形も簡潔に記述することが可能です。

## Documentation website
This current documentation has been statically generated with Hugo with a simple command : `hugo -t hugo-theme-learn` -- source code is [available here at GitHub](https://github.com/matcornic/hugo-theme-learn)
#### 他の特徴
他にもPitaは次のような特徴を備えています。

{{% notice note %}}
Automatically published and hosted thanks to [Netlify](https://www.netlify.com/). Read more about [Automated HUGO deployments with Netlify](https://www.netlify.com/blog/2015/07/30/hosting-hugo-on-netlifyinsanely-fast-deploys/)
{{% /notice %}}
- Windows, MacOS, Ubuntu のサポート
- 数値計算による高速な制約計算
- フォント対応
- SVG出力対応
- パスに関する演算機能
- MITライセンス
2 changes: 1 addition & 1 deletion docs/pita_doc/content/features/_index.ja.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Pitaの特徴"
title: "1. Pitaの特徴"
---

## Pitaの特徴
Expand Down
12 changes: 12 additions & 0 deletions docs/pita_doc/content/start/_index.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: "クイックスタート"
weight: 10
chapter: true
pre: "<b>1. </b>"
---

### チャプター 1

# クイックスタート

Pitaのダウンロードとインストール、サンプルの実行手順を紹介します。
19 changes: 19 additions & 0 deletions docs/pita_doc/content/start/download/_index.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: "ダウンロードとインストール"
weight: 10
---

### ダウンロードとインストール
#### Windows


#### MacOS
Pitaは一度図形を作ったら、それを継承することで似たような図形を簡単に作ることができます。
また、図形同士のブーリアン演算も行うことができます。
さらに図形定義から他の図形定義を参照することもでき、作図工程のモジュール化を支援します。

#### Ubuntu
Pitaは図形に関する高度な演算機能(図形をパスに沿うよう変形させる、障害物を迂回する経路を探索する、...)を提供します。
また、分岐やループなどの制御構文、レコードやリストなどのデータ構造、第一級関数など汎用性の高い言語機能を備えているので、複雑な図形も簡潔に記述することが可能です。

### ソースコードのビルド
Binary file added docs/pita_doc/images/pita_examples.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions examples/examples.cgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import "rec_shape2.cgl" as rec2
import "koch_snowflake.cgl" as koch
import "pita_p2.cgl" as p2
import "pita_constraint_example.cgl" as cs

Center = (shape -> Square{polygon=BoundingBox(shape).result.polygon}.center())
Left = (shape -> Square{polygon=BoundingBox(shape).result.polygon}.left())
Right = (shape -> Square{polygon=BoundingBox(shape).result.polygon}.right())

main = Shape{
a: (s = rec2.tree, s{})
b: (s = koch.tree, s{scale: X2(0.4), pos: Vec2(500,0)})
c: (s = p2.main, s{scale: X2(0.5), pos: Vec2(800,0)})
d: (s = cs.main, s{scale: X2(2.0), pos: Vec2(1200,0)})
sat((Center(a).y - Center(b).y)^2 == 0)
sat((Center(b).y - Center(c).y)^2 == 0)
sat((Center(c).y - Center(d).y)^2 == 0)
var(b.pos.y, c.pos.y, d.pos.y)
}

s = Free(main)
main2 = s{
dd = (Right(s.a).x - Left(s.b).x)
sat( (dd - (Right(b).x - Left(c).x))^2 == 0)
sat( (dd - (Right(c).x - Left(d).x))^2 == 0)
var(c.pos.x, d.pos.x)
}
2 changes: 1 addition & 1 deletion examples/koch_snowflake.cgl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ koch_template = (p, q ->
n = {x: -v.y, y: v.x}
vby3 = div3(p, q)
m = Div(Add(p, q), 2.0)
nby3 = SetLength(n, 0.5*Sqrt(3.0)*length(vby3))
nby3 = SetLength(n, 0.5*Sqrt(3.0)*Length(vby3))
m1 = Add(p, vby3)
m2 = Add(m1, vby3)
ps = [p, m1, Add(m, nby3), m2, q]
Expand Down
3 changes: 2 additions & 1 deletion examples/logo.cgl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ main = Shape{
a: tri{scale: X2(0.6), angle: -90}
b: pita{}
//sat(Contact(Moved(getRight(a), 10,0), getLeft(b)))
sat(Contact(getRight(a), Moved(getLeft(b), -10, 0) ))
sat(Contact(getRight(a), Moved(getLeft(b), -20, 0) ))
var(b.pos)
fill: Rgb(255,255,255)
}
21 changes: 2 additions & 19 deletions examples/pita_p2.cgl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,12 @@ baseColor = Rgb(245, 245, 245)
mainColor = Rgb(49, 187, 222)
accentColor = Rgb(68, 84, 106)

fontPath = "C:/Users/dphs1/AppData/Roaming/Adobe/CoreSync/plugins/livetype/r/35668"
sourceFontPath = "C:/Windows/Fonts/SourceCodePro-Regular.ttf"

sourceCodeText =
"{
size = 100
polygon: [
{x: 0, y: 0}, {x: size, y: 0}
{x: size, y: size}, {x: 0, y: size}
]
fill: {r: 49, g: 187, b: 222}
}"

sourceCodeShape = {
a: BuildText(sourceCodeText, {}, sourceFontPath)
}

arrow = Shape{
body: Square{scale: Vec2(400, 20), pos: Vec2(-200, 0)}
head: Triangle{scale: X2(50), pos: X2(0), angle: 90}
}

main = {
main = Shape{
a: Square{scale: X2(100), angle: 45}
b: a{pos: Vec2(300, 0)}
strength = 5.0
Expand All @@ -37,6 +20,6 @@ main = {

arrowShape = arrow{}
d: DeformShapeByPath2({s:SubDiv(arrowShape, 10)},
c,
c.result,
arrowShape.body.left(), arrowShape.head.top())
}
8 changes: 4 additions & 4 deletions examples/rec_shape2.cgl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ shapeList = (f, depth, template ->
}
else Shape{
a: template{}
b: f(f, depth-1, template){
b: (c = f(f, depth-1, template), c{
pos.y = -1
angle = 30
scale = X2(0.9)
}
})
}
)

tree = Shape{
depth = 50
a: shapeList(shapeList, depth, Shape{a:Diff(Triangle{}, Buffer(Triangle{}, -0.1))}){scale = X2(100)}
a.b.b.b.b.b = 0
a: (c = shapeList(shapeList, depth, Shape{a:Diff(Triangle{}, Buffer(Triangle{}, -0.1))}), c{scale = X2(100)})
//a.b.b.b.b.b = 0
}
138 changes: 69 additions & 69 deletions source/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,75 @@ namespace cgl
}
};

PackedRecord GetOffsetPathImpl(const Path& originalPath, double offset)
{
auto factory = gg::GeometryFactory::create();
gg::PrecisionModel model(gg::PrecisionModel::Type::FLOATING);

//gob::BufferParameters param(10, gob::BufferParameters::CAP_ROUND, gob::BufferParameters::JOIN_BEVEL, 10.0);
gob::BufferParameters param(10, gob::BufferParameters::CAP_FLAT, gob::BufferParameters::JOIN_BEVEL, 10.0);

gob::OffsetCurveBuilder builder(&model, param);

std::vector<gg::CoordinateSequence*> resultLines;
bool isClosedPath = false;
if (originalPath.empty())
{
CGL_Error("Original Path is Empty");
}

if (2 <= originalPath.cs->size())
{
const auto front = originalPath.cs->front();
const auto back = originalPath.cs->back();

isClosedPath = (front.x == back.x && front.y == back.y);
}

const bool isLeftSide = 0.0 <= offset;
//builder.getLineCurve(&points, 15.0, result);
builder.getSingleSidedLineCurve(originalPath.cs.get(), std::abs(offset), resultLines, isLeftSide, !isLeftSide);

const auto coord = [&](double x, double y)
{
PackedRecord record;
record.add("x", x);
record.add("y", y);
return record;
};
const auto appendCoord = [&](PackedList& list, double x, double y)
{
const auto record = coord(x, y);
list.add(record);
};

PackedList polygonList;
for (size_t i = 0; i < resultLines.size(); ++i)
{
const auto line = resultLines[i];
for (size_t p = 0; p < line->getSize(); ++p)
{
appendCoord(polygonList, line->getX(p), line->getY(p));
}
}

//getSingleSidedLineCurveがClosedPathを返すので最後の点を消す
if (!isClosedPath)
{
polygonList.data.pop_back();
}

//getSingleSidedLineCurveに左と右を指定したとき方向が逆になるので合わせる
if (!isLeftSide)
{
std::reverse(polygonList.data.begin(), polygonList.data.end());
}

PackedRecord result;
result.add("line", polygonList);
return result;
}

PackedRecord ShapeResult(const PackedVal& lhs = PackedList())
{
return MakeRecord(
Expand Down Expand Up @@ -1116,75 +1185,6 @@ namespace cgl
return ShapeResult(MakeRecord("line", polygonList));
}

PackedRecord GetOffsetPathImpl(const Path& originalPath, double offset)
{
auto factory = gg::GeometryFactory::create();
gg::PrecisionModel model(gg::PrecisionModel::Type::FLOATING);

//gob::BufferParameters param(10, gob::BufferParameters::CAP_ROUND, gob::BufferParameters::JOIN_BEVEL, 10.0);
gob::BufferParameters param(10, gob::BufferParameters::CAP_FLAT, gob::BufferParameters::JOIN_BEVEL, 10.0);

gob::OffsetCurveBuilder builder(&model, param);

std::vector<gg::CoordinateSequence*> resultLines;
bool isClosedPath = false;
if (originalPath.empty())
{
CGL_Error("Original Path is Empty");
}

if (2 <= originalPath.cs->size())
{
const auto front = originalPath.cs->front();
const auto back = originalPath.cs->back();

isClosedPath = (front.x == back.x && front.y == back.y);
}

const bool isLeftSide = 0.0 <= offset;
//builder.getLineCurve(&points, 15.0, result);
builder.getSingleSidedLineCurve(originalPath.cs.get(), std::abs(offset), resultLines, isLeftSide, !isLeftSide);

const auto coord = [&](double x, double y)
{
PackedRecord record;
record.add("x", x);
record.add("y", y);
return record;
};
const auto appendCoord = [&](PackedList& list, double x, double y)
{
const auto record = coord(x, y);
list.add(record);
};

PackedList polygonList;
for (size_t i = 0; i < resultLines.size(); ++i)
{
const auto line = resultLines[i];
for (size_t p = 0; p < line->getSize(); ++p)
{
appendCoord(polygonList, line->getX(p), line->getY(p));
}
}

//getSingleSidedLineCurveがClosedPathを返すので最後の点を消す
if (!isClosedPath)
{
polygonList.data.pop_back();
}

//getSingleSidedLineCurveに左と右を指定したとき方向が逆になるので合わせる
if (!isLeftSide)
{
std::reverse(polygonList.data.begin(), polygonList.data.end());
}

PackedRecord result;
result.add("line", polygonList);
return ShapeResult(result);
}

PackedRecord GetOffsetPath(const PackedRecord& packedPathRecord, double offset)
{
Path originalPath = std::move(ReadPathPacked(packedPathRecord));
Expand Down
Loading

0 comments on commit 058d3ff

Please sign in to comment.